Re: [PATCH 4/6] libmount: fix memory overflow [AddressSanitizer]

Karel Zak
2014-11-18T12:06:17Z

On Mon, Nov 10, 2014 at 09:49:53PM +0000, Sami Kerola wrote:
> - if (sscanf(line, " %128[^\n ]\n", name) != 1)
> + if (sscanf(line, " %" stringify(sizeof(line) - 1) "[^\n ]\n", name) != 1)
> continue;

Are you really sure with this code? Did you test it?

Your homework:

#include <stdio.h>

#define stringify(s) #s

int main(int argc, char **argv)
{
char buf[123];
printf("Size is:" stringify(sizeof(buf) - 1) ".\n");
return 1;
}

result:

$ make a
cc a.c -o a
x2:~$ ./a
Size is:sizeof(buf) - 1.

Anyway, fixed and merged..

Karel

--
Karel Zak <kzak@redhat.com>