[vlc-commits] memstream: vlc_memstream_vprintf: handle vsnprintf failure

Filip Roséen git at videolan.org
Mon Feb 27 18:10:04 CET 2017


vlc | branch: master | Filip Roséen <filip at atch.se> | Mon Feb 27 02:58:03 2017 +0100| [7933177bff28b95cb5df9e3855e8a17ade255eba] | committer: Rémi Denis-Courmont

memstream: vlc_memstream_vprintf: handle vsnprintf failure

If there is an output error in the call to vsnprintf in
"len = vsnprintf( ... )", len would be negative; leading to undefined
behavior further down the road.

Signed-off-by: Rémi Denis-Courmont <remi at remlab.net>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7933177bff28b95cb5df9e3855e8a17ade255eba
---

 src/text/memstream.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/text/memstream.c b/src/text/memstream.c
index 5dba5f2..093a419 100644
--- a/src/text/memstream.c
+++ b/src/text/memstream.c
@@ -164,6 +164,9 @@ int vlc_memstream_vprintf(struct vlc_memstream *ms, const char *fmt,
     len = vsnprintf(NULL, 0, fmt, ap);
     va_end(ap);
 
+    if (len < 0)
+        goto error;
+
     ptr = realloc(ms->ptr, ms->length + len + 1);
     if (ptr == NULL)
         goto error;



More information about the vlc-commits mailing list