diff options
Diffstat (limited to 'scripts/gcc-plugins/stackleak_plugin.c')
| -rw-r--r-- | scripts/gcc-plugins/stackleak_plugin.c | 29 | 
1 files changed, 25 insertions, 4 deletions
| diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c index e9db7dcb3e5f..42f0252ee2a4 100644 --- a/scripts/gcc-plugins/stackleak_plugin.c +++ b/scripts/gcc-plugins/stackleak_plugin.c @@ -429,6 +429,23 @@ static unsigned int stackleak_cleanup_execute(void)  	return 0;  } +/* + * STRING_CST may or may not be NUL terminated: + * https://gcc.gnu.org/onlinedocs/gccint/Constant-expressions.html + */ +static inline bool string_equal(tree node, const char *string, int length) +{ +	if (TREE_STRING_LENGTH(node) < length) +		return false; +	if (TREE_STRING_LENGTH(node) > length + 1) +		return false; +	if (TREE_STRING_LENGTH(node) == length + 1 && +	    TREE_STRING_POINTER(node)[length] != '\0') +		return false; +	return !memcmp(TREE_STRING_POINTER(node), string, length); +} +#define STRING_EQUAL(node, str)	string_equal(node, str, strlen(str)) +  static bool stackleak_gate(void)  {  	tree section; @@ -438,13 +455,17 @@ static bool stackleak_gate(void)  	if (section && TREE_VALUE(section)) {  		section = TREE_VALUE(TREE_VALUE(section)); -		if (!strncmp(TREE_STRING_POINTER(section), ".init.text", 10)) +		if (STRING_EQUAL(section, ".init.text")) +			return false; +		if (STRING_EQUAL(section, ".devinit.text")) +			return false; +		if (STRING_EQUAL(section, ".cpuinit.text"))  			return false; -		if (!strncmp(TREE_STRING_POINTER(section), ".devinit.text", 13)) +		if (STRING_EQUAL(section, ".meminit.text"))  			return false; -		if (!strncmp(TREE_STRING_POINTER(section), ".cpuinit.text", 13)) +		if (STRING_EQUAL(section, ".noinstr.text"))  			return false; -		if (!strncmp(TREE_STRING_POINTER(section), ".meminit.text", 13)) +		if (STRING_EQUAL(section, ".entry.text"))  			return false;  	} |