Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2018-05-11 13:59:26 -0400
committerAllan McRae <allan@archlinux.org>2018-05-12 21:36:35 +1000
commitaf6125fbcc51b2074321003c3cbd74aeb65d9b7b (patch)
treedbf4a445db1670c21d7c3d42fc90c643fb52a016
parent0d356c27c17fb62ed31327d634748f64c781dc49 (diff)
Fix gcc8 warnings.
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 <eschwartz@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--lib/libalpm/remove.c16
1 files changed, 12 insertions, 4 deletions
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);
}