Powered by Linux
Re: [PATCH] direct_return_instead_of_goto: don't warn about other forms of printks — Semantic Matching Tool

Re: [PATCH] direct_return_instead_of_goto: don't warn about other forms of printks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Feb 11, 2023 at 05:43:17AM -0800, Harshit Mogalapalli wrote:
> @@ -76,6 +77,8 @@ static bool is_printk_stmt(struct statement *stmt)
>  	if (!str)
>  		return false;
>  
> +	len = strlen(str);
> +
>  	if (strcmp(str, "dev_err") == 0 ||
>  	    strcmp(str, "dev_info") == 0 ||
>  	    strcmp(str, "dev_warn") == 0 ||
> @@ -92,6 +95,11 @@ static bool is_printk_stmt(struct statement *stmt)
>  	    strcmp(str, "pr_debug") == 0)
>  		return true;
>  
> +	if (strcmp(&str[len - 8], "_dev_err") == 0 ||
> +	    strcmp(&str[len - 9], "_dev_warn") == 0 ||
> +	    strcmp(&str[len - 8], "_dev_dbg") == 0)

This code assumes that len is >= 8, but we don't know that's true.

You should write a Smatch check for that kind of subtraction.  The
heuristic is:
1) We have a string. "str" in this case.
2) The offset is a subtraction.
3) We do not know that len >= 8.

regards,
dan carpenter




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux