summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2026-01-27 08:03:01 +0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2026-01-27 08:03:01 +0300
commit678ed6b707e4b2db250f255d2f959322896dae65 (patch)
treec3fba3eba416a8037eb597b1c706d92582d0ef3b
parentb42868624c7d00206f77d19a6fbfea73a44ff6f2 (diff)
downloadlinux-678ed6b707e4b2db250f255d2f959322896dae65.tar.xz
perf strlist: Don't write to const memory
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>
-rw-r--r--tools/perf/util/strlist.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/tools/perf/util/strlist.c b/tools/perf/util/strlist.c
index 8a868cbeffae..98883672fcf4 100644
--- a/tools/perf/util/strlist.c
+++ b/tools/perf/util/strlist.c
@@ -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)