From af6125fbcc51b2074321003c3cbd74aeb65d9b7b Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Fri, 11 May 2018 13:59:26 -0400 Subject: Fix gcc8 warnings. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Attempting to compile pacman with gcc8 results in several warnings like: remove.c: In function ‘unlink_file.isra.4’: remove.c:407:34: warning: ‘.pacsave.’ directive output may be truncated writing 9 bytes into a region of size between 1 and 4096 [-Wformat-truncation=] Fix by adding checks to error out if snprintf tries to reserve a truncated filename. Because the return values are checked, gcc delegates the truncation response to our code instead of throwing warnings. Signed-off-by: Eli Schwartz Signed-off-by: Allan McRae --- lib/libalpm/remove.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index a83710ed..8b92a084 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -404,14 +404,22 @@ static void shift_pacsave(alpm_handle_t *handle, const char *file) /* Shift pacsaves */ unsigned long i; for(i = log_max + 1; i > 1; i--) { - snprintf(oldfile, PATH_MAX, "%s.pacsave.%lu", file, i-1); - snprintf(newfile, PATH_MAX, "%s.pacsave.%lu", file, i); + if(snprintf(oldfile, PATH_MAX, "%s.pacsave.%lu", file, i-1) >= PATH_MAX + || snprintf(newfile, PATH_MAX, "%s.pacsave.%lu", file, i) >= PATH_MAX) { + _alpm_log(handle, ALPM_LOG_ERROR, + _("could not backup %s due to PATH_MAX overflow\n"), file); + goto cleanup; + } rename(oldfile, newfile); } - snprintf(oldfile, PATH_MAX, "%s.pacsave", file); + if(snprintf(oldfile, PATH_MAX, "%s.pacsave", file) >= PATH_MAX + || snprintf(newfile, PATH_MAX, "%s.1", oldfile) >= PATH_MAX) { + _alpm_log(handle, ALPM_LOG_ERROR, + _("could not backup %s due to PATH_MAX overflow\n"), file); + goto cleanup; + } if(stat(oldfile, &st) == 0) { - snprintf(newfile, PATH_MAX, "%s.1", oldfile); rename(oldfile, newfile); } -- cgit v1.2.3-54-g00ecf