Skip to content

Commit 110ce8f

Browse files
acmelgregkh
authored andcommitted
perf strlist: Don't write to const memory
commit 678ed6b upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f89c296 commit 110ce8f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

tools/perf/util/strlist.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,25 @@ static int strlist__parse_list_entry(struct strlist *slist, const char *s,
139139
return err;
140140
}
141141

142-
static int strlist__parse_list(struct strlist *slist, const char *s, const char *subst_dir)
142+
static int strlist__parse_list(struct strlist *slist, const char *list, const char *subst_dir)
143143
{
144-
char *sep;
144+
char *sep, *s = strdup(list), *sdup = s;
145145
int err;
146146

147+
if (s == NULL)
148+
return -ENOMEM;
149+
147150
while ((sep = strchr(s, ',')) != NULL) {
148151
*sep = '\0';
149152
err = strlist__parse_list_entry(slist, s, subst_dir);
150-
*sep = ',';
151153
if (err != 0)
152154
return err;
153155
s = sep + 1;
154156
}
155157

156-
return *s ? strlist__parse_list_entry(slist, s, subst_dir) : 0;
158+
err = *s ? strlist__parse_list_entry(slist, s, subst_dir) : 0;
159+
free(sdup);
160+
return err;
157161
}
158162

159163
struct strlist *strlist__new(const char *list, const struct strlist_config *config)

0 commit comments

Comments
 (0)