Skip to contentSkip to conversation

lsdir_bid_tail_filter: fix index check

PATCH In review Gaurav Singh 2 participants 2 messages Jun 24, 2020 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lsdir_bid_tail_filter: fix index check

Check bounds before accessing d->d_name[].

---
 tools/perf/util/build-id.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/build-id.c +1 -1
index c076fc7fe025..8c35cbe93f10 100644
@@ -431,7 +431,7 @@ static bool lsdir_bid_tail_filter(const char *name __maybe_unused,
 				  struct dirent *d)
 {
 	int i = 0;
-	while (isxdigit(d->d_name[i]) && i < SBUILD_ID_SIZE - 3)
+	while (i < SBUILD_ID_SIZE - 3 && isxdigit(d->d_name[i]))
 		i++;
 	return (i == SBUILD_ID_SIZE - 3) && (d->d_name[i] == '\0');
 }
Signature · 1 line
2.17.1
#1 lore raw
Quoted 12 lines · Gaurav Singh

Check bounds before accessing d->d_name[].

---
 tools/perf/util/build-id.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/build-id.c +0 -0
index c076fc7fe025..8c35cbe93f10 100644

tools/perf/util/build-id.c static bool lsdir_bid_tail_filter(const char *name __maybe_unused, · line 434

Quoted 5 lines
tools/perf/util/build-id.c +1 -1
@@ -431,7 +431,7 @@ static bool lsdir_bid_tail_filter(const char *name __maybe_unused,
 				  struct dirent *d)
 {
 	int i = 0;
-	while (isxdigit(d->d_name[i]) && i < SBUILD_ID_SIZE - 3)
+	while (i < SBUILD_ID_SIZE - 3 && isxdigit(d->d_name[i]))

hum, I guess it looks better, but technicaly this is not a problem right?

isxdigit will return false on zero byte which is always present in d->d_name so it will never get out of bounds

jirka

Quoted 6 lines
tools/perf/util/build-id.c +0 -0
 		i++;
 	return (i == SBUILD_ID_SIZE - 3) && (d->d_name[i] == '\0');
 }
Signature · 1 line
2.17.1