sdl2_frt/src/stdlib
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
..
SDL_getenv.c Updated copyright to 2016 2016-01-02 10:10:34 -08:00
SDL_iconv.c Still more compiler warning fixes for various platforms. 2016-11-23 17:20:28 -05:00
SDL_malloc.c Updated copyright to 2016 2016-01-02 10:10:34 -08:00
SDL_qsort.c Fixed signed/unsigned comparison warnings in Visual Studio 2016-11-11 03:18:16 -08:00
SDL_stdlib.c Fixed bug 3468 - _allshr in SDL_stdlib.c is not working properly 2016-11-06 10:01:08 -08:00
SDL_string.c Fixed bug 3531 - internal SDL_vsnprintf implementation access memory outside given buffer ranges 2016-12-31 16:14:51 -08:00