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 12/02/23 5:08 pm, Marion & Christophe JAILLET wrote:

Le 12/02/2023 à 07:17, Harshit Mogalapalli a écrit :


On 12/02/23 12:34 am, Marion JAILLET wrote:

Le 11/02/2023 à 14:43, Harshit Mogalapalli a écrit :
Also tracking these type of goto are uninteresting for the check.
fail:
     ata_dev_err(dev, "failed to set xfermode (err_mask=0x%x)\n", err_mask);
     return -EIO;

Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@xxxxxxxxxx>
---
  check_direct_return_instead_of_goto.c | 8 ++++++++
  1 file changed, 8 insertions(+)

diff --git a/check_direct_return_instead_of_goto.c b/check_direct_return_instead_of_goto.c
index b075bc2f..90e5aed6 100644
--- a/check_direct_return_instead_of_goto.c
+++ b/check_direct_return_instead_of_goto.c
@@ -68,6 +68,7 @@ static bool is_do_nothing_goto(struct statement *goto_stmt)
  static bool is_printk_stmt(struct statement *stmt)
  {
      char *str;
+    int len;
      if (!stmt)
          return false;
@@ -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)

Hi,

When we get here, can len be <8 or <9 ?

Hi,

Yes, that is possible but strcmp will just return a negative number in that case.

https://urldefense.com/v3/__https://godbolt.org/z/Gxj55feec__;!!ACWV5N9M2RV99hQ!L7nft0e17YoAGEh2vNNVdi0HkFI3b2zVY2MgsgHR-k2ubQ90EDwViQyHBnevAWdjT0JP9NsPgnCjbUbe6ukOnqtZ_wr2vfMBp8A0zok$
So I think we don't need check on len.

Hi,

for me, it means that we could access "random memory", and possibly, crash.
Maybe strstr() would make it?


Hi Christophe,

Thanks for the suggestion. I will send a v2 with this.

Regards,
Harshit

CJ



Any thoughts?

Thanks,
Harshit


CJ


+        return true;
+
      return false;
  }



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

  Powered by Linux