fsck.f2fs: do not hard-code encrypted filename length to avoid heap buffer overflow
authorRandall Huang <huangrandall@google.com>
Wed, 10 Oct 2018 00:38:01 +0000 (17:38 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 21 Nov 2018 19:38:23 +0000 (11:38 -0800)
If the len is less than 24, heap buffer overflow is reported.

Signed-off-by: Randall Huang <huangrandall@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/fsck.c

index 85d9823..366ba13 100644 (file)
@@ -1145,7 +1145,7 @@ static int digest_encode(const char *src, int len, char *dst)
        int i = 0, bits = 0, ac = 0;
        char *cp = dst;
 
-       while (i < len) {
+       while (i < len && i < 24) {
                ac += (((unsigned char) src[i]) << bits);
                bits += 8;
                do {
@@ -1173,7 +1173,7 @@ int convert_encrypted_name(unsigned char *name, u32 len,
        }
 
        *new = '_';
-       return digest_encode((const char *)name, 24, (char *)new + 1);
+       return digest_encode((const char *)name, len, (char *)new + 1);
 }
 
 static void print_dentry(__u32 depth, __u8 *name,