From 3c9553c3061dee4d502abef038244c83cb546d90 Mon Sep 17 00:00:00 2001 From: Peter Valchev Date: Thu, 24 Apr 2003 17:48:31 +0000 Subject: get rid of incorrectly sized buffer by using asprintf; ok millert --- sbin/pdisk/pdisk.c | 11 ++++++++--- sbin/pdisk/util.c | 27 ++++++++++++++------------- 2 files changed, 22 insertions(+), 16 deletions(-) (limited to 'sbin/pdisk') 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 #include +#include #include "version.h" #include "util.h" @@ -56,11 +57,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; -- cgit v1.2.3