Skip to contentSkip to conversation

pahole: fix BTF function parameter type match check

PATCH In review Florian Larysch 2 participants 2 messages Jul 14 – Jul 16

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pahole: fix BTF function parameter type match check

The BTF_KIND_FUNC_PROTO arm in types__match() first checks whether two function types identified by t1/t2 have matching return types and then attempts to iterate over the function parameters (p1/p2) to check them for compatibility too.

However, the loop just repeats the check on t1/t2 instead of p1/p2, so we just keep re-checking return type compatibility, ignoring possible mismatches of the actual parameter types.

Fix this by actually comparing p1 and p2. This also resolves a unused-but-set-variable build-time warning.

---
 btf_encoder.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
btf_encoder.c +2 -2
index d5af706..3aca2c2 100644
@@ -1129,8 +1129,8 @@ static bool types__match(struct btf_encoder *encoder,
 					  btf2, t2->type))
 				return false;
 			for (i = 0; i < vlen; i++, p1++, p2++) {
-				if (!types__match(encoder, btf1, t1->type,
-						  btf2, t2->type))
+				if (!types__match(encoder, btf1, p1->type,
+						  btf2, p2->type))
 					return false;
 			}
 			return true;
Signature · 1 line
2.55.0
#1 lore raw
Quoted 5 lines · Florian Larysch

The BTF_KIND_FUNC_PROTO arm in types__match() first checks whether two function types identified by t1/t2 have matching return types and then attempts to iterate over the function parameters (p1/p2) to check them for compatibility too.

Quoted 8 lines

However, the loop just repeats the check on t1/t2 instead of p1/p2, so we just keep re-checking return type compatibility, ignoring possible mismatches of the actual parameter types.

Fix this by actually comparing p1 and p2. This also resolves a unused-but-set-variable build-time warning.

Great catch, applied. Thank you!

Alan

Quoted 22 lines
---
 btf_encoder.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
btf_encoder.c +2 -2
index d5af706..3aca2c2 100644
@@ -1129,8 +1129,8 @@ static bool types__match(struct btf_encoder *encoder,
 					  btf2, t2->type))
 				return false;
 			for (i = 0; i < vlen; i++, p1++, p2++) {
-				if (!types__match(encoder, btf1, t1->type,
-						  btf2, t2->type))
+				if (!types__match(encoder, btf1, p1->type,
+						  btf2, p2->type))
 					return false;
 			}
 			return true;
Signature · 1 line
2.55.0