From 3eddbcc25ef574253f4a9d0406245e816fb89411 Mon Sep 17 00:00:00 2001 From: dholland Date: Sun, 27 Jul 2014 04:38:03 +0000 Subject: [PATCH] Fix broken snprintf usage; noted in PR 47976 from Henning Petersen. As a bonus, this removes the nonliteral format arguments. --- common/Makefile | 3 +-- common/log.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/common/Makefile b/common/Makefile index 5f27095..1e5aac8 100644 --- a/common/Makefile +++ b/common/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.19 2012/08/10 12:10:29 joerg Exp $ +# $NetBSD: Makefile,v 1.20 2014/07/27 04:38:03 dholland Exp $ LIBISPRIVATE= yes @@ -21,4 +21,3 @@ version.c: VERSION .include COPTS.print.c+= -Wno-pointer-sign -COPTS.log.c+= -Wno-format-nonliteral diff --git a/common/log.c b/common/log.c index 15b9ee0..1d8f973 100644 --- a/common/log.c +++ b/common/log.c @@ -1,4 +1,4 @@ -/* $NetBSD: log.c,v 1.2 2008/04/28 20:24:17 martin Exp $ */ +/* $NetBSD: log.c,v 1.3 2014/07/27 04:38:03 dholland Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include #ifndef lint -__RCSID("$NetBSD: log.c,v 1.2 2008/04/28 20:24:17 martin Exp $"); +__RCSID("$NetBSD: log.c,v 1.3 2014/07/27 04:38:03 dholland Exp $"); #endif #include @@ -47,13 +47,15 @@ mopLogErr(const char *fmt, ...) { va_list ap; char buf[1024]; + int error; va_start(ap, fmt); if (mopInteractive) verr(1, fmt, ap); else { - snprintf(buf, sizeof(buf), "%s: %%m", buf); - vsyslog(LOG_ERR, buf, ap); + error = errno; + vsnprintf(buf, sizeof(buf), fmt, ap); + syslog(LOG_ERR, "%s: %s", buf, strerror(error)); } va_end(ap); exit(1); @@ -64,13 +66,15 @@ mopLogWarn(const char *fmt, ...) { va_list ap; char buf[1024]; + int error; va_start(ap, fmt); if (mopInteractive) vwarn(fmt, ap); else { - snprintf(buf, sizeof(buf), "%s: %%m", buf); - vsyslog(LOG_WARNING, buf, ap); + error = errno; + vsnprintf(buf, sizeof(buf), fmt, ap); + syslog(LOG_WARNING, "%s: %s", buf, strerror(error)); } va_end(ap); }