]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
column: fix memory use [coverity scan]
authorKarel Zak <kzak@redhat.com>
Thu, 31 Mar 2022 07:55:23 +0000 (09:55 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 31 Mar 2022 07:55:23 +0000 (09:55 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
text-utils/column.c

index 220e5e6a42b045d5bf887a2be958539b7441c40f..a78e2a6af827422de3b720da696ca05020475bdd 100644 (file)
@@ -294,6 +294,7 @@ static int column_set_flag(struct libscols_column *cl, int fl)
 static int has_unnamed(const char *list)
 {
        char **all, **one;
+       int rc = 0;
 
        if (!list)
                return 0;
@@ -305,13 +306,15 @@ static int has_unnamed(const char *list)
        all = split_or_error(list, NULL);
        if (all) {
                STRV_FOREACH(one, all) {
-                       if (strcmp(*one, "-") == 0)
-                               return 1;
+                       if (strcmp(*one, "-") == 0) {
+                               rc = 1;
+                               break;
+                       }
                }
                strv_free(all);
        }
 
-       return 0;
+       return rc;
 }
 
 static void apply_columnflag_from_list(struct column_control *ctl, const char *list,
@@ -804,7 +807,8 @@ int main(int argc, char **argv)
 
                switch(c) {
                case 'C':
-                       strv_extend(&ctl.tab_columns, optarg);
+                       if (strv_extend(&ctl.tab_columns, optarg))
+                               err_oom();
                        break;
                case 'c':
                        if (strcmp(optarg, "unlimited") == 0)