Skip to content

Fixes for vgm -Wformat-overflow#159

Merged
mywave82 merged 2 commits into
adplug:masterfrom
mywave82:vgm-Wformat-overflow
Feb 26, 2023
Merged

Fixes for vgm -Wformat-overflow#159
mywave82 merged 2 commits into
adplug:masterfrom
mywave82:vgm-Wformat-overflow

Conversation

@mywave82

Copy link
Copy Markdown
Contributor

These are the warnings we are trying to fix.

Initially these are buffer overflows controlled by the input file, since the target buffer length is not taken into account.

src/vgm.cpp: In member function ‘virtual std::string CvgmPlayer::getdesc()’:
src/vgm.cpp:352:37: warning: ‘ / ’ directive writing 3 bytes into a region of size between 1 and 256 [-Wformat-overflow=]
  352 |                 sprintf(str_sys, "%s / %s", system, date);
      |                                     ^~~
src/vgm.cpp:352:24: note: ‘sprintf’ output between 4 and 514 bytes into a destination of size 256
  352 |                 sprintf(str_sys, "%s / %s", system, date);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/vgm.cpp:368:46: warning: ‘ (’ directive writing 2 bytes into a region of size between 1 and 256 [-Wformat-overflow=]
  368 |                         sprintf(str_game, "%s (%s)", game, str_sys);
      |                                              ^~
src/vgm.cpp:368:32: note: ‘sprintf’ output between 4 and 514 bytes into a destination of size 256
  368 |                         sprintf(str_game, "%s (%s)", game, str_sys);
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/vgm.cpp:381:38: warning: ‘

   ’ directive writing 4 bytes into a region of size between 1 and 256 [-Wformat-overflow=]
  381 |                 sprintf(str_desc, "%s\r\n\r\n%s", str_game, notes);
      |                                      ^~~~~~~~
src/vgm.cpp:381:24: note: ‘sprintf’ output between 5 and 515 bytes into a destination of size 256
  381 |                 sprintf(str_desc, "%s\r\n\r\n%s", str_game, notes);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

… a buffer-overflow waiting to happen. Atleast use snprintf() to remove the buffer-overflow.
…rce chopping of input strings instead of the formatting.
@mywave82 mywave82 merged commit 926ae9a into adplug:master Feb 26, 2023
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

Successfully merging this pull request may close these issues.

1 participant