Coverity and cleanup patches
Volker Lendecke
Volker.Lendecke at SerNet.DE
Mon Dec 16 03:58:08 MST 2013
Hi!
Attached find some Coverity fixes and other smaller
cleanups.
Please review & push!
Thanks,
Volker
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From dafd445cf28c2c4f6670c7edcfd947bb45f4a364 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 20:22:36 +0100
Subject: [PATCH 01/13] tdb_util: Fix CID 1138343 Uninitialized scalar
variable
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/tdb_wrap/tdb_wrap.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/lib/tdb_wrap/tdb_wrap.c b/lib/tdb_wrap/tdb_wrap.c
index 0f49be1..c50c6e0 100644
--- a/lib/tdb_wrap/tdb_wrap.c
+++ b/lib/tdb_wrap/tdb_wrap.c
@@ -120,6 +120,8 @@ static struct tdb_wrap_private *tdb_wrap_private_open(TALLOC_CTX *mem_ctx,
}
lctx.log_fn = tdb_wrap_log;
+ lctx.log_private = NULL;
+
result->tdb = tdb_open_ex(name, hash_size, tdb_flags,
open_flags, mode, &lctx, NULL);
if (result->tdb == NULL) {
--
1.7.9.5
From f3cd9e9b195779f4b21d61321e377a2bdbf7a3ae Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 20:23:16 +0100
Subject: [PATCH 02/13] tdb_util: Fix whitespace
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/tdb_wrap/tdb_wrap.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/lib/tdb_wrap/tdb_wrap.c b/lib/tdb_wrap/tdb_wrap.c
index c50c6e0..312d17f 100644
--- a/lib/tdb_wrap/tdb_wrap.c
+++ b/lib/tdb_wrap/tdb_wrap.c
@@ -1,20 +1,20 @@
-/*
+/*
Unix SMB/CIFS implementation.
TDB wrap functions
Copyright (C) Andrew Tridgell 2004
Copyright (C) Jelmer Vernooij <jelmer at samba.org> 2007
-
+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
-
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -28,10 +28,10 @@
/*
Log tdb messages via DEBUG().
*/
-static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level,
+static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level,
const char *format, ...) PRINTF_ATTRIBUTE(3,4);
-static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level,
+static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level,
const char *format, ...)
{
va_list ap;
@@ -54,7 +54,7 @@ static void tdb_wrap_log(TDB_CONTEXT *tdb, enum tdb_debug_level level,
break;
default:
debuglevel = 0;
- }
+ }
va_start(ap, format);
ret = vasprintf(&ptr, format, ap);
@@ -81,7 +81,7 @@ static int tdb_wrap_private_destructor(struct tdb_wrap_private *w)
tdb_close(w->tdb);
DLIST_REMOVE(tdb_list, w);
return 0;
-}
+}
static struct tdb_wrap_private *tdb_wrap_private_open(TALLOC_CTX *mem_ctx,
const char *name,
--
1.7.9.5
From e9bccf949b8a624a02bac581f3b101a8a133db70 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 20:28:04 +0100
Subject: [PATCH 03/13] Fix CID 1138341 Resource leak
Signed-off-by: Volker Lendecke <vl at samba.org>
---
ctdb/lib/replace/test/testsuite.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/ctdb/lib/replace/test/testsuite.c b/ctdb/lib/replace/test/testsuite.c
index 52629ec..387f096 100644
--- a/ctdb/lib/replace/test/testsuite.c
+++ b/ctdb/lib/replace/test/testsuite.c
@@ -266,12 +266,14 @@ static int test_strndup(void)
x = strndup("bla", 2);
if (strcmp(x, "bl") != 0) {
printf("failure: strndup [\ninvalid\n]\n");
+ free(x);
return false;
}
free(x);
x = strndup("bla", 10);
if (strcmp(x, "bla") != 0) {
printf("failure: strndup [\ninvalid\n]\n");
+ free(x);
return false;
}
free(x);
--
1.7.9.5
From 66c61855b665fdae7400e1ce09e3efe964e9b868 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 20:28:53 +0100
Subject: [PATCH 04/13] Fix CID 1138340 Resource leak
Signed-off-by: Volker Lendecke <vl at samba.org>
---
ctdb/lib/replace/test/testsuite.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/ctdb/lib/replace/test/testsuite.c b/ctdb/lib/replace/test/testsuite.c
index 387f096..df8b71f 100644
--- a/ctdb/lib/replace/test/testsuite.c
+++ b/ctdb/lib/replace/test/testsuite.c
@@ -166,6 +166,7 @@ static int test_strdup(void)
if (strcmp("bla", x) != 0) {
printf("failure: strdup [\nfailed: expected \"bla\", got \"%s\"\n]\n",
x);
+ free(x);
return false;
}
free(x);
--
1.7.9.5
From 68dc10165756d51463a754dcdd1d4fc9a6b7d354 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 20:40:06 +0100
Subject: [PATCH 05/13] tevent: Fix CID 1138326 Unchecked return value
For this case we explicitly have added tevent_req_oom
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/tevent/tevent_queue.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/tevent/tevent_queue.c b/lib/tevent/tevent_queue.c
index 0c5fe4e..930319c 100644
--- a/lib/tevent/tevent_queue.c
+++ b/lib/tevent/tevent_queue.c
@@ -325,7 +325,7 @@ struct tevent_req *tevent_queue_wait_send(TALLOC_CTX *mem_ctx,
tevent_queue_wait_trigger,
NULL);
if (!ok) {
- tevent_req_nomem(NULL, req);
+ tevent_req_oom(req);
return tevent_req_post(req, ev);
}
--
1.7.9.5
From 48a5d62b58b089da52da347aa9ced884f5b4eb67 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 21:00:04 +0100
Subject: [PATCH 06/13] ntvfs: Fix CID 241291 Argument cannot be negative
getgroups can return -1, which talloc_array won't be happy about
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/ntvfs/posix/pvfs_acl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source4/ntvfs/posix/pvfs_acl.c b/source4/ntvfs/posix/pvfs_acl.c
index 4e9c1ac..730ad48 100644
--- a/source4/ntvfs/posix/pvfs_acl.c
+++ b/source4/ntvfs/posix/pvfs_acl.c
@@ -497,7 +497,7 @@ static bool pvfs_group_member(struct pvfs_state *pvfs, gid_t gid)
return true;
}
ngroups = getgroups(0, NULL);
- if (ngroups == 0) {
+ if (ngroups <= 0) {
return false;
}
groups = talloc_array(pvfs, gid_t, ngroups);
--
1.7.9.5
From 21db76cc0f6971239a928878dd73edd8db1104ea Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 21:07:00 +0100
Subject: [PATCH 07/13] scannedonly: Fix CID 242109 Unchecked return value
from library
---
source3/modules/vfs_scannedonly.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/source3/modules/vfs_scannedonly.c b/source3/modules/vfs_scannedonly.c
index 0d2e7cc..3cee511 100644
--- a/source3/modules/vfs_scannedonly.c
+++ b/source3/modules/vfs_scannedonly.c
@@ -228,10 +228,12 @@ static int connect_to_scanner(vfs_handle_struct * handle)
large directory with lots of unscanned files. */
int sndsize;
socklen_t size = sizeof(int);
- getsockopt(so->socket, SOL_SOCKET, SO_RCVBUF,
- (char *)&sndsize, &size);
- DEBUG(SCANNEDONLY_DEBUG, ("current socket buffer size=%d\n",
- sndsize));
+ if (getsockopt(so->socket, SOL_SOCKET, SO_RCVBUF,
+ (char *)&sndsize, &size) == 0) {
+ DEBUG(SCANNEDONLY_DEBUG,
+ ("current socket buffer size=%d\n",
+ sndsize));
+ }
sndsize = 262144;
if (setsockopt(so->socket, SOL_SOCKET, SO_RCVBUF,
(char *)&sndsize,
--
1.7.9.5
From 6721b8e9f28e032dfc15b1b57f5ad3a10613623a Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 21:18:07 +0100
Subject: [PATCH 08/13] smbd: Fix CID 1138328 Logically dead code
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/smbd/smb2_server.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/source3/smbd/smb2_server.c b/source3/smbd/smb2_server.c
index 768a9c8..fe42ac9 100644
--- a/source3/smbd/smb2_server.c
+++ b/source3/smbd/smb2_server.c
@@ -2963,11 +2963,13 @@ static int socket_error_from_errno(int ret,
}
#ifdef EWOULDBLOCK
+#if EWOULDBLOCK != EAGAIN
if (sys_errno == EWOULDBLOCK) {
*retry = true;
return sys_errno;
}
#endif
+#endif
return sys_errno;
}
--
1.7.9.5
From 836b49a4b0cb0d6de4511ff5ac8e4e07e06446e8 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 21:23:59 +0100
Subject: [PATCH 09/13] ldb: Fix 1138330 Dereference null return value
Signed-off-by: Volker Lendecke <vl at samba.org>
---
lib/ldb/common/ldb.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/ldb/common/ldb.c b/lib/ldb/common/ldb.c
index d2b873f..e5fa819 100644
--- a/lib/ldb/common/ldb.c
+++ b/lib/ldb/common/ldb.c
@@ -112,6 +112,10 @@ struct ldb_context *ldb_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev_ctx)
* having to provide their own private one explicitly */
if (ev_ctx == NULL) {
ev_ctx = tevent_context_init(ldb);
+ if (ev_ctx == NULL) {
+ talloc_free(ldb);
+ return NULL;
+ }
tevent_set_debug(ev_ctx, ldb_tevent_debug, ldb);
tevent_loop_allow_nesting(ev_ctx);
}
--
1.7.9.5
From 103b3ef31fef0edebfa8d75a4a82ebb2f32beef6 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 21:28:08 +0100
Subject: [PATCH 10/13] share_ldb: Fix CID 1138337 Dereference null return
value
False positive, but this way we avoid another strchr
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/param/share_ldb.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c
index f4d02b2..1473eb0 100644
--- a/source4/param/share_ldb.c
+++ b/source4/param/share_ldb.c
@@ -62,20 +62,21 @@ static const char *sldb_string_option(struct share_config *scfg, const char *opt
{
struct ldb_message *msg;
struct ldb_message_element *el;
+ const char *colon;
if (scfg == NULL) return defval;
msg = talloc_get_type(scfg->opaque, struct ldb_message);
- if (strchr(opt_name, ':')) {
- char *name, *p;
+ colon = strchr(opt_name, ':');
+ if (colon != NULL) {
+ char *name;
name = talloc_strdup(scfg, opt_name);
if (!name) {
return NULL;
}
- p = strchr(name, ':');
- *p = '-';
+ name[colon-opt_name] = '-';
el = ldb_msg_find_element(msg, name);
} else {
--
1.7.9.5
From d3c0461b6f757aff1838a9d6b74adf5a3d766d2c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 21:29:59 +0100
Subject: [PATCH 11/13] share_ldb: Fix a memleak
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/param/share_ldb.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c
index 1473eb0..212d910 100644
--- a/source4/param/share_ldb.c
+++ b/source4/param/share_ldb.c
@@ -79,6 +79,7 @@ static const char *sldb_string_option(struct share_config *scfg, const char *opt
name[colon-opt_name] = '-';
el = ldb_msg_find_element(msg, name);
+ TALLOC_FREE(name);
} else {
el = ldb_msg_find_element(msg, opt_name);
}
--
1.7.9.5
From 57bed72fff7910d0425480f9e805f5b0646b552c Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 21:28:08 +0100
Subject: [PATCH 12/13] share_ldb: Fix CID 1138336 Dereference null return
value
False positive, but this way we avoid another strchr
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/param/share_ldb.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c
index 212d910..601ab04 100644
--- a/source4/param/share_ldb.c
+++ b/source4/param/share_ldb.c
@@ -123,21 +123,22 @@ static const char **sldb_string_list_option(TALLOC_CTX *mem_ctx, struct share_co
struct ldb_message *msg;
struct ldb_message_element *el;
const char **list;
+ const char *colon;
int i;
if (scfg == NULL) return NULL;
msg = talloc_get_type(scfg->opaque, struct ldb_message);
- if (strchr(opt_name, ':')) {
- char *name, *p;
+ colon = strchr(opt_name, ':');
+ if (colon != NULL) {
+ char *name;
name = talloc_strdup(scfg, opt_name);
if (!name) {
return NULL;
}
- p = strchr(name, ':');
- *p = '-';
+ name[colon-opt_name] = '-';
el = ldb_msg_find_element(msg, name);
} else {
--
1.7.9.5
From efc9a7781b26a0c1c9efd8cb3cda33d4a500851e Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 15 Dec 2013 21:28:08 +0100
Subject: [PATCH 13/13] share_ldb: Fix a memleak
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source4/param/share_ldb.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c
index 601ab04..0e27376 100644
--- a/source4/param/share_ldb.c
+++ b/source4/param/share_ldb.c
@@ -141,6 +141,7 @@ static const char **sldb_string_list_option(TALLOC_CTX *mem_ctx, struct share_co
name[colon-opt_name] = '-';
el = ldb_msg_find_element(msg, name);
+ TALLOC_FREE(name);
} else {
el = ldb_msg_find_element(msg, opt_name);
}
--
1.7.9.5
More information about the samba-technical
mailing list