Commit 42eab5a2 authored by unknown's avatar unknown

Fixing wrong memory read problem detected by Valgrind in "xml" test.

The source of the problem was in my_vsnprintf() implementation.


strings/my_vsnprintf.c:
  Fixing a problem in vsnprintf('%.*s', len, ptr)
  When processing the above format, it's incorrect
  to use strlen() because the string is not necessarily
  a null terminated string.
  Changing strlen() followed by set_if_smaller()
  to strnlen() - which covers both cases - limiting
  by '\0' and by "len".
parent b3949122
...@@ -95,8 +95,7 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap) ...@@ -95,8 +95,7 @@ int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
reg2 char *par = va_arg(ap, char *); reg2 char *par = va_arg(ap, char *);
uint plen,left_len = (uint)(end-to)+1; uint plen,left_len = (uint)(end-to)+1;
if (!par) par = (char*)"(null)"; if (!par) par = (char*)"(null)";
plen = (uint) strlen(par); plen= (uint) strnlen(par, width);
set_if_smaller(plen,width);
if (left_len <= plen) if (left_len <= plen)
plen = left_len - 1; plen = left_len - 1;
to=strnmov(to,par,plen); to=strnmov(to,par,plen);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment