Skip to contentSkip to conversation

perf session: Fix possible null pointer dereference in session.c

PATCH Applied Masanari Iida 3 participants 3 messages May 14, 2014 – May 21, 2014 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf session: Fix possible null pointer dereference in session.c

cppcheck detected following warning. [tools/perf/util/session.c:1628] -> [tools/perf/util/session.c:1632]:
(warning) Possible null pointer dereference: session - otherwise it is redundant to check it against null.

In order to avoide null pointer, check the pointer before use.

---
 tools/perf/util/session.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/session.c +3 -2
index 55960f2..64a186e 100644
@@ -1625,13 +1625,14 @@ out_delete_map:
 void perf_session__fprintf_info(struct perf_session *session, FILE *fp,
 				bool full)
 {
-	int fd = perf_data_file__fd(session->file);
 	struct stat st;
-	int ret;
+	int fd, ret;
 
 	if (session == NULL || fp == NULL)
 		return;
 
+	fd = perf_data_file__fd(session->file);
+
 	ret = fstat(fd, &st);
 	if (ret == -1)
 		return;
Signature · 1 line
2.0.0.rc3.2.g998f840
Applied
#1 lore raw
Quoted 8 lines · Masanari Iida

cppcheck detected following warning. [tools/perf/util/session.c:1628] -> [tools/perf/util/session.c:1632]:
(warning) Possible null pointer dereference: session - otherwise it is redundant to check it against null.

In order to avoide null pointer, check the pointer before use.

applied, thanks

jirka

Quoted 28 lines
---
 tools/perf/util/session.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/session.c +3 -2
index 55960f2..64a186e 100644
@@ -1625,13 +1625,14 @@ out_delete_map:
 void perf_session__fprintf_info(struct perf_session *session, FILE *fp,
 				bool full)
 {
-	int fd = perf_data_file__fd(session->file);
 	struct stat st;
-	int ret;
+	int fd, ret;
 
 	if (session == NULL || fp == NULL)
 		return;
 
+	fd = perf_data_file__fd(session->file);
+
 	ret = fstat(fd, &st);
 	if (ret == -1)
 		return;
Signature · 1 line
2.0.0.rc3.2.g998f840
#2 lore raw
In reply to Masanari Iida
perf session: Fix possible null pointer dereference in session.c
Commit-ID:  c5765ece8a050836c6255e1276fc8e0e867078da
Gitweb:     http://git.kernel.org/tip/c5765ece8a050836c6255e1276fc8e0e867078da
Author:     Masanari Iida <[email protected]>
AuthorDate: Thu, 15 May 2014 02:13:38 +0900
Committer:  Jiri Olsa <[email protected]>
CommitDate: Fri, 16 May 2014 09:18:51 +0200

perf session: Fix possible null pointer dereference in session.c

cppcheck detected following warning:
[tools/perf/util/session.c:1628] -> [tools/perf/util/session.c:1632]:
(warning) Possible null pointer dereference: session - otherwise it is redundant to check it against null.

In order to avoide null pointer, check the pointer before use.

---
 tools/perf/util/session.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
tools/perf/util/session.c +3 -2
index 55960f2..64a186e 100644
@@ -1625,13 +1625,14 @@ out_delete_map:
 void perf_session__fprintf_info(struct perf_session *session, FILE *fp,
 				bool full)
 {
-	int fd = perf_data_file__fd(session->file);
 	struct stat st;
-	int ret;
+	int fd, ret;
 
 	if (session == NULL || fp == NULL)
 		return;
 
+	fd = perf_data_file__fd(session->file);
+
 	ret = fstat(fd, &st);
 	if (ret == -1)
 		return;