Don't use emalloc() in fmt_string(); we want to be able to use it from

a plugin.
This commit is contained in:
Todd C. Miller
2010-03-06 14:29:04 -05:00
parent 847a7c1b24
commit cc23068c2a
3 changed files with 21 additions and 8 deletions

View 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);
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);
}

View 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;

View 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;