From: Michael Marley Date: Sun, 12 Dec 2021 01:56:54 +0000 (-0500) Subject: Check the return code of snprintf in utils.c:rmtree X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f3b31043d89324c6b406286c1561ca0a213ba48;p=thirdparty%2Ftvheadend.git Check the return code of snprintf in utils.c:rmtree And return -ENAMETOOLONG if the string overflowed. This fixes the FTBFS on s390x with recent glibc/gcc versions. This fixes #5949. --- diff --git a/src/utils.c b/src/utils.c index a23ef2524..d8ffe4ad5 100644 --- a/src/utils.c +++ b/src/utils.c @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -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))