Skip to content

Commit

Permalink
fixing possible buffer overflow in fgetws
Browse files Browse the repository at this point in the history
sizeof(buf) is 1024, but sizeof(wchar_t) is 4,
so there is just space for sizeof(buf)/sizeof(wchar_t) - 256 chars in buffer.

/*
CC="gcc -D_FORTIFY_SOURCE=2  -O2" make
...
call to ‘__fgetws_chk_warn’ declared with attribute warning: \
fgetws called with bigger size than length of destination buffer
*/
  • Loading branch information
urbec-guest authored and kilobyte committed Dec 3, 2020
1 parent 14b2b1a commit 1cdb4c1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion braillefont.c
Expand Up @@ -52,7 +52,7 @@ int main()
wchar_t buf[1024];
setlocale(LC_CTYPE, "");

while (fgetws(buf, sizeof(buf), stdin))
while (fgetws(buf, sizeof(buf)/sizeof(wchar_t), stdin))
{
const wchar_t *b;
for (b=buf; *b; b++)
Expand Down

0 comments on commit 1cdb4c1

Please sign in to comment.