]> sourceware.org Git - systemtap.git/commitdiff
code hygiene: some more coverity cleanups
authorFrank Ch. Eigler <fche@redhat.com>
Tue, 1 Nov 2011 12:04:55 +0000 (08:04 -0400)
committerFrank Ch. Eigler <fche@redhat.com>
Tue, 1 Nov 2011 12:04:55 +0000 (08:04 -0400)
* 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
stap-serverd.cxx
util.cxx

index 450cbf282c7e197ebc18bbdf0fd2d17492fd34c4..58e1c69b979e96e39b7a5afe5626afaf8c21cb4e 100644 (file)
@@ -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)
index 9dab0d58232c758072689571af6ecb1c275f4aa9..87fcec4e4d48ba07bf6b5358e398a82eb8883a47 100644 (file)
@@ -968,8 +968,10 @@ get_stap_locale (const string &staplang, vector<string> &envVec)
   for (unsigned i=0; environ[i]; i++)
     {
       vector<string> 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<string> &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);
index c54e286f632f98dbbf47ab57eaf50265c96f3d9f..7516c2bf77e0185ca725b86a226dc4f3b3dec1df 100644 (file)
--- 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<string>& 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
This page took 0.037559 seconds and 5 git commands to generate.