Skip to content

Commit

Permalink
11280 custr in belt but not braces, bungles vsnprintf() buffer length
Browse files Browse the repository at this point in the history
Reviewed by: Jason King <jason.king@joyent.com>
Reviewed by: Andy Fiddaman <omnios@citrus-it.co.uk>
Approved by: Richard Lowe <richlowe@richlowe.net>
  • Loading branch information
jclulow committed Jul 4, 2019
1 parent ff16829 commit 09cb6b0
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions usr/src/lib/libcustr/common/custr.c
Expand Up @@ -14,7 +14,7 @@
*/

/*
* Copyright 2018 Joyent, Inc.
* Copyright 2019 Joyent, Inc.
*/

#include <stdlib.h>
Expand Down Expand Up @@ -78,8 +78,9 @@ custr_append_vprintf(custr_t *cus, const char *fmt, va_list ap)
int len = vsnprintf(NULL, 0, fmt, ap);
size_t chunksz = STRING_CHUNK_SIZE;

if (len == -1)
if (len < 0) {
return (len);
}

while (chunksz < len) {
chunksz *= 2;
Expand Down Expand Up @@ -120,10 +121,10 @@ custr_append_vprintf(custr_t *cus, const char *fmt, va_list ap)
/*
* Append new string to existing string:
*/
len = vsnprintf(cus->cus_data + cus->cus_strlen,
(uintptr_t)cus->cus_data - (uintptr_t)cus->cus_strlen, fmt, ap);
if (len == -1)
if ((len = vsnprintf(cus->cus_data + cus->cus_strlen,
cus->cus_datalen - cus->cus_strlen, fmt, ap)) < 0) {
return (len);
}
cus->cus_strlen += len;

return (0);
Expand Down

0 comments on commit 09cb6b0

Please sign in to comment.