Skip to contentSkip to conversation

perf tools: fix off-by-one comparison on maximum code

PATCH Applied Colin King 3 participants 3 messages Apr 24, 2016 – Apr 27, 2016 perf events

lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 perf tools: fix off-by-one comparison on maximum code

From: Colin Ian King <[email protected]>

The check for the maximum code is off-by-one; the current comparison of a code that is INTEL_PT_ERR_MAX will cause the strlcpy to perform an out of bounds array access on the intel_pt_err_msgs array. Fix this with a >= comparison.

---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -1
index 9409d01..9c8f15d 100644
@@ -356,7 +356,7 @@ static const char *intel_pt_err_msgs[] = {
 
 int intel_pt__strerror(int code, char *buf, size_t buflen)
 {
-	if (code < 1 || code > INTEL_PT_ERR_MAX)
+	if (code < 1 || code >= INTEL_PT_ERR_MAX)
 		code = INTEL_PT_ERR_UNK;
 	strlcpy(buf, intel_pt_err_msgs[code], buflen);
 	return 0;
Signature · 1 line
2.7.4
maintainer Applied
#1 lore raw

Em Sun, Apr 24, 2016 at 07:56:43PM +0100, Colin King escreveu:

Quoted 6 lines

From: Colin Ian King <[email protected]>

The check for the maximum code is off-by-one; the current comparison of a code that is INTEL_PT_ERR_MAX will cause the strlcpy to perform an out of bounds array access on the intel_pt_err_msgs array. Fix this with a >= comparison.

Applied, thanks.

- Arnaldo

Quoted 20 lines
---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -1
index 9409d01..9c8f15d 100644
@@ -356,7 +356,7 @@ static const char *intel_pt_err_msgs[] = {
 
 int intel_pt__strerror(int code, char *buf, size_t buflen)
 {
-	if (code < 1 || code > INTEL_PT_ERR_MAX)
+	if (code < 1 || code >= INTEL_PT_ERR_MAX)
 		code = INTEL_PT_ERR_UNK;
 	strlcpy(buf, intel_pt_err_msgs[code], buflen);
 	return 0;
Signature · 1 line
2.7.4
#2 lore raw

[tip:perf/core] perf intel-pt: Fix off-by-one comparison on maximum code

In reply to Colin King
perf intel-pt: Fix off-by-one comparison on maximum code
Commit-ID:  c0664893050cc6b2d8b02d3e035f82fbfd0cd4cf
Gitweb:     http://git.kernel.org/tip/c0664893050cc6b2d8b02d3e035f82fbfd0cd4cf
Author:     Colin Ian King <[email protected]>
AuthorDate: Sun, 24 Apr 2016 19:56:43 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 25 Apr 2016 20:35:59 -0300

perf intel-pt: Fix off-by-one comparison on maximum code

The check for the maximum code is off-by-one; the current comparison of a code that is INTEL_PT_ERR_MAX will cause the strlcpy to perform an out of bounds array access on the intel_pt_err_msgs array.

Fix this with a >= comparison.

---
 tools/perf/util/intel-pt-decoder/intel-pt-decoder.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/intel-pt-decoder/intel-pt-decoder.c +1 -1
index 9409d01..9c8f15d 100644
@@ -356,7 +356,7 @@ static const char *intel_pt_err_msgs[] = {
 
 int intel_pt__strerror(int code, char *buf, size_t buflen)
 {
-	if (code < 1 || code > INTEL_PT_ERR_MAX)
+	if (code < 1 || code >= INTEL_PT_ERR_MAX)
 		code = INTEL_PT_ERR_UNK;
 	strlcpy(buf, intel_pt_err_msgs[code], buflen);
 	return 0;