From 2195a803799f7cf966472216a6359caa42687bcc Mon Sep 17 00:00:00 2001 From: awnuk Date: Thu, 18 Aug 2011 22:08:26 +0000 Subject: Fixed bugzilla bug #717643 - Fopen without NULL check and other Coverity issues git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@2154 c9f7a03b-bd48-0410-a16d-cbbf54688b0b --- pki/base/native-tools/src/setpin/setpin_options.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/pki/base/native-tools/src/setpin/setpin_options.c b/pki/base/native-tools/src/setpin/setpin_options.c index 6f06efa69..d8ee83a8c 100644 --- a/pki/base/native-tools/src/setpin/setpin_options.c +++ b/pki/base/native-tools/src/setpin/setpin_options.c @@ -31,6 +31,7 @@ extern void exitError(char *errstring); extern int errcode; #define PW_DEFAULT_LENGTH 6 +#define ERR_BUF_LENGTH 512 char *valid_args[] = { "host", "LDAP host [required]", @@ -182,16 +183,10 @@ int equals(char *s, char *t) { } void validateOptions() { - char *errbuf; - - errbuf = (char *)malloc(2048); - if (errbuf == NULL) { - errcode=13; - exitError("Couldn't allocate 'errbuf'."); - } + char errbuf[ERR_BUF_LENGTH]; if (o_nickname && equals(o_ssl,"no")) { - sprintf(errbuf,"specifying nickname doesn't make sense with no SSL"); + snprintf(errbuf, ERR_BUF_LENGTH, "specifying nickname doesn't make sense with no SSL"); goto loser; } @@ -243,7 +238,6 @@ void validateOptions() { } if (o_testpingen) { - free(errbuf); return; } @@ -263,7 +257,6 @@ void validateOptions() { } if (o_setup != NULL) { - free(errbuf); return; } @@ -281,17 +274,15 @@ void validateOptions() { equals(o_hash,"md5") || equals(o_hash,"none")) ) { - sprintf(errbuf,"invalid hash: %s",o_hash); + snprintf(errbuf, ERR_BUF_LENGTH, "invalid hash: %s",o_hash); goto loser; } if (equals(o_hash,"none")) o_hash = NULL; - free(errbuf); return ; loser: - errcode=14; - free(errbuf); + errcode=13; exitError(errbuf); } -- cgit