diff --git a/capi20.old/capiutils.h b/capi20.old/capiutils.h index 27b77fe6..2f2fcdbd 100644 --- a/capi20.old/capiutils.h +++ b/capi20.old/capiutils.h @@ -322,6 +322,10 @@ char *capi_info2str(_cword reason); #define capi20_cmd2str capi_cmd2str char *capi_cmd2str(_cbyte cmd, _cbyte subcmd); +/* + * WARNING: The following two functions use a single static buffer and + * are not thread-safe. + */ #define capi20_cmsg2str capi_cmsg2str char *capi_cmsg2str(_cmsg * cmsg); diff --git a/capi20.old/convert.c b/capi20.old/convert.c index fa513c87..2cf466f7 100644 --- a/capi20.old/convert.c +++ b/capi20.old/convert.c @@ -897,10 +897,14 @@ static char *p = 0; static void bufprint(char *fmt,...) { va_list f; + size_t space = buf + sizeof(buf) - p, len; va_start(f, fmt); - vsprintf(p, fmt, f); + len = vsnprintf(p, space, fmt, f); va_end(f); - p += strlen(p); + if (len < space - 1) + p += len; + else + p += space - 1; } static void printstructlen(_cbyte * m, unsigned len) diff --git a/capi20/capiutils.h b/capi20/capiutils.h index 51233966..a88e8d46 100644 --- a/capi20/capiutils.h +++ b/capi20/capiutils.h @@ -370,6 +370,10 @@ char *capi_info2str(_cword reason); #define capi20_cmd2str capi_cmd2str char *capi_cmd2str(_cbyte cmd, _cbyte subcmd); +/* + * WARNING: The following two functions use a single static buffer and + * are not thread-safe. + */ #define capi20_cmsg2str capi_cmsg2str char *capi_cmsg2str(_cmsg * cmsg); diff --git a/capi20/convert.c b/capi20/convert.c index f9bc7c7c..393409ee 100644 --- a/capi20/convert.c +++ b/capi20/convert.c @@ -842,10 +842,14 @@ static char *p = 0; static void bufprint(char *fmt,...) { va_list f; + size_t space = buf + sizeof(buf) - p, len; va_start(f, fmt); - vsprintf(p, fmt, f); + len = vsnprintf(p, space, fmt, f); va_end(f); - p += strlen(p); + if (len < space - 1) + p += len; + else + p += space - 1; } static void printstructlen(_cbyte * m, unsigned len)