Tarantool development patches archive
 help / color / mirror / Atom feed
From: Sergey Kaplun <skaplun@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>,
	Mergen Imeev <imeevma@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH] cppcheck: box/alter.cc null pointer dereference
Date: Sun, 20 Sep 2020 20:59:30 +0300	[thread overview]
Message-ID: <20200920175930.9016-1-skaplun@tarantool.org> (raw)

Found and fixed Null pointer dereference with cppcheck:

[src/box/alter.cc:395]: (error) Null pointer dereference
---

cppcheck can be run from root project directory as follows:
```
$ cppcheck --force --enable=warning,performance,portability,information --error-exitcode=1 --verbose .
```

branch: https://github.com/tarantool/tarantool/tree/skaplun/cppcheck-alter-null-ptr-dereference

 src/box/alter.cc | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/box/alter.cc b/src/box/alter.cc
index ba96d9c62..d106b7e0b 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -391,9 +391,9 @@ space_opts_decode(struct space_opts *opts, const char *map,
 	if (opts->sql != NULL) {
 		char *sql = strdup(opts->sql);
 		if (sql == NULL) {
+			size_t optlen = strlen(opts->sql) + 1;
 			opts->sql = NULL;
-			diag_set(OutOfMemory, strlen(opts->sql) + 1, "strdup",
-				 "sql");
+			diag_set(OutOfMemory, optlen, "strdup", "sql");
 			return -1;
 		}
 		opts->sql = sql;
-- 
2.28.0

             reply	other threads:[~2020-09-20 17:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-20 17:59 Sergey Kaplun [this message]
2020-09-21 20:15 ` Vladislav Shpilevoy
2020-09-21 20:37   ` Sergey Kaplun
2020-09-21 21:39     ` Vladislav Shpilevoy
2020-09-28  6:59 ` Kirill Yukhin

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=20200920175930.9016-1-skaplun@tarantool.org \
    --to=skaplun@tarantool.org \
    --cc=imeevma@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH] cppcheck: box/alter.cc null pointer dereference' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox