Skip to contentSkip to conversation

tools: Fix incorrect calculation of object size by sizeof

PATCH Applied Li Dong 2 participants 4 messages Jun 19, 2023 – Jun 21, 2023 1 message not in the archive perf events

lore
Share & tools
lore

Li Dong

author
#0 lore raw

PATCH 1/1 tools: Fix incorrect calculation of object size by sizeof

What we need to calculate is the size of the object, not the size of the pointer.

---
 tools/perf/util/scripting-engines/trace-event-python.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/scripting-engines/trace-event-python.c +2 -2
index 59063ec98619..25fcd6630a4d 100644
@@ -771,12 +771,12 @@ static void set_regs_in_dict(PyObject *dict,
 	int size = __sw_hweight64(attr->sample_regs_intr) * 28;
 	char *bf = malloc(size);
 
-	regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, sizeof(bf));
+	regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, size);
 
 	pydict_set_item_string_decref(dict, "iregs",
 			_PyUnicode_FromString(bf));
 
-	regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, sizeof(bf));
+	regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, size);
 
 	pydict_set_item_string_decref(dict, "uregs",
 			_PyUnicode_FromString(bf));
Signature · 1 line
2.31.1.windows.1
maintainer Acked-by on v1 1/1
#1 lore raw

Hello,

Quoted 5 lines · Li Dong

What we need to calculate is the size of the object, not the size of the pointer.

Since this problem was introduced in the current dev cycle and not in the mainline yet, I think we can skip the Fixes tag.

Thanks,
Namhyung

Quoted 26 lines
---
 tools/perf/util/scripting-engines/trace-event-python.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/util/scripting-engines/trace-event-python.c +2 -3
index 59063ec98619..25fcd6630a4d 100644
@@ -771,12 +771,12 @@ static void set_regs_in_dict(PyObject *dict,
        int size = __sw_hweight64(attr->sample_regs_intr) * 28;
        char *bf = malloc(size);
 
-       regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, sizeof(bf));
+       regs_map(&sample->intr_regs, attr->sample_regs_intr, arch, bf, size);
 
        pydict_set_item_string_decref(dict, "iregs",
                        _PyUnicode_FromString(bf));
 
-       regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, sizeof(bf));
+       regs_map(&sample->user_regs, attr->sample_regs_user, arch, bf, size);
 
        pydict_set_item_string_decref(dict, "uregs",
                        _PyUnicode_FromString(bf));
--

2.31.1.windows.1

A message that is not in the archive (sent off-list or not yet received): CA+JHD93f_c8OJf4Kg68C_Xo=_rcO669G0QJ_mjL78upLmUwfoA@mail.gmail.com

maintainer
#3 lore raw

Hi Arnaldo,

Quoted 14 lines · Arnaldo Carvalho de Melo
Quoted 10 lines · Namhyung Kim

Hello,

Quoted 5 lines · Li Dong

What we need to calculate is the size of the object, not the size of the pointer.

Quoted 7 lines
Quoted 4 lines

Since this problem was introduced in the current dev cycle and not in the mainline yet, I think we can skip the Fixes tag.

I think we should have it anyway, if not for the stable guys to pick it up, for documentation sake :-)

Ok, I'll add that. Thanks for the reply while on your vacation. :)

Thanks,
Namhyung

maintainer Applied
#4 lore raw
Quoted 22 lines · Namhyung Kim

Hi Arnaldo,

Quoted 17 lines · Arnaldo Carvalho de Melo
Quoted 13 lines · Namhyung Kim

Hello,

Quoted 5 lines · Li Dong

What we need to calculate is the size of the object, not the size of the pointer.

Since this problem was introduced in the current dev cycle and not in the mainline yet, I think we can skip the Fixes tag.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

I think we should have it anyway, if not for the stable guys to pick it up, for documentation sake :-)

Ok, I'll add that. Thanks for the reply while on your vacation. :)

Applied to perf-tools-next with the below tag, thanks!

Fixed: 51cfe7a3e87e ("perf python: Avoid 2 leak sanitizer issues")