All of lore.kernel.org
 help / color / mirror / Atom feed
From: William Roberts <bill.c.roberts@gmail.com>
To: Nicolas Iooss <nicolas.iooss@m4x.org>
Cc: selinux@tycho.nsa.gov
Subject: Re: [PATCH 3/6] libsemanage: never call memcpy with a NULL value
Date: Mon, 27 Feb 2017 14:16:04 -0800	[thread overview]
Message-ID: <CAFftDdry4gzU33U3UuZBk=mk_A-K9+TQieUc7cTWkR10ZAWO=g@mail.gmail.com> (raw)
In-Reply-To: <20170227203935.23674-3-nicolas.iooss@m4x.org>

[-- Attachment #1: Type: text/plain, Size: 1434 bytes --]

On Feb 27, 2017 12:42, "Nicolas Iooss" <nicolas.iooss@m4x.org> wrote:

clang's static analyzer reports "Argument with 'nonnull' attribute
passed null" in append_str(), because argument t may be NULL but is used
in a call to memcpy().

Make append_str() do nothing when called with t=NULL.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 libsemanage/src/semanage_store.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/libsemanage/src/semanage_store.c b/libsemanage/src/semanage_
store.c
index f468faba4b64..47ec93185e06 100644
--- a/libsemanage/src/semanage_store.c
+++ b/libsemanage/src/semanage_store.c
@@ -1194,8 +1194,14 @@ static char *append(char *s, char c)
 static char *append_str(char *s, const char *t)
 {
        size_t s_len = (s == NULL ? 0 : strlen(s));
-       size_t t_len = (t == NULL ? 0 : strlen(t));
-       char *new_s = realloc(s, s_len + t_len + 1);
+       size_t t_len;
+       char *new_s;
+
+       if (t == NULL) {
+               return s;
+       }
+       t_len = strlen(t);
+       new_s = realloc(s, s_len + t_len + 1);


Overflow possibility here?

        if (new_s == NULL) {
                return NULL;
        }
--
2.11.1

_______________________________________________
Selinux mailing list
Selinux@tycho.nsa.gov
To unsubscribe, send email to Selinux-leave@tycho.nsa.gov.
To get help, send an email containing "help" to
Selinux-request@tycho.nsa.gov.

[-- Attachment #2: Type: text/html, Size: 2541 bytes --]

  reply	other threads:[~2017-02-27 22:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-27 20:39 [PATCH 1/6] semodule_package: do not leak memory when using -u or -s Nicolas Iooss
2017-02-27 20:39 ` [PATCH 2/6] libsepol/cil: do not dereference args before checking it was not null Nicolas Iooss
2017-02-27 20:39 ` [PATCH 3/6] libsemanage: never call memcpy with a NULL value Nicolas Iooss
2017-02-27 22:16   ` William Roberts [this message]
2017-02-28  4:05     ` William Roberts
2017-02-27 20:39 ` [PATCH 4/6] libsemanage/tests: include libsepol headers from $DESTDIR Nicolas Iooss
2017-02-27 20:39 ` [PATCH 5/6] mcstrans: do not dereference color_str if it is NULL Nicolas Iooss
2017-02-27 20:39 ` [PATCH 6/6] libselinux: initialize temp value in SWIG wrapper to prevent freeing garbage Nicolas Iooss
2017-03-01 16:35 ` [PATCH 1/6] semodule_package: do not leak memory when using -u or -s James Carter

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='CAFftDdry4gzU33U3UuZBk=mk_A-K9+TQieUc7cTWkR10ZAWO=g@mail.gmail.com' \
    --to=bill.c.roberts@gmail.com \
    --cc=nicolas.iooss@m4x.org \
    --cc=selinux@tycho.nsa.gov \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.