Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overflow logging.c)nwipe_log_sysinfo) #202

Closed
martijnvanbrummelen opened this issue Mar 10, 2020 · 13 comments
Closed

Overflow logging.c)nwipe_log_sysinfo) #202

martijnvanbrummelen opened this issue Mar 10, 2020 · 13 comments

Comments

@martijnvanbrummelen
Copy link
Owner

martijnvanbrummelen commented Mar 10, 2020

While compiling a overflow issue(warning) is found:

logging.c: In function ‘nwipe_log_sysinfo’:
logging.c:438:37: warning: ‘%s’ directive writing up to 527 bytes into a region of size 37 [-Wformat-overflow=]
438 | sprintf( cmd, "dmidecode -s %s", &dmidecode_keywords[keywords_idx][0] );
| ^~
In file included from /usr/include/stdio.h:867,
from logging.c:29:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:36:10: note: ‘__builtin___sprintf_chk’ output between 14 and 541 bytes into a destination of size 50
36 | return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
37 | __bos (__s), __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

char cmd[50];

@PartialVolume
Copy link
Collaborator

Hi Martyn, I'll take a look at that today.

@PartialVolume
Copy link
Collaborator

I'm not seeing this warning when i compile under sid. How are you compiling it with ?
./configure --prefix=/usr CFLAGS='-O0 -g -Wall -Wextra'
make
make install

@martijnvanbrummelen
Copy link
Owner Author

Im building with hardening (all) options see https://wiki.debian.org/Hardening

@PartialVolume
Copy link
Collaborator

PartialVolume commented Mar 10, 2020

I don't see any issues with the code, it generates a command with a maximum length of 37 characters including the NULL so fits easily into the string cmd[50]. Maybe if I used snprintf where you can specify a limit, i.e 50 then it would be get rid of the warning. Irrespective of that I don't think there is an issue with the code, I think it's just a warning thats there to inform you that there is a safer way to do this using snprinf as i can set bounds.

Are you able to let it go through as is and I'll make the change to use snprintf in the next release ? Let me know what you want me to do. :-)

ps I'll check out the link above and try and reproduce and see if using snprintf instead clears the warning.

@martijnvanbrummelen
Copy link
Owner Author

Try this export CFLAGS="-g -O2 -fstack-protector-strong -Wformat -Werror=format-security"

@PartialVolume
Copy link
Collaborator

Still not seeing it using the
./configure --prefix=/usr CFLAGS='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security'

then
make clean
make
make
make all-recursive
make[1]: Entering directory '/media/nick/Data_sdb/MIC/Technical_Data/Software/nwipe'
Making all in src
make[2]: Entering directory '/media/nick/Data_sdb/MIC/Technical_Data/Software/nwipe/src'
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -MT isaac_rand/nwipe-isaac_rand.o -MD -MP -MF isaac_rand/.deps/nwipe-isaac_rand.Tpo -c -o isaac_rand/nwipe-isaac_rand.o test -f 'isaac_rand/isaac_rand.c' || echo './'isaac_rand/isaac_rand.c
mv -f isaac_rand/.deps/nwipe-isaac_rand.Tpo isaac_rand/.deps/nwipe-isaac_rand.Po
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -MT nwipe-nwipe.o -MD -MP -MF .deps/nwipe-nwipe.Tpo -c -o nwipe-nwipe.o test -f 'nwipe.c' || echo './'nwipe.c
mv -f .deps/nwipe-nwipe.Tpo .deps/nwipe-nwipe.Po
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -MT nwipe-gui.o -MD -MP -MF .deps/nwipe-gui.Tpo -c -o nwipe-gui.o test -f 'gui.c' || echo './'gui.c
mv -f .deps/nwipe-gui.Tpo .deps/nwipe-gui.Po
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -MT nwipe-pass.o -MD -MP -MF .deps/nwipe-pass.Tpo -c -o nwipe-pass.o test -f 'pass.c' || echo './'pass.c
mv -f .deps/nwipe-pass.Tpo .deps/nwipe-pass.Po
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -MT nwipe-device.o -MD -MP -MF .deps/nwipe-device.Tpo -c -o nwipe-device.o test -f 'device.c' || echo './'device.c
mv -f .deps/nwipe-device.Tpo .deps/nwipe-device.Po
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -MT mt19937ar-cok/nwipe-mt19937ar-cok.o -MD -MP -MF mt19937ar-cok/.deps/nwipe-mt19937ar-cok.Tpo -c -o mt19937ar-cok/nwipe-mt19937ar-cok.o test -f 'mt19937ar-cok/mt19937ar-cok.c' || echo './'mt19937ar-cok/mt19937ar-cok.c
mv -f mt19937ar-cok/.deps/nwipe-mt19937ar-cok.Tpo mt19937ar-cok/.deps/nwipe-mt19937ar-cok.Po
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -MT nwipe-logging.o -MD -MP -MF .deps/nwipe-logging.Tpo -c -o nwipe-logging.o test -f 'logging.c' || echo './'logging.c
mv -f .deps/nwipe-logging.Tpo .deps/nwipe-logging.Po
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -MT nwipe-method.o -MD -MP -MF .deps/nwipe-method.Tpo -c -o nwipe-method.o test -f 'method.c' || echo './'method.c
mv -f .deps/nwipe-method.Tpo .deps/nwipe-method.Po
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -MT nwipe-options.o -MD -MP -MF .deps/nwipe-options.Tpo -c -o nwipe-options.o test -f 'options.c' || echo './'options.c
mv -f .deps/nwipe-options.Tpo .deps/nwipe-options.Po
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -MT nwipe-prng.o -MD -MP -MF .deps/nwipe-prng.Tpo -c -o nwipe-prng.o test -f 'prng.c' || echo './'prng.c
mv -f .deps/nwipe-prng.Tpo .deps/nwipe-prng.Po
gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -MT nwipe-version.o -MD -MP -MF .deps/nwipe-version.Tpo -c -o nwipe-version.o test -f 'version.c' || echo './'version.c
mv -f .deps/nwipe-version.Tpo .deps/nwipe-version.Po
gcc -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -D_DEFAULT_SOURCE -o nwipe isaac_rand/nwipe-isaac_rand.o nwipe-nwipe.o nwipe-gui.o nwipe-pass.o nwipe-device.o mt19937ar-cok/nwipe-mt19937ar-cok.o nwipe-logging.o nwipe-method.o nwipe-options.o nwipe-prng.o nwipe-version.o -lparted -lpthread -luuid -lpanel -lncurses -ltinfo
make[2]: Leaving directory '/media/nick/Data_sdb/MIC/Technical_Data/Software/nwipe/src'
Making all in man
make[2]: Entering directory '/media/nick/Data_sdb/MIC/Technical_Data/Software/nwipe/man'
make[2]: Nothing to be done for 'all'.
make[2]: Leaving directory '/media/nick/Data_sdb/MIC/Technical_Data/Software/nwipe/man'
make[2]: Entering directory '/media/nick/Data_sdb/MIC/Technical_Data/Software/nwipe'
make[2]: Leaving directory '/media/nick/Data_sdb/MIC/Technical_Data/Software/nwipe'
make[1]: Leaving directory '/media/nick/Data_sdb/MIC/Technical_Data/Software/nwipe'

@PartialVolume
Copy link
Collaborator

@martijnvanbrummelen OK !, got it, under Ubuntu it doesn't show the warning using the CFLAGS you provided but under SID it does. I'll do a patch using snprintf and see if it clears the warning.

@PartialVolume
Copy link
Collaborator

@martijnvanbrummelen So using snprintf didn't fix the warning. However the fix was actually easier. I changed:
char cmd[50]; to char cmd[541];

The compiler was happy with that !. It was very specific i.e. 540 produced a warning that the NULL terminator would over write the buffer. 541 bytes was what it required.

Do you want to try that on your system ?

@PartialVolume
Copy link
Collaborator

@martijnvanbrummelen In the warning it says "directive writing upto 527 bytes" and in the second part of the warning it says 541 bytes.

The compiler has basically looked at the total size of the char array and assuming the entire 504 byte array could be written to the cmd buffer. Of course it fails to recognise the array is full of null terminated strings with a maximum size of 24 bytes. Even if you made the array const char the warning still comes up. So basically the fix to get rid of the warning is to make the destination string the same size as the array containing all the strings, i.e 504+13(dmidecode -s )+24(the maximum length of one string. = 541 bytes.

@PartialVolume
Copy link
Collaborator

Fixed by #204

@PartialVolume
Copy link
Collaborator

PartialVolume commented Mar 10, 2020

@martijnvanbrummelen I've applied the overflow warning patch to the master (not 0.27 release). I've done it a better way than hard coding the array size.

I've used 'sizeof' to determine what the size of the character array that we construct the dmidecode command in should be.

This is a better way to determine the array size as it's determined by the compiler. It also means that if somebody adds extra dmidecode keywords to the keyword array, the destination array size is automatically adjusted by the compiler.

Maybe it would be better to skip 0.27 and just jump to 0.28 ? The current master has some nice fixes for the GUI when resizing the terminal. Or we could just ignore the overflow warning in 0.27 as it's not a 'real' bug. Let me know what you would prefer me to do.

@martijnvanbrummelen
Copy link
Owner Author

I think we should drop 0.27 and release 0.28 which comes with at least this fix and the man page fix.

@PartialVolume
Copy link
Collaborator

PartialVolume commented Mar 10, 2020

I think we should drop 0.27 and release 0.28 which comes with at least this fix and the man page fix.

No problem, I'll update the various version files etc and do a release on 0.28, run the checks on all the various distros as before and then I'll let you know when 0.28 is ready to upload to debian. It will probably be ready by end of business tomorrow.

0.28 will come with the following plus all the 0.27 updates. CHANGELOG.md

v0.28

  • Fix premature exit when terminal resized on completion of wipes (Thanks PartialVolume)
  • Fix GUI when terminal is resized, currently not handled correctly causing missing or incorrectly sized ncurses windows/panels (Thanks PartialVolume)
  • Fix GUI screen flicker under various situations. [Fix flicker #200] Fixes Flicker when stats are updated every second #115 (Thanks PartialVolume)
  • Fix responsivness of screen during wipe when resized. Info is updated every 10th/sec. Key presses are more responsive. (Thanks PartialVolume)
  • Fix compiler warning re sprintf.
  • Update man page.

v0.27

  • Add verify method to verify a disk is zero filled #128 (Thanks Legogizmo)
  • Add new HMG IS5 enhanced wipe method #168 (Thanks infrastation)
  • Fix percentage progress and show on completion of wipe (Thanks PartialVolume)
  • Implement clang-format support (Thanks louib)
  • Implement more frequent disk sync support (Thanks Legogizmo)
  • Format command line help to 80 character line length #114 (Thanks PartialVolume)
  • Fix nwipe message log and missing messages that was causing segfaults under certain conditions (Thanks PartialVolume)
  • Add the Github build CI service and update Readme with build status labels (Thanks louib)
  • Miscellaneous smaller fixes

Proposed for 0.29

  • Add enhancement fibre channel wiping of non 512 bytes/sector drives such as 524/528 bytes/sector etc (work in progress by PartialVolume)
  • HPA/DCO detection and adjustment to wipe full drive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants