tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[PATCH] off-by-one in libexecinfo's rasprintf



I just committed the following change to FreeBSD.
http://svnweb.freebsd.org/changeset/base/258426

  libexecinfo: Include terminating null in byte count

  Otherwise, a formatted string with a strlen equal to the remaining
  buffer space would have the last character omitted (because vsnprintf
  always null-terminates), and later the assert in backtrace_symbols_fmt
  would fail.

Modified:
  head/contrib/libexecinfo/backtrace.c

Modified: head/contrib/libexecinfo/backtrace.c
==============================================================================
--- head/contrib/libexecinfo/backtrace.c        Thu Nov 21 09:19:14
2013        (r258425)
+++ head/contrib/libexecinfo/backtrace.c        Thu Nov 21 14:12:36
2013        (r258426)
@@ -89,7 +89,7 @@ rasprintf(char **buf, size_t *bufsiz, si
                        len = vsnprintf(*buf + offs, *bufsiz - offs, fmt, ap);
                        va_end(ap);

-                       if (len < 0 || (size_t)len < *bufsiz - offs)
+                       if (len < 0 || (size_t)len + 1 < *bufsiz - offs)
                                return len;
                        nbufsiz = MAX(*bufsiz + 512, (size_t)len + 1);
                } else


Home | Main Index | Thread Index | Old Index