-
Bug
-
Resolution: Unresolved
-
Medium
-
None
-
None
-
None
-
3
-
9223372036854775807
When cfs_abs_path() appends the file name to the resolved parent
directory, it stores the snprintf() result in "len", which already
holds the length of the parent. The overflow check that follows,
"len >= sizeof(buf) - len", then compares the appended length against
the wrong remaining space. Truncation is only detected when the file
name alone is longer than about half of the buffer, so a long parent
path combined with a long file name can be silently truncated.
Keep the snprintf() result in a separate variable and compare it
against the space left after the parent, sizeof(buf) - len. Also treat
a negative return as an error, and cast the result to size_t for the
comparison so that it is never converted from a negative value.
This is unlikely to be hit in practice because it needs a path close to
PATH_MAX, but a truncated path should be reported as -ENAMETOOLONG
instead of being returned to the caller.