Fix broken snprintf usage; noted in PR 47976 from Henning Petersen.

As a bonus, this removes the nonliteral format arguments.
This commit is contained in:
dholland
2014-07-27 04:38:03 +00:00
parent a3206cf133
commit 3eddbcc25e
2 changed files with 11 additions and 8 deletions

View File

@@ -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 <bsd.lib.mk>
COPTS.print.c+= -Wno-pointer-sign
COPTS.log.c+= -Wno-format-nonliteral

View File

@@ -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 <sys/cdefs.h>
#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 <err.h>
@@ -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);
}