summaryrefslogtreecommitdiff
path: root/sbin/pdisk
diff options
context:
space:
mode:
authorPeter Valchev <pvalchev@cvs.openbsd.org>2003-04-24 17:48:31 +0000
committerPeter Valchev <pvalchev@cvs.openbsd.org>2003-04-24 17:48:31 +0000
commit3c9553c3061dee4d502abef038244c83cb546d90 (patch)
tree3976df1fe4d644e467858274b4bd5aeb6938b339 /sbin/pdisk
parent0fe23fcd7c5f09b4e8a341831cb14f5fbc7bd4a1 (diff)
get rid of incorrectly sized buffer by using asprintf; ok millert
Diffstat (limited to 'sbin/pdisk')
-rw-r--r--sbin/pdisk/pdisk.c11
-rw-r--r--sbin/pdisk/util.c27
2 files changed, 22 insertions, 16 deletions
diff --git a/sbin/pdisk/pdisk.c b/sbin/pdisk/pdisk.c
index ce373b30fc3..cb371e05bdc 100644
--- a/sbin/pdisk/pdisk.c
+++ b/sbin/pdisk/pdisk.c
@@ -152,6 +152,7 @@ main(int argc, char **argv)
SIOUXSettings.autocloseonquit = 0; /* Do we close the SIOUX window on program termination ... */
SIOUXSettings.asktosaveonclose = 0; /* Do we offer to save on a close ... */
#endif
+ char *versionstr;
init_program_name(argv);
@@ -165,9 +166,13 @@ main(int argc, char **argv)
"is not equal to block size (%d)\n",
sizeof(Block0), PBLOCK_SIZE);
}
- if (strcmp(VERSION, get_version_string()) != 0) {
- fatal(-1, "Version string static form (%s) does not match dynamic form (%s)\n",
- VERSION, get_version_string());
+ versionstr = (char *)get_version_string();
+ if (versionstr) {
+ if (strcmp(VERSION, versionstr) != 0) {
+ fatal(-1, "Version string static form (%s) does not match dynamic form (%s)\n",
+ VERSION, versionstr);
+ }
+ free(versionstr);
}
#if defined(__linux__) || defined(__OpenBSD__)
diff --git a/sbin/pdisk/util.c b/sbin/pdisk/util.c
index 120de895bc8..68fc272d8b8 100644
--- a/sbin/pdisk/util.c
+++ b/sbin/pdisk/util.c
@@ -28,6 +28,7 @@
#include <stdio.h>
#include <ctype.h>
+#include <err.h>
#include "version.h"
#include "util.h"
@@ -57,11 +58,6 @@
/*
- * Global Variables
- */
-static char dynamic_version[10];
-
-/*
* Forward declarations
*/
@@ -130,6 +126,7 @@ const char *
get_version_string(void)
{
int stage;
+ char *dynamic_version;
/* "copy" of stuff from SysTypes.r, since we can't include that*/
enum {development = 0x20, alpha = 0x40, beta = 0x60, final = 0x80, /* or */ release = 0x80};
@@ -143,19 +140,23 @@ get_version_string(void)
if (kVersionBugFix != 0) {
if (kVersionStage == final) {
- snprintf(dynamic_version, sizeof dynamic_version, "%d.%d.%d",
- kVersionMajor, kVersionMinor, kVersionBugFix);
+ if (asprintf(&dynamic_version, "%d.%d.%d", kVersionMajor,
+ kVersionMinor, kVersionBugFix) == -1)
+ err(1, "asprintf");
} else {
- snprintf(dynamic_version, sizeof dynamic_version, "%d.%d.%d%c%d",
- kVersionMajor, kVersionMinor, kVersionBugFix, stage, kVersionDelta);
+ if (asprintf(&dynamic_version, "%d.%d.%d%c%d", kVersionMajor,
+ kVersionMinor, kVersionBugFix, stage, kVersionDelta) == -1)
+ err(1, "asprintf");
}
} else {
if (kVersionStage == final) {
- snprintf(dynamic_version, sizeof dynamic_version, "%d.%d",
- kVersionMajor, kVersionMinor);
+ if (asprintf(&dynamic_version, "%d.%d", kVersionMajor,
+ kVersionMinor) == -1)
+ err(1, "asprintf");
} else {
- snprintf(dynamic_version, sizeof dynamic_version, "%d.%d%c%d",
- kVersionMajor, kVersionMinor, stage, kVersionDelta);
+ if (asprintf(&dynamic_version, "%d.%d%c%d", kVersionMajor,
+ kVersionMinor, stage, kVersionDelta) == -1)
+ err(1, "asprintf");
}
}
return dynamic_version;