[FFmpeg-cvslog] avutil/avstring: Check for memory allocation error in av_escape

Andreas Rheinhardt git at videolan.org
Mon Mar 15 08:01:58 EET 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Tue Mar  9 21:25:06 2021 +0100| [520754476d9c2627b610fb9c508d0a85182d5a87] | committer: Andreas Rheinhardt

avutil/avstring: Check for memory allocation error in av_escape

av_bprint_finalize() can still fail even when it has been checked that
the AVBPrint is currently complete: Namely if the string was so short
that it fit into the AVBPrint's internal buffer.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=520754476d9c2627b610fb9c508d0a85182d5a87
---

 libavutil/avstring.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 832bec750f..49e8df55aa 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -336,6 +336,7 @@ int av_escape(char **dst, const char *src, const char *special_chars,
               enum AVEscapeMode mode, int flags)
 {
     AVBPrint dstbuf;
+    int ret;
 
     av_bprint_init(&dstbuf, 1, INT_MAX); /* (int)dstbuf.len must be >= 0 */
     av_bprint_escape(&dstbuf, src, special_chars, mode, flags);
@@ -343,10 +344,10 @@ int av_escape(char **dst, const char *src, const char *special_chars,
     if (!av_bprint_is_complete(&dstbuf)) {
         av_bprint_finalize(&dstbuf, NULL);
         return AVERROR(ENOMEM);
-    } else {
-        av_bprint_finalize(&dstbuf, dst);
-        return dstbuf.len;
     }
+    if ((ret = av_bprint_finalize(&dstbuf, dst)) < 0)
+        return ret;
+    return dstbuf.len;
 }
 
 int av_match_name(const char *name, const char *names)



More information about the ffmpeg-cvslog mailing list