aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorColin Ian King <colin.king@canonical.com>2016-08-12 17:44:56 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-08-15 16:06:19 -0400
commit0325862dc364d8af524bf2db53ef4360ed55b989 (patch)
tree4c307fc74ea114e1a97b78bb6365a6f61ca51e2f /tools
parent50de1a0c54cdbc69a6dbcbc323f53daf95a4050e (diff)
perf probe: Check for dup and fdopen failures
dup and fdopen can potentially fail, so add some extra error handling checks rather than assuming they always work. Signed-off-by: Colin King <colin.king@canonical.com> Acked-by: Masami Hiramatsu <mhiramat@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/r/1471038296-12956-1-git-send-email-colin.king@canonical.com [ Free resources when those functions (now being verified) fail ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/util/probe-file.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 9aed9c332da6..a8e76233c088 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -133,7 +133,7 @@ int probe_file__open_both(int *kfd, int *ufd, int flag)
133/* Get raw string list of current kprobe_events or uprobe_events */ 133/* Get raw string list of current kprobe_events or uprobe_events */
134struct strlist *probe_file__get_rawlist(int fd) 134struct strlist *probe_file__get_rawlist(int fd)
135{ 135{
136 int ret, idx; 136 int ret, idx, fddup;
137 FILE *fp; 137 FILE *fp;
138 char buf[MAX_CMDLEN]; 138 char buf[MAX_CMDLEN];
139 char *p; 139 char *p;
@@ -144,7 +144,14 @@ struct strlist *probe_file__get_rawlist(int fd)
144 144
145 sl = strlist__new(NULL, NULL); 145 sl = strlist__new(NULL, NULL);
146 146
147 fp = fdopen(dup(fd), "r"); 147 fddup = dup(fd);
148 if (fddup < 0)
149 goto out_free_sl;
150
151 fp = fdopen(fddup, "r");
152 if (!fp)
153 goto out_close_fddup;
154
148 while (!feof(fp)) { 155 while (!feof(fp)) {
149 p = fgets(buf, MAX_CMDLEN, fp); 156 p = fgets(buf, MAX_CMDLEN, fp);
150 if (!p) 157 if (!p)
@@ -163,6 +170,12 @@ struct strlist *probe_file__get_rawlist(int fd)
163 fclose(fp); 170 fclose(fp);
164 171
165 return sl; 172 return sl;
173
174out_close_fddup:
175 close(fddup);
176out_free_sl:
177 strlist__delete(sl);
178 return NULL;
166} 179}
167 180
168static struct strlist *__probe_file__get_namelist(int fd, bool include_group) 181static struct strlist *__probe_file__get_namelist(int fd, bool include_group)
@@ -447,10 +460,13 @@ static int probe_cache__load(struct probe_cache *pcache)
447{ 460{
448 struct probe_cache_entry *entry = NULL; 461 struct probe_cache_entry *entry = NULL;
449 char buf[MAX_CMDLEN], *p; 462 char buf[MAX_CMDLEN], *p;
450 int ret = 0; 463 int ret = 0, fddup;
451 FILE *fp; 464 FILE *fp;
452 465
453 fp = fdopen(dup(pcache->fd), "r"); 466 fddup = dup(pcache->fd);
467 if (fddup < 0)
468 return -errno;
469 fp = fdopen(fddup, "r");
454 if (!fp) 470 if (!fp)
455 return -EINVAL; 471 return -EINVAL;
456 472