Re: [cocci] [RFC] Detecting missing null pointer checks after memory allocations

Markus Elfring <[email protected]>
Newsgroups fr.inria.cocci,org.kernel.vger.kernel-janitors,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
> I got into the mood to try another simple source code search out which
> can be achieved also by the means of the semantic patch language.

I would like to present further data processing approaches accordingly.
The application of a tiny function name selection was demonstrated
by an SmPL disjunction (which can be extended on demand).
Additional techniques can become more helpful for advanced code reviews.

* Further preparations would be needed in software infrastructures (ACID properties)
  if you would like to benefit more from parallel data processing here.

* It might be easier for a while to stick to a serial data processing approach
  like the following.


@initialize:python@
@@
import sys
records = []

def store_data(id, places):
   """Add data to an internal list."""
   for place in places:
      records.append((id, place.current_element, place.file, place.line, str(int(place.column) + 1)))

@searching@
expression size, source, target;
identifier action;
position pos;
@@
 target = action@pos(...);
 memcpy(target, source, size);

@script:python collection@
id << searching.action;
place << searching.pos;
@@
store_data(id, place)

@finalize:python@
@@
if records:
   delimiter = "|"
   sys.stdout.write(delimiter.join(["action", '"function name"', '"source file"', "line", "column"]) + "\n")

   for record in records:
      sys.stdout.write(delimiter.join(record) + "\n")
else:
   sys.stderr.write("No result for this analysis!\n")



A text file can accordingly be generated by the Coccinelle software. It can be
imported into a spreadsheet application. A Pivot table can be constructed then.

Would you become interested to take another look at the 71 called actions
(from 121 source files of the software “Linux next-20251031”) if they would need
the check for a failure predicate before copying data to affected memory areas?
https://cwe.mitre.org/data/definitions/252.html

Under which circumstances will error detection and corresponding exception
handling be completed?
https://wiki.sei.cmu.edu/confluence/display/c/EXP34-C.+Do+not+dereference+null+pointers#EXP34C.Donotdereferencenullpointers-AutomatedDetection

Regards,
Markus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.