From 241b2395cf229fe21abc247ee9f43aaceb35009d Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Fri, 10 Aug 2012 12:18:38 -0400 Subject: [PATCH] Reduce the number of "internal error, foo overflow" messages that need to be translated. --- common/alloc.c | 10 +++++----- plugins/sudoers/check.c | 2 +- plugins/sudoers/env.c | 16 ++++++++++------ plugins/sudoers/linux_audit.c | 6 ++++-- plugins/sudoers/sudoers.c | 6 +++--- plugins/sudoers/testsudoers.c | 2 +- 6 files changed, 24 insertions(+), 18 deletions(-) diff --git a/common/alloc.c b/common/alloc.c index cbf8f626f..e1fe25843 100644 --- a/common/alloc.c +++ b/common/alloc.c @@ -98,7 +98,7 @@ emalloc2(size_t nmemb, size_t size) if (nmemb == 0 || size == 0) errorx2(1, _("internal error, tried to emalloc2(0)")); if (nmemb > SIZE_MAX / size) - errorx2(1, _("internal error, emalloc2() overflow")); + errorx2(1, _("internal error, %s overflow"), "emalloc2()"); size *= nmemb; if ((ptr = malloc(size)) == NULL) @@ -120,7 +120,7 @@ ecalloc(size_t nmemb, size_t size) errorx2(1, _("internal error, tried to ecalloc(0)")); if (nmemb != 1) { if (nmemb > SIZE_MAX / size) - errorx2(1, _("internal error, ecalloc() overflow")); + errorx2(1, _("internal error, %s overflow"), "ecalloc()"); size *= nmemb; } if ((ptr = malloc(size)) == NULL) @@ -160,7 +160,7 @@ erealloc3(void *ptr, size_t nmemb, size_t size) if (nmemb == 0 || size == 0) errorx2(1, _("internal error, tried to erealloc3(0)")); if (nmemb > SIZE_MAX / size) - errorx2(1, _("internal error, erealloc3() overflow")); + errorx2(1, _("internal error, %s overflow"), "erealloc3()"); size *= nmemb; 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; 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) - errorx2(1, _("internal error, erealloc3() overflow")); + errorx2(1, _("internal error, %s overflow"), "erecalloc()"); size = nmemb * msize; ptr = ptr ? realloc(ptr, size) : malloc(size); diff --git a/plugins/sudoers/check.c b/plugins/sudoers/check.c index 0d98e4dc8..28f515f22 100644 --- a/plugins/sudoers/check.c +++ b/plugins/sudoers/check.c @@ -396,7 +396,7 @@ expand_prompt(char *old_prompt, char *user, char *host) oflow: /* 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()"); } /* diff --git a/plugins/sudoers/env.c b/plugins/sudoers/env.c index a9b4f45f1..a77613964 100644 --- a/plugins/sudoers/env.c +++ b/plugins/sudoers/env.c @@ -285,11 +285,15 @@ sudo_putenv_nodebug(char *str, bool dupcheck, bool overwrite) char **nenvp; size_t nsize; - if (env.env_size > SIZE_MAX - 128) - errorx2(1, _("internal error, sudo_putenv_nodebug() overflow")); + if (env.env_size > SIZE_MAX - 128) { + errorx2(1, _("internal error, %s overflow"), + "sudo_putenv_nodebug()"); + } nsize = env.env_size + 128; - if (nsize > SIZE_MAX / sizeof(char *)) - errorx2(1, _("internal error, sudo_putenv_nodebug() overflow")); + if (nsize > SIZE_MAX / sizeof(char *)) { + errorx2(1, _("internal error, %s overflow"), + "sudo_putenv_nodebug()"); + } nenvp = realloc(env.envp, nsize * sizeof(char *)); if (nenvp == NULL) { errno = ENOMEM; @@ -388,7 +392,7 @@ sudo_setenv2(const char *var, const char *val, bool dupcheck, bool overwrite) strlcat(estring, "=", 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); if (rval == -1) @@ -440,7 +444,7 @@ sudo_setenv(const char *var, const char *val, int overwrite) rval = sudo_setenv_nodebug(var, val, overwrite); if (rval == -1) { if (errno == EINVAL) - errorx(1, _("internal error, sudo_setenv() overflow")); + errorx(1, _("internal error, %s overflow"), "sudo_setenv()"); errorx(1, _("unable to allocate memory")); } debug_return_int(rval); diff --git a/plugins/sudoers/linux_audit.c b/plugins/sudoers/linux_audit.c index 71f9e5e73..9cfd4a7a6 100644 --- a/plugins/sudoers/linux_audit.c +++ b/plugins/sudoers/linux_audit.c @@ -78,8 +78,10 @@ linux_audit_command(char *argv[], int result) command = cp = emalloc(size); for (av = argv; *av != NULL; av++) { n = strlcpy(cp, *av, size - (cp - command)); - if (n >= size - (cp - command)) - errorx(1, _("internal error, linux_audit_command() overflow")); + if (n >= size - (cp - command)) { + errorx(1, _("internal error, %s overflow"), + "linux_audit_command()"); + } cp += n; *cp++ = ' '; } diff --git a/plugins/sudoers/sudoers.c b/plugins/sudoers/sudoers.c index 1c011a876..b33628ca4 100644 --- a/plugins/sudoers/sudoers.c +++ b/plugins/sudoers/sudoers.c @@ -667,14 +667,14 @@ sudoers_policy_main(int argc, char * const argv[], int pwflag, char *env_add[], (unsigned int)runas_pw->pw_gid; len = snprintf(cp, glsize - (cp - gid_list), "%u", egid); 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; for (i = 0; i < grlist->ngids; i++) { if (grlist->gids[i] != egid) { len = snprintf(cp, glsize - (cp - gid_list), ",%u", (unsigned int) grlist->gids[i]); 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; } } @@ -933,7 +933,7 @@ set_cmnd(void) for (to = user_args, av = NewArgv + 1; *av; av++) { n = strlcpy(to, *av, 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++ = ' '; } diff --git a/plugins/sudoers/testsudoers.c b/plugins/sudoers/testsudoers.c index 576458c1a..148dd6e53 100644 --- a/plugins/sudoers/testsudoers.c +++ b/plugins/sudoers/testsudoers.c @@ -250,7 +250,7 @@ main(int argc, char *argv[]) for (to = user_args, from = argv; *from; from++) { n = strlcpy(to, *from, 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++ = ' '; }