From 1d7ae21bfe1e4698ce6f2e4fc602a6919f9e86f0 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Tue, 1 Nov 2011 08:04:55 -0400 Subject: [PATCH] code hygiene: some more coverity cleanups * nsscommon.cxx (add_client_cert): Check PORT_Alloc() return value. * stap-serverd.cxx (get_stap_locale): Check getenv() return value and localization key=value parsability. * util.cxx (assert_regexp_match, regexp_match): Assert regcomp success. --- nsscommon.cxx | 7 +++++++ stap-serverd.cxx | 9 ++++++++- util.cxx | 10 ++-------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/nsscommon.cxx b/nsscommon.cxx index 450cbf282..58e1c69b9 100644 --- a/nsscommon.cxx +++ b/nsscommon.cxx @@ -745,6 +745,13 @@ add_client_cert (const string &inFileName, const string &db_path) SECItem certDER; certDER.len = info.st_size; certDER.data = (unsigned char *)PORT_Alloc (certDER.len); + if (certDER.data == NULL) + { + nsscommon_error (_F("Could not allocate certDER\n%s", + strerror (errno))); + fclose (inFile); + return SECFailure; + } size_t read = fread (certDER.data, 1, certDER.len, inFile); fclose (inFile); if (read != certDER.len) diff --git a/stap-serverd.cxx b/stap-serverd.cxx index 9dab0d582..87fcec4e4 100644 --- a/stap-serverd.cxx +++ b/stap-serverd.cxx @@ -968,8 +968,10 @@ get_stap_locale (const string &staplang, vector &envVec) for (unsigned i=0; environ[i]; i++) { vector environTok; + const char *value = getenv(environTok[0].c_str()); + if (!value) continue; tokenize(environ[i], environTok, "="); - envMap[environTok[0]] = (string)getenv(environTok[0].c_str()); + envMap[environTok[0]] = string(value); } /* Create regular expression objects to verify lines read from file. Should not allow @@ -993,6 +995,11 @@ get_stap_locale (const string &staplang, vector &envVec) string value; size_t pos; pos = line.find("="); + if (pos == string::npos) + { + client_error(_F("Localization key=value line '%s' cannot be parsed", line.c_str())); + continue; + } key = line.substr(0, pos); pos++; value = line.substr(pos); diff --git a/util.cxx b/util.cxx index c54e286f6..7516c2bf7 100644 --- a/util.cxx +++ b/util.cxx @@ -727,10 +727,7 @@ void assert_regexp_match (const string& name, const string& value, const string& { r = new regex_t; int rc = regcomp (r, re.c_str(), REG_ICASE|REG_NOSUB|REG_EXTENDED); - if (rc) { - cerr << _F("regcomp %s (%s) error rc= %d", re.c_str(), name.c_str(), rc) << endl; - exit(1); - } + assert (rc == 0); compiled[re] = r; } else @@ -757,10 +754,7 @@ int regexp_match (const string& value, const string& re, vector& matches { r = new regex_t; int rc = regcomp (r, re.c_str(), REG_EXTENDED); /* REG_ICASE? */ - if (rc) { - cerr << _F("regcomp %s error rc=%d", re.c_str(), rc) << endl; - return rc; - } + assert (rc == 0); compiled[re] = r; } else -- 2.43.5