From 6f3b31043d89324c6b406286c1561ca0a213ba48 Mon Sep 17 00:00:00 2001 From: Michael Marley Date: Sat, 11 Dec 2021 20:56:54 -0500 Subject: [PATCH] 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. --- src/utils.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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)) -- 2.47.2