fs: fix d_path() with zero-length input buffer
PATCH 1/1 fs: fix d_path() with zero-length input buffer
In prepend_name(), *buflen < dlen + 1 comparison is buggy because dlen has unsigned data type, and we can reach this location with *buflen == -1.
The fix casts dlen to int.
Bug reports:
https://bugzilla.redhat.com/show_bug.cgi?id=1050964
https://bugzilla.redhat.com/show_bug.cgi?id=1060384
--- fs/dcache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dcache.c +1 -1
@@ -2833,7 +2833,7 @@ static int prepend_name(char **buffer, int *buflen, struct qstr *name)u32 dlen =ACCESS_ONCE (name->len);char *p; -if (*buflen < dlen +1 ) +if (*buflen < (int )dlen +1 )return -ENAMETOOLONG ; *buflen -= dlen +1 ; p = *buffer -= dlen +1 ;
Signature · 1 line
1.8.1.4
Quoted 4 lines · Denys Vlasenko
In
prepend_name(), *buflen < dlen + 1 comparison is buggy because dlen has unsigned data type, and we can reach this location with *buflen == -1.
because, say, path_with_deleted() doesn't check the result of prepend(), and prepend() updates *buflen unconditionally. I am wondering if it should be changed too just for consistency.
fs/dcache.c static int prepend_name(char **buffer, int *buflen, struct qstr *name) · line 2836
Quoted 8 lines
fs/dcache.c +1
-1@@ -2833,7 +2833,7 @@ static int prepend_name(char **buffer, int *buflen, struct qstr *name)u32 dlen =ACCESS_ONCE (name->len);char *p; -if (*buflen < dlen +1 ) +if (*buflen < (int )dlen +1 )
perhaps it would be better to simply make dlen "int" ?
Oleg.