]> granicus.if.org Git - sudo/commitdiff
Don't use emalloc() in fmt_string(); we want to be able to use it from
authorTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 6 Mar 2010 19:29:04 +0000 (14:29 -0500)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Sat, 6 Mar 2010 19:29:04 +0000 (14:29 -0500)
a plugin.

src/fmt_string.c
src/parse_args.c
src/sudo.c

index e2aabb6b1ffe5c08a62153aa18997ffb08f5e4cd..f54a2a736d6a461501d75d411100e3e6fc45dd35 100644 (file)
@@ -51,13 +51,15 @@ fmt_string(const char *var, const char *val)
     size_t val_len = strlen(val);
     char *cp, *str;
 
-    cp = str = emalloc(var_len + 1 + val_len + 1);
-    memcpy(cp, var, var_len);
-    cp += var_len;
-    *cp++ = '=';
-    memcpy(cp, val, val_len);
-    cp += val_len;
-    *cp = '\0';
+    cp = str = malloc(var_len + 1 + val_len + 1);
+       if (str != NULL) {
+       memcpy(cp, var, var_len);
+       cp += var_len;
+       *cp++ = '=';
+       memcpy(cp, val, val_len);
+       cp += val_len;
+       *cp = '\0';
+    }
 
     return(str);
 }
index c03dffb7ca7d342683af8952a113ff9ad07f5871..ce5d0913253c0fcb77b1ebd5adbe1bcbf456f991 100644 (file)
@@ -359,8 +359,11 @@ parse_args(int argc, char **argv, int *nargc, char ***nargv, char ***settingsp,
        if (sudo_settings[i].value) {
            sudo_debug(9, "settings: %s=%s", sudo_settings[i].name,
                sudo_settings[i].value);
-           settings[j++] = fmt_string(sudo_settings[i].name,
+           settings[j] = fmt_string(sudo_settings[i].name,
                sudo_settings[i].value);
+           if (settings[j] == NULL)
+               errorx(1, "unable to allocate memory");
+           j++;
        }
     }
     settings[j] = NULL;
index 28210108ba3dab9c9601bba880f7b67ffafd319e..2af5ab7046f4c18f313084af4390d6ad344e5318 100644 (file)
@@ -328,6 +328,8 @@ get_user_info(struct user_details *ud)
        errorx(1, "unknown uid %lu: who are you?", (unsigned long)ud->uid);
 
     user_info[i] = fmt_string("user", pw->pw_name);
+    if (user_info[i] == NULL)
+       errorx(1, "unable to allocate memory");
     ud->username = user_info[i] + sizeof("user=") - 1;
 
     easprintf(&user_info[++i], "uid=%lu", (unsigned long)ud->uid);
@@ -340,12 +342,16 @@ get_user_info(struct user_details *ud)
 
     if (getcwd(cwd, sizeof(cwd)) != NULL) {
        user_info[++i] = fmt_string("cwd", cwd);
+       if (user_info[i] == NULL)
+           errorx(1, "unable to allocate memory");
        ud->cwd = user_info[i] + sizeof("cwd=") - 1;
     }
 
     if ((cp = ttyname(STDIN_FILENO)) || (cp = ttyname(STDOUT_FILENO)) ||
        (cp = ttyname(STDERR_FILENO))) {
        user_info[++i] = fmt_string("tty", cp);
+       if (user_info[i] == NULL)
+           errorx(1, "unable to allocate memory");
        ud->tty = user_info[i] + sizeof("tty=") - 1;
     }
 
@@ -354,6 +360,8 @@ get_user_info(struct user_details *ud)
     else
        strlcpy(host, "localhost", sizeof(host));
     user_info[++i] = fmt_string("host", host);
+    if (user_info[i] == NULL)
+       errorx(1, "unable to allocate memory");
     ud->host = user_info[i] + sizeof("host=") - 1;
 
     user_info[++i] = NULL;