Reduce the number of "internal error, foo overflow" messages that

need to be translated.
This commit is contained in:
Todd C. Miller
2012-08-10 12:18:38 -04:00
parent afaf5e07fe
commit 241b2395cf
6 changed files with 24 additions and 18 deletions

View File

@@ -98,7 +98,7 @@ emalloc2(size_t nmemb, size_t size)
if (nmemb == 0 || size == 0) if (nmemb == 0 || size == 0)
errorx2(1, _("internal error, tried to emalloc2(0)")); errorx2(1, _("internal error, tried to emalloc2(0)"));
if (nmemb > SIZE_MAX / size) if (nmemb > SIZE_MAX / size)
errorx2(1, _("internal error, emalloc2() overflow")); errorx2(1, _("internal error, %s overflow"), "emalloc2()");
size *= nmemb; size *= nmemb;
if ((ptr = malloc(size)) == NULL) if ((ptr = malloc(size)) == NULL)
@@ -120,7 +120,7 @@ ecalloc(size_t nmemb, size_t size)
errorx2(1, _("internal error, tried to ecalloc(0)")); errorx2(1, _("internal error, tried to ecalloc(0)"));
if (nmemb != 1) { if (nmemb != 1) {
if (nmemb > SIZE_MAX / size) if (nmemb > SIZE_MAX / size)
errorx2(1, _("internal error, ecalloc() overflow")); errorx2(1, _("internal error, %s overflow"), "ecalloc()");
size *= nmemb; size *= nmemb;
} }
if ((ptr = malloc(size)) == NULL) if ((ptr = malloc(size)) == NULL)
@@ -160,7 +160,7 @@ erealloc3(void *ptr, size_t nmemb, size_t size)
if (nmemb == 0 || size == 0) if (nmemb == 0 || size == 0)
errorx2(1, _("internal error, tried to erealloc3(0)")); errorx2(1, _("internal error, tried to erealloc3(0)"));
if (nmemb > SIZE_MAX / size) if (nmemb > SIZE_MAX / size)
errorx2(1, _("internal error, erealloc3() overflow")); errorx2(1, _("internal error, %s overflow"), "erealloc3()");
size *= nmemb; size *= nmemb;
ptr = ptr ? realloc(ptr, size) : malloc(size); ptr = ptr ? realloc(ptr, size) : malloc(size);
@@ -182,9 +182,9 @@ erecalloc(void *ptr, size_t onmemb, size_t nmemb, size_t msize)
size_t size; size_t size;
if (nmemb == 0 || msize == 0) if (nmemb == 0 || msize == 0)
errorx2(1, _("internal error, tried to erealloc3(0)")); errorx2(1, _("internal error, tried to erecalloc(0)"));
if (nmemb > SIZE_MAX / msize) if (nmemb > SIZE_MAX / msize)
errorx2(1, _("internal error, erealloc3() overflow")); errorx2(1, _("internal error, %s overflow"), "erecalloc()");
size = nmemb * msize; size = nmemb * msize;
ptr = ptr ? realloc(ptr, size) : malloc(size); ptr = ptr ? realloc(ptr, size) : malloc(size);

View File

@@ -396,7 +396,7 @@ expand_prompt(char *old_prompt, char *user, char *host)
oflow: oflow:
/* We pre-allocate enough space, so this should never happen. */ /* We pre-allocate enough space, so this should never happen. */
errorx(1, _("internal error, expand_prompt() overflow")); errorx(1, _("internal error, %s overflow"), "expand_prompt()");
} }
/* /*

View File

@@ -285,11 +285,15 @@ sudo_putenv_nodebug(char *str, bool dupcheck, bool overwrite)
char **nenvp; char **nenvp;
size_t nsize; size_t nsize;
if (env.env_size > SIZE_MAX - 128) if (env.env_size > SIZE_MAX - 128) {
errorx2(1, _("internal error, sudo_putenv_nodebug() overflow")); errorx2(1, _("internal error, %s overflow"),
"sudo_putenv_nodebug()");
}
nsize = env.env_size + 128; nsize = env.env_size + 128;
if (nsize > SIZE_MAX / sizeof(char *)) if (nsize > SIZE_MAX / sizeof(char *)) {
errorx2(1, _("internal error, sudo_putenv_nodebug() overflow")); errorx2(1, _("internal error, %s overflow"),
"sudo_putenv_nodebug()");
}
nenvp = realloc(env.envp, nsize * sizeof(char *)); nenvp = realloc(env.envp, nsize * sizeof(char *));
if (nenvp == NULL) { if (nenvp == NULL) {
errno = ENOMEM; errno = ENOMEM;
@@ -388,7 +392,7 @@ sudo_setenv2(const char *var, const char *val, bool dupcheck, bool overwrite)
strlcat(estring, "=", esize) >= esize || strlcat(estring, "=", esize) >= esize ||
strlcat(estring, val, esize) >= esize) { strlcat(estring, val, esize) >= esize) {
errorx(1, _("internal error, sudo_setenv2() overflow")); errorx(1, _("internal error, %s overflow"), "sudo_setenv2()");
} }
rval = sudo_putenv(estring, dupcheck, overwrite); rval = sudo_putenv(estring, dupcheck, overwrite);
if (rval == -1) if (rval == -1)
@@ -440,7 +444,7 @@ sudo_setenv(const char *var, const char *val, int overwrite)
rval = sudo_setenv_nodebug(var, val, overwrite); rval = sudo_setenv_nodebug(var, val, overwrite);
if (rval == -1) { if (rval == -1) {
if (errno == EINVAL) if (errno == EINVAL)
errorx(1, _("internal error, sudo_setenv() overflow")); errorx(1, _("internal error, %s overflow"), "sudo_setenv()");
errorx(1, _("unable to allocate memory")); errorx(1, _("unable to allocate memory"));
} }
debug_return_int(rval); debug_return_int(rval);

View File

@@ -78,8 +78,10 @@ linux_audit_command(char *argv[], int result)
command = cp = emalloc(size); command = cp = emalloc(size);
for (av = argv; *av != NULL; av++) { for (av = argv; *av != NULL; av++) {
n = strlcpy(cp, *av, size - (cp - command)); n = strlcpy(cp, *av, size - (cp - command));
if (n >= size - (cp - command)) if (n >= size - (cp - command)) {
errorx(1, _("internal error, linux_audit_command() overflow")); errorx(1, _("internal error, %s overflow"),
"linux_audit_command()");
}
cp += n; cp += n;
*cp++ = ' '; *cp++ = ' ';
} }

View File

@@ -667,14 +667,14 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[],
(unsigned int)runas_pw->pw_gid; (unsigned int)runas_pw->pw_gid;
len = snprintf(cp, glsize - (cp - gid_list), "%u", egid); len = snprintf(cp, glsize - (cp - gid_list), "%u", egid);
if (len < 0 || len >= glsize - (cp - gid_list)) if (len < 0 || len >= glsize - (cp - gid_list))
errorx(1, _("internal error, runas_groups overflow")); errorx(1, _("internal error, %s overflow"), "runas_groups");
cp += len; cp += len;
for (i = 0; i < grlist->ngids; i++) { for (i = 0; i < grlist->ngids; i++) {
if (grlist->gids[i] != egid) { if (grlist->gids[i] != egid) {
len = snprintf(cp, glsize - (cp - gid_list), ",%u", len = snprintf(cp, glsize - (cp - gid_list), ",%u",
(unsigned int) grlist->gids[i]); (unsigned int) grlist->gids[i]);
if (len < 0 || len >= glsize - (cp - gid_list)) if (len < 0 || len >= glsize - (cp - gid_list))
errorx(1, _("internal error, runas_groups overflow")); errorx(1, _("internal error, %s overflow"), "runas_groups");
cp += len; cp += len;
} }
} }
@@ -933,7 +933,7 @@ set_cmnd(void)
for (to = user_args, av = NewArgv + 1; *av; av++) { for (to = user_args, av = NewArgv + 1; *av; av++) {
n = strlcpy(to, *av, size - (to - user_args)); n = strlcpy(to, *av, size - (to - user_args));
if (n >= size - (to - user_args)) if (n >= size - (to - user_args))
errorx(1, _("internal error, set_cmnd() overflow")); errorx(1, _("internal error, %s overflow"), "set_cmnd()");
to += n; to += n;
*to++ = ' '; *to++ = ' ';
} }

View File

@@ -250,7 +250,7 @@ main(int argc, char *argv[])
for (to = user_args, from = argv; *from; from++) { for (to = user_args, from = argv; *from; from++) {
n = strlcpy(to, *from, size - (to - user_args)); n = strlcpy(to, *from, size - (to - user_args));
if (n >= size - (to - user_args)) if (n >= size - (to - user_args))
errorx(1, _("internal error, init_vars() overflow")); errorx(1, _("internal error, %s overflow"), "init_vars()");
to += n; to += n;
*to++ = ' '; *to++ = ' ';
} }