Skip to contentSkip to conversation

perf dso: prevent null dsos from being added

PATCH Applied Anubhav Shelat 3 participants 3 messages Apr 1 – Apr 2 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf dso: prevent null dsos from being added

When sorting the dso array we sometimes get a crash due to null comparisons in comparator functions. So prevent __dsos__add from adding null to the dso array to avoid out-of-memory related errors.

---
 tools/perf/util/dsos.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/dsos.c +3 -0
index 0a7645c7fae7..5cf8c878bab2 100644
@@ -196,6 +196,9 @@ static struct dso *__dsos__find_by_longname_id(struct dsos *dsos,
 
 int __dsos__add(struct dsos *dsos, struct dso *dso)
 {
+	if (!dso)
+		return -EINVAL;
+
 	if (dsos->cnt == dsos->allocated) {
 		unsigned int to_allocate = 2;
 		struct dso **temp;
Signature · 1 line
2.52.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Anubhav Shelat

When sorting the dso array we sometimes get a crash due to null comparisons in comparator functions. So prevent __dsos__add from adding null to the dso array to avoid out-of-memory related errors.

Thanks!
Ian

Quoted 21 lines
---
 tools/perf/util/dsos.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/dsos.c +3 -1
index 0a7645c7fae7..5cf8c878bab2 100644
@@ -196,6 +196,9 @@ static struct dso *__dsos__find_by_longname_id(struct dsos *dsos,
 
 int __dsos__add(struct dsos *dsos, struct dso *dso)
 {
+       if (!dso)
+               return -EINVAL;
+
        if (dsos->cnt == dsos->allocated) {
                unsigned int to_allocate = 2;
                struct dso **temp;
--

2.52.0

maintainer Applied
#2 lore raw
In reply to Anubhav Shelat
Quoted 5 lines · Anubhav Shelat

When sorting the dso array we sometimes get a crash due to null comparisons in comparator functions. So prevent __dsos__add from adding null to the dso array to avoid out-of-memory related errors.

Applied to perf-tools-next, thanks!

Best regards,
Namhyung