]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Check the return code of snprintf in utils.c:rmtree
authorMichael Marley <michael@michaelmarley.com>
Sun, 12 Dec 2021 01:56:54 +0000 (20:56 -0500)
committerFlole998 <Flole998@users.noreply.github.com>
Sun, 12 Dec 2021 22:08:16 +0000 (23:08 +0100)
And return -ENAMETOOLONG if the string overflowed.  This fixes the
FTBFS on s390x with recent glibc/gcc versions.

This fixes #5949.

src/utils.c

index a23ef2524db5a55eeaca3002f11c2ed7fd24e87c..d8ffe4ad5c339229c6365158bee30888e78eefb8 100644 (file)
@@ -29,6 +29,7 @@
 #include <ctype.h>
 #include <signal.h>
 #include <net/if.h>
+#include <errno.h>
 
 #include <openssl/sha.h>
 
@@ -701,7 +702,10 @@ rmtree ( const char *path )
   while (!readdir_r(dir, &de, &der) && der) {
     if (!strcmp("..", de.d_name) || !strcmp(".", de.d_name))
       continue;
-    snprintf(buf, sizeof(buf), "%s/%s", path, de.d_name);
+    if (snprintf(buf, sizeof(buf), "%s/%s", path, de.d_name) >= sizeof(buf)) {
+        err = -ENAMETOOLONG;
+        break;
+    }
     err = stat(buf, &st);
     if (err) break;
     if (S_ISDIR(st.st_mode))