]> granicus.if.org Git - sudo/commitdiff
Add missing warnings for memory allocation failure.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 14 Jul 2015 20:50:36 +0000 (14:50 -0600)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Tue, 14 Jul 2015 20:50:36 +0000 (14:50 -0600)
Add function name to memory allocation warnings.

plugins/sudoers/toke.c
plugins/sudoers/toke.l
plugins/sudoers/toke_util.c

index 7bc4e4200ae5c9284a181dfad3efc64b2c2f8cd4..537aa21d449e1355a1c9b0bd1b8d986a7113aa3a 100644 (file)
@@ -4041,9 +4041,11 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
        }
        goto bad;
     }
-    paths = malloc(sizeof(*paths) * max_paths);
-    if (paths == NULL)
+    paths = reallocarray(NULL, max_paths, sizeof(*paths));
+    if (paths == NULL) {
+       sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
        goto bad;
+    }
     while ((dent = readdir(dir)) != NULL) {
        struct path_list *pl;
        struct stat sb;
@@ -4062,6 +4064,7 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
        }
        pl = malloc(sizeof(*pl));
        if (pl == NULL) {
+           sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
            free(path);
            goto bad;
        }
@@ -4071,6 +4074,7 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
            max_paths <<= 1;
            tmp = reallocarray(paths, max_paths, sizeof(*paths));
            if (tmp == NULL) {
+               sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
                free(path);
                free(pl);
                goto bad;
@@ -4178,7 +4182,7 @@ push_include_int(char *path, bool isdir)
        istacksize += SUDOERS_STACK_INCREMENT;
        new_istack = reallocarray(istack, istacksize, sizeof(*istack));
        if (new_istack == NULL) {
-           sudo_warn(NULL);
+           sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
            sudoerserror(NULL);
            debug_return_bool(false);
        }
@@ -4336,7 +4340,7 @@ parse_include(char *base)
     len += (int)(ep - cp);
     path = pp = malloc(len + dirlen + 1);
     if (path == NULL) {
-       sudo_warn(NULL);
+       sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
        sudoerserror(NULL);
        debug_return_str(NULL);
     }
index 6a40a681acaf5d921b6cd06b3ec7751e89a707a2..93b4ac695537df17f56a7080c7558eb8c482d2f2 100644 (file)
@@ -770,9 +770,11 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
        }
        goto bad;
     }
-    paths = malloc(sizeof(*paths) * max_paths);
-    if (paths == NULL)
+    paths = reallocarray(NULL, max_paths, sizeof(*paths));
+    if (paths == NULL) {
+       sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
        goto bad;
+    }
     while ((dent = readdir(dir)) != NULL) {
        struct path_list *pl;
        struct stat sb;
@@ -791,6 +793,7 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
        }
        pl = malloc(sizeof(*pl));
        if (pl == NULL) {
+           sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
            free(path);
            goto bad;
        }
@@ -800,6 +803,7 @@ read_dir_files(const char *dirpath, struct path_list ***pathsp)
            max_paths <<= 1;
            tmp = reallocarray(paths, max_paths, sizeof(*paths));
            if (tmp == NULL) {
+               sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
                free(path);
                free(pl);
                goto bad;
@@ -907,7 +911,7 @@ push_include_int(char *path, bool isdir)
        istacksize += SUDOERS_STACK_INCREMENT;
        new_istack = reallocarray(istack, istacksize, sizeof(*istack));
        if (new_istack == NULL) {
-           sudo_warn(NULL);
+           sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
            sudoerserror(NULL);
            debug_return_bool(false);
        }
@@ -1065,7 +1069,7 @@ parse_include(char *base)
     len += (int)(ep - cp);
     path = pp = malloc(len + dirlen + 1);
     if (path == NULL) {
-       sudo_warn(NULL);
+       sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
        sudoerserror(NULL);
        debug_return_str(NULL);
     }
index 87a56dd3b8969bc4fc47801110b5d5d4f632a6a7..b3073a5dd50c6a8ceb3834809992342fe31b033b 100644 (file)
@@ -53,7 +53,7 @@ fill_txt(const char *src, int len, int olen)
 
     dst = olen ? realloc(sudoerslval.string, olen + len + 1) : malloc(len + 1);
     if (dst == NULL) {
-       sudo_warn(NULL);
+       sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
        sudoerserror(NULL);
        debug_return_bool(false);
     }
@@ -106,7 +106,7 @@ fill_cmnd(const char *src, int len)
 
     dst = sudoerslval.command.cmnd = malloc(len + 1);
     if (sudoerslval.command.cmnd == NULL) {
-       sudo_warn(NULL);
+       sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
        sudoerserror(NULL);
        debug_return_bool(false);
     }
@@ -144,9 +144,9 @@ fill_args(const char *s, int len, int addspace)
 
        p = realloc(sudoerslval.command.args, arg_size);
        if (p == NULL) {
-           free(sudoerslval.command.args);
-           sudo_warn(NULL);
+           sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
            sudoerserror(NULL);
+           free(sudoerslval.command.args);
            debug_return_bool(false);
        } else
            sudoerslval.command.args = p;