SDL/src
Sam Lantinga 880842cfdf Fixed bug 3531 - internal SDL_vsnprintf implementation access memory outside given buffer ranges
Tristan

The internal SDL_vsnprintf implementation accesses memory outside buffer. The bug existed also inside the format (%) processing, which was fixed with Bug 3441.

But there is still an invalid access, if we do not have any format inside the source string and the destination string is shorter than the format string. You can use any string for this test, as long it is longer than the buffer.

Example:

va_list argList;
char buffer[4];
SDL_vsnprintf(buffer, sizeof(buffer), "Testing", argList);

The bug is located on the 'else' branch of the format char test:

while (*fmt) {
  if (*fmt == '%') {
    ...
  } else {
    if (left > 1) {
      *text = *fmt;
      --left;
    }
    ++fmt;
    ++text;
  }
}
if (left > 0) {
  *text = '\0';
}

As you can see that text is always incremented, even when left is already one. When then on the last lines, *text is assigned the NULL char, the pointer is located outside bounds.
2016-12-31 16:14:51 -08:00
..
atomic Updated copyright to 2016 2016-01-02 10:10:34 -08:00
audio Fixed bug 3516 - fix build on illumos 2016-12-26 01:56:52 -08:00
core Fixed bug 3517 - Compiler warnings with gcc -Wstrict-prototypes 2016-12-26 02:12:21 -08:00
cpuinfo cpuinfo: fix SDL_HasNEON() on older iOS devices, fixed C++ comment. 2016-11-21 20:35:59 -05:00
dynapi Fixed updated return value for SDL_GL_SwapWindow() 2016-12-12 09:19:48 -08:00
events Fixed crash at startup 2016-12-03 09:59:43 -08:00
file Updated copyright to 2016 2016-01-02 10:10:34 -08:00
filesystem Fixed compiling if filesystem is disabled (thanks, Elias!). 2016-08-30 21:14:13 +02:00
haptic Renaming of guard header names to quiet -Wreserved-id-macro 2016-11-20 21:34:54 -08:00
joystick Fixed crash if allocating memory for game controller failed. 2016-12-28 20:10:48 +01:00
libm Fixed all known static analysis bugs, with checker-279 on macOS. 2016-11-24 21:41:09 -05:00
loadso Fixed bug 3478 - Patch Haiku to use dlopen instead of load_add_on 2016-11-01 10:30:46 -07:00
main Fixed bug 3461 - Implement TEXTINPUT events for Haiku 2016-10-19 20:42:22 -07:00
power Fixed missing prototypes on Android, patch from Sylvain 2016-12-02 02:25:12 -08:00
render Fixed all known static analysis bugs, with checker-279 on macOS. 2016-11-24 21:41:09 -05:00
stdlib Fixed bug 3531 - internal SDL_vsnprintf implementation access memory outside given buffer ranges 2016-12-31 16:14:51 -08:00
test Still more compiler warning fixes for various platforms. 2016-11-23 17:20:28 -05:00
thread Renaming of guard header names to quiet -Wreserved-id-macro 2016-11-20 21:34:54 -08:00
timer Patch from Sylvain to fix clang warnings 2016-11-13 22:57:41 -08:00
video Fixed bug 3541 - DisplayIndex out of bounds in SDL_SetWindowPosition 2016-12-31 10:30:07 -08:00
SDL.c Patch from Sylvain to fix clang warnings 2016-11-13 22:57:41 -08:00
SDL_assert.c Fixed bug 1646 - Warnings from clang with -Weverything 2016-11-15 01:30:08 -08:00
SDL_assert_c.h Updated copyright to 2016 2016-01-02 10:10:34 -08:00
SDL_dataqueue.c Refactored the audio queueing code to a generic SDL_DataQueue interface. 2016-12-06 02:23:54 -05:00
SDL_dataqueue.h Refactored the audio queueing code to a generic SDL_DataQueue interface. 2016-12-06 02:23:54 -05:00
SDL_error.c Still more compiler warning fixes for various platforms. 2016-11-23 17:20:28 -05:00
SDL_error_c.h Renaming of guard header names to quiet -Wreserved-id-macro 2016-11-20 21:34:54 -08:00
SDL_hints.c Implemented SDL_GetHintBoolean() to make it easier to check boolean hints 2016-10-07 23:40:44 -07:00
SDL_internal.h Added SDL_VARIABLE_LENGTH_ARRAY so this #ifdef is localized to one place. 2016-12-06 02:20:58 -05:00
SDL_log.c Removed unneeded warning when running from Visual Studio 2016-12-07 11:02:02 -08:00