From: Theodore Ts'o Date: Fri, 12 Aug 2022 02:16:41 +0000 (-0400) Subject: e2fsck: when mutating file name make sure its length never exceeds 255 X-Git-Tag: v1.46.6-rc1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1bd16e790308f92e89a5dfbd40ab9e164fe88aa9;p=thirdparty%2Fe2fsprogs.git e2fsck: when mutating file name make sure its length never exceeds 255 E2fsck will attempt to mutate filenames to ensure uniqueness if necessary. If there are two unique filenames that are 254 or 255 characters in length and do not contain the '~' character, the mutate_name() function would create a filename which is 256 bytes long, which is not a legal filename in Linux. Adjust the mutate_name function to avoid this possibility. Addresses-Coverity-Bug: 1500768 Signed-off-by: Theodore Ts'o --- diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c index 8cc36f24f..210cfdf2f 100644 --- a/e2fsck/rehash.c +++ b/e2fsck/rehash.c @@ -414,6 +414,8 @@ static void mutate_name(char *str, unsigned int *len) l += 2; else l = (l+3) & ~3; + if (l > 255) + l = 255; str[l-2] = '~'; str[l-1] = '0'; *len = l;