public inbox for linux-sparse@vger.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Edgar Khachatryan <khachatryan.edgar@student.rau.am>
Cc: linux-sparse@vger.kernel.org
Subject: Re: Issue with Setting Up Sparse
Date: Wed, 12 Mar 2025 18:11:48 +0300	[thread overview]
Message-ID: <aa5d1aa2-1d27-468c-b9b5-38fee37d1179@stanley.mountain> (raw)
In-Reply-To: <CAN1=rvLAcxNqWzRR3EjtNgqk2A3T92iREEYTJdRog3OekK4=NA@mail.gmail.com>

On Wed, Mar 12, 2025 at 06:04:02PM +0400, Edgar Khachatryan wrote:
> My name is Edgar Khachatryan, and I am a student currently working on a
> project that involves static analysis using Sparse. I have encountered an
> issue where running Sparse with the command "sparse file.c" does not detect
> simple memory issues such as memory leaks, double frees, or use-after-free
> errors in a single file.

Sparse doesn't look for those kinds of bugs.  You're better off using
Smatch for that.

With Smatch, I've never really looked for memory leaks.  It's quite a
hard problem and I've never been able to do it in a useful way without
introducing a lot of false positives.

$ ./smatch test.c
test.c:4:18: warning: non-ANSI function declaration of function 'memory_leak'
test.c:13:18: warning: non-ANSI function declaration of function 'double_free'
test.c:23:21: warning: non-ANSI function declaration of function 'use_after_free'
test.c:33:10: warning: non-ANSI function declaration of function 'main'
test.c:20 double_free() error: double free of 'ptr'
test.c:30 use_after_free() error: dereferencing freed memory 'ptr'
$

But the other problem with Smatch is that it's only ever really used on
the kernel so user space support is proof of concept quality.  I had to
push a quick patch it to make it find the use after free bug.  I use
a different check for check_free_strict.c module for kernel code.
https://github.com/error27/smatch/commit/993d157ab147720b558f0f6293dd4acfeb0d2a18

regards,
dan carpenter

      reply	other threads:[~2025-03-12 15:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-12 14:04 Issue with Setting Up Sparse Edgar Khachatryan
2025-03-12 15:11 ` Dan Carpenter [this message]

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=aa5d1aa2-1d27-468c-b9b5-38fee37d1179@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=khachatryan.edgar@student.rau.am \
    --cc=linux-sparse@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