Skip to content

Commit d6b7326

Browse files
committed
modpost: fix undefined behavior of is_arm_mapping_symbol()
The return value of is_arm_mapping_symbol() is unpredictable when "$" is passed in. strchr(3) says: The strchr() and strrchr() functions return a pointer to the matched character or NULL if the character is not found. The terminating null byte is considered part of the string, so that if c is specified as '\0', these functions return a pointer to the terminator. When str[1] is '\0', strchr("axtd", str[1]) is not NULL, and str[2] is referenced (i.e. buffer overrun). Test code --------- char str1[] = "abc"; char str2[] = "ab"; strcpy(str1, "$"); strcpy(str2, "$"); printf("test1: %d\n", is_arm_mapping_symbol(str1)); printf("test2: %d\n", is_arm_mapping_symbol(str2)); Result ------ test1: 0 test2: 1 Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]>
1 parent b5beffa commit d6b7326

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

scripts/mod/modpost.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,8 @@ static int secref_whitelist(const struct sectioncheck *mismatch,
11801180

11811181
static inline int is_arm_mapping_symbol(const char *str)
11821182
{
1183-
return str[0] == '$' && strchr("axtd", str[1])
1183+
return str[0] == '$' &&
1184+
(str[1] == 'a' || str[1] == 'd' || str[1] == 't' || str[1] == 'x')
11841185
&& (str[2] == '\0' || str[2] == '.');
11851186
}
11861187

0 commit comments

Comments
 (0)