]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf strlist: Don't write to const memory
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 27 Jan 2026 05:03:01 +0000 (02:03 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 27 Jan 2026 05:03:01 +0000 (02:03 -0300)
Do a strdup to the list string and parse from it, free at the end.

This is to deal with newer glibcs const-correctness.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/strlist.c

index 8a868cbeffae263e35558e0974d68f32f697896c..98883672fcf47102c51c32f28a61b4034bb1c996 100644 (file)
@@ -139,21 +139,25 @@ out:
        return err;
 }
 
-static int strlist__parse_list(struct strlist *slist, const char *s, const char *subst_dir)
+static int strlist__parse_list(struct strlist *slist, const char *list, const char *subst_dir)
 {
-       char *sep;
+       char *sep, *s = strdup(list), *sdup = s;
        int err;
 
+       if (s == NULL)
+               return -ENOMEM;
+
        while ((sep = strchr(s, ',')) != NULL) {
                *sep = '\0';
                err = strlist__parse_list_entry(slist, s, subst_dir);
-               *sep = ',';
                if (err != 0)
                        return err;
                s = sep + 1;
        }
 
-       return *s ? strlist__parse_list_entry(slist, s, subst_dir) : 0;
+       err = *s ? strlist__parse_list_entry(slist, s, subst_dir) : 0;
+       free(sdup);
+       return err;
 }
 
 struct strlist *strlist__new(const char *list, const struct strlist_config *config)