Module Name: src
Committed By: dholland
Date: Mon May 30 17:34:36 UTC 2016
Modified Files:
src/bin/pax: dumptar.c
Log Message:
Remove undefined behavior in buf(); use buf() as intended in intarg().
While here also add includes to fix the build. Retires PR 50999 from
David Binderman.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/bin/pax/dumptar.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/pax/dumptar.c
diff -u src/bin/pax/dumptar.c:1.2 src/bin/pax/dumptar.c:1.3
--- src/bin/pax/dumptar.c:1.2 Mon Apr 28 20:22:51 2008
+++ src/bin/pax/dumptar.c Mon May 30 17:34:35 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: dumptar.c,v 1.2 2008/04/28 20:22:51 martin Exp $ */
+/* $NetBSD: dumptar.c,v 1.3 2016/05/30 17:34:35 dholland Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,8 +30,12 @@
*/
#include <stdio.h>
-#include <err.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
#include <fcntl.h>
+#include <err.h>
+#include <assert.h>
#include <sys/stat.h>
#include <sys/mman.h>
@@ -39,20 +43,25 @@
#define ussum(a) 1
+/*
+ * Ensure null termination.
+ */
static char *
buf(const char *p, size_t s)
{
static char buf[1024];
- (void)snprintf(buf, sizeof(buf), "%s", p);
+
+ assert(s < sizeof(buf));
+ memcpy(buf, p, s);
buf[s] = '\0';
return buf;
}
-int
+static int
intarg(const char *p, size_t s)
{
char *ep, *b = buf(p, s);
- int r = (int)strtol(p, &ep, 8);
+ int r = (int)strtol(b, &ep, 8);
return r;
}