From bedf9e129597380eb865de17abe3245d90076158 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 25 Sep 2010 09:27:44 +0200 Subject: [PATCH] avoid printf format abuse; use -Wformat-security; report errno more A use like "error(0,errno,cfg_file)" would malfunction for a file name containing a printf %-directive. Using -Wformat-security will help prevent this. Upon OOM, always use errno in the diagnostic. --- Makefile.am | 2 +- proxy.c | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Makefile.am b/Makefile.am index ed09056..6a22e11 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,7 +13,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -AM_CFLAGS = -W -Wall -Wextra -Wno-unused \ +AM_CFLAGS = -W -Wall -Wextra -Wno-unused -Wformat-security \ -Wp,-D_FORTIFY_SOURCE=2 -O2 -fdiagnostics-show-option AM_CPPFLAGS = -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include diff --git a/proxy.c b/proxy.c index 493b63d..ba34b8e 100644 --- a/proxy.c +++ b/proxy.c @@ -210,7 +210,7 @@ parse_config (void) unsigned int i; if (access(cfg_file,R_OK) < 0) { - error(0,errno,cfg_file); + error(0,errno,"failed to open %s for reading", cfg_file); return NULL; } @@ -282,7 +282,7 @@ proxy_repl_prod_fs (void *ctx) ibytes = read(ifd,buf,sizeof(buf)); if (ibytes <= 0) { if (ibytes < 0) { - error(0,errno,"read"); + error(0,errno,"%s: read failed", item->path); } else { DPRINTF("EOF on ifd\n"); @@ -847,12 +847,17 @@ replicate (const char *url, size_t size, const char *policy) DPRINTF("REPLICATING %s to %u\n",url,i); item = malloc(sizeof(*item)); if (!item) { - error(0,0,"could not create repl_item for %s\n", - url); + error(0,errno,"could not create repl_item for %s\n", + url); break; } item->type = REPL_PUT; item->path = strdup(url); + if (!item->path) { + error(0,errno,"could not create repl_item for %s\n", + url); + break; + } item->server = i; item->size = size; pthread_mutex_lock(&queue_lock); @@ -885,8 +890,8 @@ replicate_namespace_action (const char *name, repl_t action) DPRINTF("replicating delete(%s) on %u\n",name,i); item = malloc(sizeof(*item)); if (!item) { - error(0,0,"could not create repl_item for %s\n", - name); + error(0,errno,"could not create repl_item for %s\n", + name); return; } item->type = action; -- 2.11.4.GIT