summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2016-12-07 13:37:20 -0600
committerGerrit Code Review <gerrit2@gerrit.digium.api>2016-12-07 13:37:20 -0600
commit119c41d00193494ddc72abcb3f5d3fa5b12c691e (patch)
tree71d5b599f96b9eb10311dee70ac67e7c21fb7d82
parentfe9f070885811c712f99317c805e3311db2ff2f0 (diff)
parentbf6423a33678d95896cfb6325572dab3a23e6d6a (diff)
Merge "Iostreams: Correct off-by-one error."
-rw-r--r--main/iostream.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/main/iostream.c b/main/iostream.c
index a20a04896..22cd5985c 100644
--- a/main/iostream.c
+++ b/main/iostream.c
@@ -404,7 +404,7 @@ ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buf, size_t
ssize_t ast_iostream_printf(struct ast_iostream *stream, const void *fmt, ...)
{
- char sbuf[256], *buf = sbuf;
+ char sbuf[512], *buf = sbuf;
int len, len2, ret = -1;
va_list va;
@@ -412,15 +412,18 @@ ssize_t ast_iostream_printf(struct ast_iostream *stream, const void *fmt, ...)
len = vsnprintf(buf, sizeof(sbuf), fmt, va);
va_end(va);
- if (len > sizeof(sbuf)) {
- buf = ast_malloc(len);
+ if (len > sizeof(sbuf) - 1) {
+ /* Add one to the string length to accommodate the NULL byte */
+ size_t buf_len = len + 1;
+
+ buf = ast_malloc(buf_len);
if (!buf) {
return -1;
}
va_start(va, fmt);
- len2 = vsnprintf(buf, len, fmt, va);
+ len2 = vsnprintf(buf, buf_len, fmt, va);
va_end(va);
- if (len2 > len) {
+ if (len2 != len) {
goto error;
}
}