]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: util: Finally remove possibilities of using sys_popen() unsafely.
authorJeremy Allison <jra@samba.org>
Sat, 18 May 2019 18:40:26 +0000 (11:40 -0700)
committerKarolin Seeger <kseeger@samba.org>
Thu, 13 Jun 2019 10:22:10 +0000 (10:22 +0000)
All code now uses sys_popenv() which is much
harder to use incorrectly.

Remove the extract_args() function that was the
cause of possible issues.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13964

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
(cherry picked from commit 9fa95d5b45369acfdd38923e8618e94e5d04b07e)

lib/util/sys_popen.c
lib/util/sys_popen.h

index 65040508c811d72d96c4121adb25d9cf4063b04b..659e99ba73637d6bb8947f0495814025117388d7 100644 (file)
 #include "lib/util/sys_popen.h"
 #include "lib/util/debug.h"
 
-/**************************************************************************
- Extract a command into an arg list.
-****************************************************************************/
-
-static char **extract_args(TALLOC_CTX *mem_ctx, const char *command)
-{
-       char *trunc_cmd;
-       char *saveptr;
-       char *ptr;
-       int argcl;
-       char **argl = NULL;
-       int i;
-
-       if (!(trunc_cmd = talloc_strdup(mem_ctx, command))) {
-               DEBUG(0, ("talloc failed\n"));
-               goto nomem;
-       }
-
-       if(!(ptr = strtok_r(trunc_cmd, " \t", &saveptr))) {
-               TALLOC_FREE(trunc_cmd);
-               errno = EINVAL;
-               return NULL;
-       }
-
-       /*
-        * Count the args.
-        */
-
-       for( argcl = 1; ptr; ptr = strtok_r(NULL, " \t", &saveptr))
-               argcl++;
-
-       TALLOC_FREE(trunc_cmd);
-
-       if (!(argl = talloc_array(mem_ctx, char *, argcl + 1))) {
-               goto nomem;
-       }
-
-       /*
-        * Now do the extraction.
-        */
-
-       if (!(trunc_cmd = talloc_strdup(mem_ctx, command))) {
-               goto nomem;
-       }
-
-       ptr = strtok_r(trunc_cmd, " \t", &saveptr);
-       i = 0;
-
-       if (!(argl[i++] = talloc_strdup(argl, ptr))) {
-               goto nomem;
-       }
-
-       while((ptr = strtok_r(NULL, " \t", &saveptr)) != NULL) {
-
-               if (!(argl[i++] = talloc_strdup(argl, ptr))) {
-                       goto nomem;
-               }
-       }
-
-       argl[i++] = NULL;
-       TALLOC_FREE(trunc_cmd);
-       return argl;
-
- nomem:
-       DEBUG(0, ("talloc failed\n"));
-       TALLOC_FREE(trunc_cmd);
-       TALLOC_FREE(argl);
-       errno = ENOMEM;
-       return NULL;
-}
-
 /**************************************************************************
  Wrapper for popen. Safer as it doesn't search a path.
  Modified from the glibc sources.
@@ -204,30 +133,6 @@ err_exit:
        return -1;
 }
 
-int sys_popen(const char *command)
-{
-       char **argl = NULL;
-       int ret;
-
-       if (!*command) {
-               errno = EINVAL;
-               return -1;
-       }
-
-       /*
-        * Extract the command and args into a NULL terminated array.
-        */
-
-       argl = extract_args(NULL, command);
-       if (argl == NULL) {
-               DBG_ERR("extract_args() failed: %s\n", strerror(errno));
-               return -1;
-       }
-       ret = sys_popenv(argl);
-       TALLOC_FREE(argl);
-       return ret;
-}
-
 /**************************************************************************
  Wrapper for pclose. Modified from the glibc sources.
 ****************************************************************************/
index 80ea70efa75514ac682b56f15b01b5bdf47437d1..be4374836265a617d62880a2a92b657ac74423d4 100644 (file)
@@ -20,7 +20,6 @@
 #ifndef __LIB_SYS_POPEN_H__
 #define __LIB_SYS_POPEN_H__
 
-int sys_popen(const char *command);
 int sys_popenv(char * const argl[]);
 int sys_pclose(int fd);