]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
Fix various issues discovered by Coverity
authorNeil Brown <neilb@suse.de>
Fri, 23 Jun 2006 04:38:33 +0000 (14:38 +1000)
committerNeil Brown <neilb@suse.de>
Fri, 23 Jun 2006 04:38:33 +0000 (14:38 +1000)
Thanks to Michael Halcrow for finding them.

support/misc/mountpoint.c
support/nfs/cacheio.c
support/nfs/svc_socket.c
tools/rpcgen/rpc_parse.c
tools/rpcgen/rpc_scan.c
utils/idmapd/cfg.c
utils/idmapd/idmapd.c
utils/rquotad/rquota_server.c
utils/statd/notlist.c

index 6d0f34eab4954826fd636dcf3a5dd4f1eef6b35f..2cf1324fb17a9674109221fd49dde2643f65577a 100644 (file)
@@ -20,15 +20,21 @@ is_mountpoint(char *path)
         */
        char *dotdot;
        struct stat stb, pstb;
+       int rv;
 
        dotdot = malloc(strlen(path)+4);
+       if (!dotdot)
+               return 0;
        strcat(strcpy(dotdot, path), "/..");
        if (lstat(path, &stb) != 0 ||
            lstat(dotdot, &pstb) != 0)
-               return 0;
-
-       if (stb.st_dev != pstb.st_dev
-           || stb.st_ino == pstb.st_ino)
-               return 1;
-       return 0;
+               rv = 0;
+       else
+               if (stb.st_dev != pstb.st_dev ||
+                   stb.st_ino == pstb.st_ino)
+                       rv = 1;
+               else
+                       rv = 0;
+       free(dotdot);
+       return rv;
 }
index d7ad4293762f4b6dd583fec668cb0ea9df47b733..3e868d8843e9c9153be7ee595eec4517ec5cd5b4 100644 (file)
@@ -259,9 +259,9 @@ cache_flush(int force)
                "nfsd.export",
                NULL
        };
-       stb.st_mtime = time(0);
-       if (!force)
-               stat(_PATH_ETAB, &stb);
+       if (force ||
+           stat(_PATH_ETAB, &stb) != 0)
+               stb.st_mtime = time(0);
        
        sprintf(stime, "%ld\n", stb.st_mtime);
        for (c=0; cachelist[c]; c++) {
index 888c915931b000f42d86d026bc94e86ed8329139..c41a1a3b15f7154f7c497e121516e6d4487bdbf8 100644 (file)
@@ -42,7 +42,7 @@ svc_socket (u_long number, int type, int protocol, int reuse)
   socklen_t len = sizeof (struct sockaddr_in);
   char rpcdata [1024], servdata [1024];
   struct rpcent rpcbuf, *rpcp;
-  struct servent servbuf, *servp;
+  struct servent servbuf, *servp = NULL;
   int sock, ret;
   const char *proto = protocol == IPPROTO_TCP ? "tcp" : "udp";
 
index 577312ecb109d7f396ac994e4a692422f93a0612..70d1260e12f1ab2df493bceb1eedb43409aac523 100644 (file)
@@ -94,6 +94,7 @@ get_definition(void)
                def_const(defp);
                break;
        case TOK_EOF:
+               free(defp);
                return (NULL);
        default:
                error("definition keyword expected");
@@ -290,7 +291,6 @@ def_union(definition *defp)
   declaration dec;
   case_list *cases;
   case_list **tailp;
-  int flag;
 
   defp->def_kind = DEF_UNION;
   scan(TOK_IDENT, &tok);
@@ -309,7 +309,6 @@ def_union(definition *defp)
     cases->case_name = tok.str;
     scan(TOK_COLON, &tok);
     /* now peek at next token */
-    flag=0;
     if(peekscan(TOK_CASE,&tok))
       {
 
@@ -325,14 +324,6 @@ def_union(definition *defp)
       
          }while(peekscan(TOK_CASE,&tok));
       }
-    else
-      if(flag)
-       {
-
-         *tailp = cases;
-         tailp = &cases->next;
-         cases = ALLOC(case_list);
-       };
 
     get_declaration(&dec, DEF_UNION);
     cases->case_decl = dec;
index 62d906d7d077de540a42eac607c3e6b7420e1664..51eecfee750539023346281e2b8a9cbbe5ce480e 100644 (file)
@@ -468,6 +468,7 @@ docppline(char *line, int *lineno, char **fname)
        *p = 0;
        if (*file == 0) {
                *fname = NULL;
+               free(file);
        } else {
                *fname = file;
        }
index b22a7c9744443b7ca0da942914a7225cfb003bc2..16d392a951071a19ffa9319b86a3dbe3c2ebc1e9 100644 (file)
@@ -487,8 +487,10 @@ conf_get_list (char *section, char *tag)
       if (!node)
        goto cleanup;
       node->field = strdup (field);
-      if (!node->field)
+      if (!node->field) {
+       free(node);
        goto cleanup;
+      }
       TAILQ_INSERT_TAIL (&list->fields, node, link);
     }
   free (liststr);
@@ -523,8 +525,10 @@ conf_get_tag_list (char *section)
        if (!node)
          goto cleanup;
        node->field = strdup (cb->tag);
-       if (!node->field)
+       if (!node->field) {
+         free(node);
          goto cleanup;
+       }
        TAILQ_INSERT_TAIL (&list->fields, node, link);
       }
   return list;
@@ -708,7 +712,7 @@ conf_remove (int transaction, char *section, char *tag)
   return 0;
 
  fail:
-  if (node->section)
+  if (node && node->section)
     free (node->section);
   if (node)
     free (node);
index 158feaf66c11627beb931ab253d7c56cb9722c6b..1231db4045dab5023dfc3504c3111ce44aef6eab 100644 (file)
@@ -1003,9 +1003,11 @@ mydaemon(int nochdir, int noclose)
 
        if (noclose == 0) {
                tempfd = open("/dev/null", O_RDWR);
-               dup2(tempfd, 0);
-               dup2(tempfd, 1);
-               dup2(tempfd, 2);
+               if (tempfd >= 0) {
+                       dup2(tempfd, 0);
+                       dup2(tempfd, 1);
+                       dup2(tempfd, 2);
+               }
                closeall(3);
        }
 
index 109c94e45cc014fee50a6dce20f000dceefc9cfa..e3715bd933a0769be9f7f9284c73baebe8f7641c 100644 (file)
@@ -201,7 +201,6 @@ getquota_rslt *getquotainfo(int flags, caddr_t *argp, struct svc_req *rqstp)
                                      free(qfpathname);
                                      continue;
                              }
-                             free(qfpathname);
                              lseek(fd, (long) dqoff(id), L_SET);
                              switch (read(fd, &dq_dqb, sizeof(struct dqblk))) {
                              case 0:/* EOF */
@@ -215,6 +214,7 @@ getquota_rslt *getquotainfo(int flags, caddr_t *argp, struct svc_req *rqstp)
                                      break;
                              default:   /* ERROR */
                                      close(fd);
+                                     free(qfpathname);
                                      continue;
                              }
                              close(fd);
@@ -228,6 +228,7 @@ getquota_rslt *getquotainfo(int flags, caddr_t *argp, struct svc_req *rqstp)
                      dqb.dqb_btime = dq_dqb.dqb_btime;
                      dqb.dqb_itime = dq_dqb.dqb_itime;
              }
+             free(qfpathname);
          endmntent(fp);
 
          if (err && (flags & ACTIVE)) {
index 4f52b1deccb3c41ab6e7550baf3324bebaeb26ad..98aa6e2fa3a2571871f148cef70e27e284076db7 100644 (file)
@@ -61,8 +61,12 @@ nlist_new(char *my_name, char *mon_name, int state)
        NL_TIMES(new) = MAX_TRIES;
        NL_STATE(new) = state;
        if (!(NL_MY_NAME(new) = xstrdup(my_name))
-                       || !(NL_MON_NAME(new) = xstrdup(mon_name)))
+           || !(NL_MON_NAME(new) = xstrdup(mon_name))) {
+               if (NL_MY_NAME(new))
+                       free(NL_MY_NAME(new));
+               free(new);
                return NULL;
+       }
 
        return new;
 }