make smbcontrol smbd ping work proper checking for arguments handle short pid_t correctly
authorOlaf Flebbe <flebbe@nix.science-computing.de>
Mon, 17 Aug 2009 15:31:01 +0000 (17:31 +0200)
committerKarolin Seeger <kseeger@samba.org>
Mon, 31 Aug 2009 07:38:47 +0000 (09:38 +0200)
Fixes bug #6655.

(cherry picked from commit 5359e397ff190c35414f6961be61a5110e237dd5)

source3/lib/util.c
source3/utils/smbcontrol.c

index 61a73e60773071ea3b07dd07b504d6723d612b1c..3d7336f957bc62f3029781626710b53117861219 100644 (file)
@@ -2743,14 +2743,15 @@ bool procid_is_me(const struct server_id *pid)
 
 struct server_id interpret_pid(const char *pid_string)
 {
-#ifdef CLUSTER_SUPPORT
-       unsigned int vnn, pid;
        struct server_id result;
-       if (sscanf(pid_string, "%u:%u", &vnn, &pid) == 2) {
+       int pid;
+#ifdef CLUSTER_SUPPORT
+       unsigned int vnn;
+       if (sscanf(pid_string, "%u:%d", &vnn, &pid) == 2) {
                result.vnn = vnn;
                result.pid = pid;
        }
-       else if (sscanf(pid_string, "%u", &pid) == 1) {
+       else if (sscanf(pid_string, "%d", &pid) == 1) {
                result.vnn = get_my_vnn();
                result.pid = pid;
        }
@@ -2758,10 +2759,19 @@ struct server_id interpret_pid(const char *pid_string)
                result.vnn = NONCLUSTER_VNN;
                result.pid = -1;
        }
-       return result;
 #else
-       return pid_to_procid(atoi(pid_string));
+       if (sscanf(pid_string, "%d", &pid) != 1) {
+               result.pid = -1;
+       } else {
+               result.pid = pid;
+       }
 #endif
+       /* Assigning to result.pid may have overflowed
+          Map negative pid to -1: i.e. error */
+       if (result.pid < 0) {
+               result.pid = -1;
+       }
+       return result;
 }
 
 char *procid_str(TALLOC_CTX *mem_ctx, const struct server_id *pid)
index fc7d0aa360f87ef1364be37440b8b4d6caef664a..7fab6eb4b26aae085db0af9b560fe49ae33ecde0 100644 (file)
@@ -1247,15 +1247,12 @@ static struct server_id parse_dest(const char *dest)
                dest = "winbindd";
        }
 
-       if (!(strequal(dest, "winbindd") || strequal(dest, "nmbd"))) {
-               /* Check for numeric pid number */
+       /* Check for numeric pid number */
+       result = interpret_pid(dest);
 
-               result = interpret_pid(dest);
-
-               /* Zero isn't valid if not smbd. */
-               if (result.pid && procid_valid(&result)) {
-                       return result;
-               }
+       /* Zero isn't valid if not "all". */
+       if (result.pid && procid_valid(&result)) {
+               return result;
        }
 
        /* Look up other destinations in pidfile directory */