You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by sf...@apache.org on 2011/10/15 23:31:56 UTC

svn commit: r1183728 - in /apr/apr/branches/1.4.x: ./ build/ file_io/netware/ file_io/os2/ file_io/unix/ file_io/win32/ memory/unix/ threadproc/beos/ threadproc/unix/

Author: sf
Date: Sat Oct 15 21:31:55 2011
New Revision: 1183728

URL: http://svn.apache.org/viewvc?rev=1183728&view=rev
Log:
Backport r979891/r1183724:

    Fix various issues found by cppcheck
    - error handling issues
    - use of uninitialized data
    - null pointer dereference
    - unused variables
    - memory/fd leaks
    - broken code in threadproc/beos/proc.c

Modified:
    apr/apr/branches/1.4.x/   (props changed)
    apr/apr/branches/1.4.x/build/aplibtool.c
    apr/apr/branches/1.4.x/build/jlibtool.c
    apr/apr/branches/1.4.x/file_io/netware/pipe.c
    apr/apr/branches/1.4.x/file_io/os2/open.c
    apr/apr/branches/1.4.x/file_io/unix/open.c
    apr/apr/branches/1.4.x/file_io/win32/open.c
    apr/apr/branches/1.4.x/memory/unix/apr_pools.c
    apr/apr/branches/1.4.x/threadproc/beos/proc.c
    apr/apr/branches/1.4.x/threadproc/unix/proc.c
    apr/apr/branches/1.4.x/threadproc/unix/procsup.c

Propchange: apr/apr/branches/1.4.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 15 21:31:55 2011
@@ -1,2 +1,2 @@
-/apr/apr/branches/1.5.x:1083592
-/apr/apr/trunk:733052,747990,748361,748371,748565,748888,748902,748988,749810,760443,782838,783398,783958,784633,784773,788588,793192-793193,794118,794485,795267,799497,800627,809745,809854,810472,811455,813063,821306,829490,831641,835607,905040,908427,910419,917837-917838,983618,990435,1072165,1078845,1183683,1183685-1183686,1183688
+/apr/apr/branches/1.5.x:1083592,1183724
+/apr/apr/trunk:733052,747990,748361,748371,748565,748888,748902,748988,749810,760443,782838,783398,783958,784633,784773,788588,793192-793193,794118,794485,795267,799497,800627,809745,809854,810472,811455,813063,821306,829490,831641,835607,905040,908427,910419,917837-917838,979891,983618,990435,1072165,1078845,1183683,1183685-1183686,1183688

Modified: apr/apr/branches/1.4.x/build/aplibtool.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/build/aplibtool.c?rev=1183728&r1=1183727&r2=1183728&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/build/aplibtool.c (original)
+++ apr/apr/branches/1.4.x/build/aplibtool.c Sat Oct 15 21:31:55 2011
@@ -230,7 +230,6 @@ bool parse_input_file_name(char *arg, cm
 {
     char *ext = strrchr(arg, '.');
     char *name = strrchr(arg, '/');
-    int pathlen;
     char *newarg;
 
     if (!ext) {
@@ -251,8 +250,6 @@ bool parse_input_file_name(char *arg, cm
         name++;
     }
 
-    pathlen = name - arg;
-
     if (strcmp(ext, "lo") == 0) {
         newarg = (char *)malloc(strlen(arg) + 10);
         strcpy(newarg, arg);
@@ -310,7 +307,6 @@ bool parse_output_file_name(char *arg, c
     char *name = strrchr(arg, '/');
     char *ext = strrchr(arg, '.');
     char *newarg = NULL, *newext;
-    int pathlen;
 
     if (name == NULL) {
         name = strrchr(arg, '\\');
@@ -336,7 +332,6 @@ bool parse_output_file_name(char *arg, c
     }
 
     ext++;
-    pathlen = name - arg;
 
     if (strcmp(ext, "la") == 0) {
         cmd_data->stub_name = arg;

Modified: apr/apr/branches/1.4.x/build/jlibtool.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/build/jlibtool.c?rev=1183728&r1=1183727&r2=1183728&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/build/jlibtool.c (original)
+++ apr/apr/branches/1.4.x/build/jlibtool.c Sat Oct 15 21:31:55 2011
@@ -1650,7 +1650,7 @@ const char* expand_path(const char *relp
 
     getcwd(foo, PATH_MAX-1);
     newpath = (char*)malloc(strlen(foo)+strlen(relpath)+2);
-    strcat(newpath, foo);
+    strcpy(newpath, foo);
     strcat(newpath, "/");
     strcat(newpath, relpath);
     return newpath;
@@ -1682,7 +1682,7 @@ void link_fixup(command_t *c)
             push_count_chars(c->shared_opts.normal, DYNAMIC_INSTALL_NAME);
 
             tmp = (char*)malloc(PATH_MAX);
-            strcat(tmp, c->install_path);
+            strcpy(tmp, c->install_path);
             strcat(tmp, strrchr(c->shared_name.normal, '/'));
             push_count_chars(c->shared_opts.normal, tmp);
 #endif

Modified: apr/apr/branches/1.4.x/file_io/netware/pipe.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/file_io/netware/pipe.c?rev=1183728&r1=1183727&r2=1183728&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/file_io/netware/pipe.c (original)
+++ apr/apr/branches/1.4.x/file_io/netware/pipe.c Sat Oct 15 21:31:55 2011
@@ -26,7 +26,6 @@
 static apr_status_t pipeblock(apr_file_t *thepipe)
 {
 #ifdef USE_FLAGS
-    int				err;
 	unsigned long	flags;
 
 	if (fcntl(thepipe->filedes, F_GETFL, &flags) != -1)
@@ -49,7 +48,6 @@ static apr_status_t pipeblock(apr_file_t
 static apr_status_t pipenonblock(apr_file_t *thepipe)
 {
 #ifdef USE_FLAGS
-	int				err;
 	unsigned long	flags;
 
     errno = 0;
@@ -138,7 +136,6 @@ APR_DECLARE(apr_status_t) apr_os_pipe_pu
 APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out, apr_pool_t *pool)
 {
 	int     	filedes[2];
-	int 		err;
 
     if (pipe(filedes) == -1) {
         return errno;

Modified: apr/apr/branches/1.4.x/file_io/os2/open.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/file_io/os2/open.c?rev=1183728&r1=1183727&r2=1183728&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/file_io/os2/open.c (original)
+++ apr/apr/branches/1.4.x/file_io/os2/open.c Sat Oct 15 21:31:55 2011
@@ -142,7 +142,7 @@ APR_DECLARE(apr_status_t) apr_file_close
     if (file->buffered)
         apr_thread_mutex_destroy(file->mutex);
 
-    return APR_SUCCESS;
+    return status;
 }
 
 

Modified: apr/apr/branches/1.4.x/file_io/unix/open.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/file_io/unix/open.c?rev=1183728&r1=1183727&r2=1183728&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/file_io/unix/open.c (original)
+++ apr/apr/branches/1.4.x/file_io/unix/open.c Sat Oct 15 21:31:55 2011
@@ -173,13 +173,17 @@ APR_DECLARE(apr_status_t) apr_file_open(
     if (!(flag & APR_FOPEN_NOCLEANUP)) {
         int flags;
 
-        if ((flags = fcntl(fd, F_GETFD)) == -1)
+        if ((flags = fcntl(fd, F_GETFD)) == -1) {
+            close(fd);
             return errno;
+        }
 
         if ((flags & FD_CLOEXEC) == 0) {
             flags |= FD_CLOEXEC;
-            if (fcntl(fd, F_SETFD, flags) == -1)
+            if (fcntl(fd, F_SETFD, flags) == -1) {
+                close(fd);
                 return errno;
+            }
         }
     }
 

Modified: apr/apr/branches/1.4.x/file_io/win32/open.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/file_io/win32/open.c?rev=1183728&r1=1183727&r2=1183728&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/file_io/win32/open.c (original)
+++ apr/apr/branches/1.4.x/file_io/win32/open.c Sat Oct 15 21:31:55 2011
@@ -145,7 +145,6 @@ void *res_name_from_filename(const char 
         apr_wchar_t *wpre, *wfile, *ch;
         apr_size_t n = strlen(file) + 1;
         apr_size_t r, d;
-        apr_status_t rv;
 
         if (apr_os_level >= APR_WIN_2000) {
             if (global)
@@ -169,7 +168,7 @@ void *res_name_from_filename(const char 
         wfile = apr_palloc(pool, (r + n) * sizeof(apr_wchar_t));
         wcscpy(wfile, wpre);
         d = n;
-        if ((rv = apr_conv_utf8_to_ucs2(file, &n, wfile + r, &d))) {
+        if (apr_conv_utf8_to_ucs2(file, &n, wfile + r, &d)) {
             return NULL;
         }
         for (ch = wfile + r; *ch; ++ch) {
@@ -186,7 +185,6 @@ void *res_name_from_filename(const char 
         apr_size_t n = strlen(file) + 1;
 
 #if !APR_HAS_UNICODE_FS
-        apr_status_t rv;
         apr_size_t r, d;
         char *pre;
 

Modified: apr/apr/branches/1.4.x/memory/unix/apr_pools.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/memory/unix/apr_pools.c?rev=1183728&r1=1183727&r2=1183728&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/memory/unix/apr_pools.c (original)
+++ apr/apr/branches/1.4.x/memory/unix/apr_pools.c Sat Oct 15 21:31:55 2011
@@ -1470,6 +1470,7 @@ static void *pool_alloc(apr_pool_t *pool
     node = pool->nodes;
     if (node == NULL || node->index == 64) {
         if ((node = malloc(SIZEOF_DEBUG_NODE_T)) == NULL) {
+            free(mem);
             if (pool->abort_fn)
                 pool->abort_fn(APR_ENOMEM);
 

Modified: apr/apr/branches/1.4.x/threadproc/beos/proc.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/threadproc/beos/proc.c?rev=1183728&r1=1183727&r2=1183728&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/threadproc/beos/proc.c (original)
+++ apr/apr/branches/1.4.x/threadproc/beos/proc.c Sat Oct 15 21:31:55 2011
@@ -362,8 +362,9 @@ APR_DECLARE(apr_status_t) apr_procattr_c
                     == APR_SUCCESS)
                 rv = apr_file_inherit_set(attr->child_in);
         }
+    }
 
-    if (parent_in != NULL && rv == APR_SUCCESS) {
+    if (parent_in != NULL && rv == APR_SUCCESS)
         rv = apr_file_dup(&attr->parent_in, parent_in, attr->pool);
 
     return rv;
@@ -391,7 +392,7 @@ APR_DECLARE(apr_status_t) apr_procattr_c
         }
     }
   
-    if (parent_out != NULL && rv == APR_SUCCESS) {
+    if (parent_out != NULL && rv == APR_SUCCESS)
         rv = apr_file_dup(&attr->parent_out, parent_out, attr->pool);
 
     return rv;
@@ -419,7 +420,7 @@ APR_DECLARE(apr_status_t) apr_procattr_c
         }
     }
   
-    if (parent_err != NULL && rv == APR_SUCCESS) {
+    if (parent_err != NULL && rv == APR_SUCCESS)
         rv = apr_file_dup(&attr->parent_err, parent_err, attr->pool);
 
     return rv;

Modified: apr/apr/branches/1.4.x/threadproc/unix/proc.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/threadproc/unix/proc.c?rev=1183728&r1=1183727&r2=1183728&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/threadproc/unix/proc.c (original)
+++ apr/apr/branches/1.4.x/threadproc/unix/proc.c Sat Oct 15 21:31:55 2011
@@ -396,7 +396,6 @@ APR_DECLARE(apr_status_t) apr_proc_creat
         return errno;
     }
     else if (new->pid == 0) {
-        int status;
         /* child process */
 
         /*
@@ -469,7 +468,7 @@ APR_DECLARE(apr_status_t) apr_proc_creat
 
         /* Only try to switch if we are running as root */
         if (attr->gid != -1 && !geteuid()) {
-            if ((status = setgid(attr->gid))) {
+            if (setgid(attr->gid)) {
                 if (attr->errfn) {
                     attr->errfn(pool, errno, "setting of group failed");
                 }
@@ -478,7 +477,7 @@ APR_DECLARE(apr_status_t) apr_proc_creat
         }
 
         if (attr->uid != -1 && !geteuid()) {
-            if ((status = setuid(attr->uid))) {
+            if (setuid(attr->uid)) {
                 if (attr->errfn) {
                     attr->errfn(pool, errno, "setting of user failed");
                 }
@@ -486,7 +485,7 @@ APR_DECLARE(apr_status_t) apr_proc_creat
             }
         }
 
-        if ((status = limit_proc(attr)) != APR_SUCCESS) {
+        if (limit_proc(attr) != APR_SUCCESS) {
             if (attr->errfn) {
                 attr->errfn(pool, errno, "setting of resource limits failed");
             }

Modified: apr/apr/branches/1.4.x/threadproc/unix/procsup.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.4.x/threadproc/unix/procsup.c?rev=1183728&r1=1183727&r2=1183728&view=diff
==============================================================================
--- apr/apr/branches/1.4.x/threadproc/unix/procsup.c (original)
+++ apr/apr/branches/1.4.x/threadproc/unix/procsup.c Sat Oct 15 21:31:55 2011
@@ -18,8 +18,6 @@
 
 APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize)
 {
-    int x;
-
     if (chdir("/") == -1) {
         return errno;
     }
@@ -28,6 +26,8 @@ APR_DECLARE(apr_status_t) apr_proc_detac
     /* Don't detach for MPE because child processes can't survive the death of
      * the parent. */
     if (daemonize) {
+        int x;
+
         if ((x = fork()) > 0) {
             exit(0);
         }