summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2012-05-02 23:18:38 -0700
committerMark Adler <madler@alumni.caltech.edu>2012-05-02 23:18:38 -0700
commitc58f7ab28d5fc346032592414055db4edcc18050 (patch)
treedfbaf405ca98d3101fb8c7319c17846b23c6aad5 /test
parent2689b3cceb054f83d4d084ffc1db09606b0c2515 (diff)
downloadProject-Tick-c58f7ab28d5fc346032592414055db4edcc18050.tar.gz
Project-Tick-c58f7ab28d5fc346032592414055db4edcc18050.zip
Replace use of unsafe string functions with snprintf if available.
This avoids warnings in OpenBSD that apparently can't be turned off whenever you link strcpy, strcat, or sprintf. When snprintf isn't available, the use of the "unsafe" string functions has always in fact been safe, since the lengths are all checked before those functions are called. We do not use strlcpy or strlcat, since they are not (yet) found on all systems. snprintf on the other hand is part of the C standard library and is very common.
Diffstat (limited to 'test')
-rw-r--r--test/minigzip.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/minigzip.c b/test/minigzip.c
index aa7ac7a049..0a1f81f770 100644
--- a/test/minigzip.c
+++ b/test/minigzip.c
@@ -463,8 +463,12 @@ void file_compress(file, mode)
exit(1);
}
+#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
+ snprintf(outfile, sizeof(outfile), "%s%s", file, GZ_SUFFIX);
+#else
strcpy(outfile, file);
strcat(outfile, GZ_SUFFIX);
+#endif
in = fopen(file, "rb");
if (in == NULL) {
@@ -499,7 +503,11 @@ void file_uncompress(file)
exit(1);
}
+#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
+ snprintf(buf, sizeof(buf), "%s", file);
+#else
strcpy(buf, file);
+#endif
if (len > SUFFIX_LEN && strcmp(file+len-SUFFIX_LEN, GZ_SUFFIX) == 0) {
infile = file;
@@ -508,7 +516,11 @@ void file_uncompress(file)
} else {
outfile = file;
infile = buf;
+#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
+ snprintf(buf + len, sizeof(buf) - len, "%s", GZ_SUFFIX);
+#else
strcat(infile, GZ_SUFFIX);
+#endif
}
in = gzopen(infile, "rb");
if (in == NULL) {
@@ -546,7 +558,11 @@ int main(argc, argv)
gzFile file;
char *bname, outmode[20];
+#if !defined(NO_snprintf) && !defined(NO_vsnprintf)
+ snprintf(outmode, sizeof(outmode), "%s", "wb6 ");
+#else
strcpy(outmode, "wb6 ");
+#endif
prog = argv[0];
bname = strrchr(argv[0], '/');