Tarantool development patches archive
 help / color / mirror / Atom feed
* [Tarantool-patches] [PATCH] cppcheck: box/alter.cc null pointer dereference
@ 2020-09-20 17:59 Sergey Kaplun
  2020-09-21 20:15 ` Vladislav Shpilevoy
  2020-09-28  6:59 ` Kirill Yukhin
  0 siblings, 2 replies; 5+ messages in thread
From: Sergey Kaplun @ 2020-09-20 17:59 UTC (permalink / raw)
  To: Vladislav Shpilevoy, Mergen Imeev; +Cc: tarantool-patches

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-28  6:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-20 17:59 [Tarantool-patches] [PATCH] cppcheck: box/alter.cc null pointer dereference Sergey Kaplun
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

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