mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: cocci@inria.fr, kernel-janitors@vger.kernel.org
Cc: linux-hardening@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: Avoiding selected variables assignments before null pointer checks
Date: Thu, 2 Jul 2026 20:27:06 +0200	[thread overview]
Message-ID: <d7a8e34b-e490-47fc-b892-886e1c799c4f@web.de> (raw)

Avoiding selected variables assignments before null pointer checks


Hello,

Another source code search approach can occasionally be helpful also by the means
of the semantic patch language (Coccinelle software).


Example:
@display@
expression action, input, target;
identifier member1, member2, var;
type t;
@@
(
*t var = \( & \( input->member1 \| input->member1.member2 \) \| action(..., & \( input->member1 \| input->member1.member2 \), ...) \);
 ... when != input
     when any
|
*target = \( & \( input->member1 \| input->member1.member2 \) \| action(..., & \( input->member1 \| input->member1.member2 \), ...) \);
 ... when != input
     when any
)
*if (input == NULL || ...)
(   return ...;
|{
    ...
    return ...;
 }
)


Test result:
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time /usr/bin/spatch --timeout 23 -j4 --chunksize 1 --no-loops -dir . …/Projekte/Coccinelle/janitor/show_pointer_dereferences_before_check10.cocci > …/Projekte/Bau/Linux/scripts/Coccinelle/show_pointer_dereferences_before_check10-20260701.diff 2> …/Projekte/Bau/Linux/scripts/Coccinelle/show_pointer_dereferences_before_check10-errors-20260701.txt

real    32m26,907s
user    105m10,515s
sys     0m45,265s
Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> lsdiff …/Projekte/Bau/Linux/scripts/Coccinelle/show_pointer_dereferences_before_check10-20260701.diff | wc -l
44



How will chances evolve to adjust more places according to remaining update candidates?

See also once more:
EXP34-C: Do not dereference null pointers
https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/expressions-exp/exp34-c/

Regards,
Markus

             reply	other threads:[~2026-07-02 18:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02 18:27 Markus Elfring [this message]
2026-07-09  8:30 ` Avoiding selected variable " Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d7a8e34b-e490-47fc-b892-886e1c799c4f@web.de \
    --to=markus.elfring@web.de \
    --cc=cocci@inria.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®