[PATCH] Some fixes detected by Undefined Sanitizer
Andreas Schneider
asn at samba.org
Wed Nov 21 10:20:44 UTC 2018
Hi,
see attached. Review and comments are welcome. Please push if OK.
Thanks,
Andreas
--
Andreas Schneider asn at samba.org
Samba Team www.samba.org
GPG-ID: 8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D
-------------- next part --------------
>From 239a4e5dc22e95cd11c4ead2762b5b4b18535828 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Fri, 16 Nov 2018 16:07:42 +0100
Subject: [PATCH 1/5] s4:bind_dlz: Only copy the dn once
../source4/dns_server/dlz_bind9.c:1132:4: error: 'dn' may be used uninitialized in this function [-Werror=maybe-uninitialized]
state->log(ISC_LOG_INFO, "failed to find dnsRecord for %s",
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ldb_dn_get_linearized(dn));
~~~~~~~~~~~~~~~~~~~~~~~~~~
Found by Undefined Sanitizer.
Signed-off-by: Andreas Schneider <asn at samba.org>
---
source4/dns_server/dlz_bind9.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/source4/dns_server/dlz_bind9.c b/source4/dns_server/dlz_bind9.c
index 43f3e57c789..8f02b07856f 100644
--- a/source4/dns_server/dlz_bind9.c
+++ b/source4/dns_server/dlz_bind9.c
@@ -1060,20 +1060,20 @@ _PUBLIC_ isc_result_t dlz_allnodes(const char *zone, void *dbdata,
struct dlz_bind9_data *state = talloc_get_type_abort(dbdata, struct dlz_bind9_data);
const char *attrs[] = { "dnsRecord", NULL };
int ret = LDB_SUCCESS, i, j;
- struct ldb_dn *dn;
+ struct ldb_dn *dn = NULL;
struct ldb_result *res;
TALLOC_CTX *tmp_ctx = talloc_new(state);
struct ldb_val zone_name_val = data_blob_string_const(zone);
+ dn = ldb_dn_copy(tmp_ctx, ldb_get_default_basedn(state->samdb));
+ if (dn == NULL) {
+ talloc_free(tmp_ctx);
+ return ISC_R_NOMEMORY;
+ }
+
for (i=0; zone_prefixes[i]; i++) {
const char *casefold;
- dn = ldb_dn_copy(tmp_ctx, ldb_get_default_basedn(state->samdb));
- if (dn == NULL) {
- talloc_free(tmp_ctx);
- return ISC_R_NOMEMORY;
- }
-
/*
* This dance ensures that it is not possible to put
* (eg) an extra DC=x, into the DNS name being
--
2.19.1
>From e18caeda1be00d214165ab41f022dcafa92678a7 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Fri, 16 Nov 2018 18:25:58 +0100
Subject: [PATCH 2/5] s4:torture: Initialize pointers in libnetapi user test
Found by Undefined Sanitizer.
Signed-off-by: Andreas Schneider <asn at samba.org>
---
source4/torture/libnetapi/libnetapi_user.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/source4/torture/libnetapi/libnetapi_user.c b/source4/torture/libnetapi/libnetapi_user.c
index e925725e5f0..134b4e8b9c0 100644
--- a/source4/torture/libnetapi/libnetapi_user.c
+++ b/source4/torture/libnetapi/libnetapi_user.c
@@ -271,8 +271,8 @@ static NET_API_STATUS test_netusergetgroups(struct torture_context *tctx,
uint8_t *buffer = NULL;
int i;
- struct GROUP_USERS_INFO_0 *i0;
- struct GROUP_USERS_INFO_1 *i1;
+ struct GROUP_USERS_INFO_0 *i0 = NULL;
+ struct GROUP_USERS_INFO_1 *i1 = NULL;
torture_comment(tctx, "Testing NetUserGetGroups level %d\n", level);
--
2.19.1
>From 2b075d762a4ff0189f5fc32f5f9ec0e406087b40 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Fri, 16 Nov 2018 20:02:26 +0100
Subject: [PATCH 3/5] s3:tests: Initialize pointers with NULL in netdisplay
test
Found by Undefined Sanitizer
Signed-off-by: Andreas Schneider <asn at samba.org>
---
source3/lib/netapi/tests/netdisplay.c | 6 +++---
source3/lib/netapi/tests/netuser.c | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/source3/lib/netapi/tests/netdisplay.c b/source3/lib/netapi/tests/netdisplay.c
index 090792cec2f..d7967fa4150 100644
--- a/source3/lib/netapi/tests/netdisplay.c
+++ b/source3/lib/netapi/tests/netdisplay.c
@@ -39,9 +39,9 @@ static NET_API_STATUS test_netquerydisplayinformation(const char *hostname,
uint32_t idx = 0;
int i;
- struct NET_DISPLAY_USER *user;
- struct NET_DISPLAY_GROUP *group;
- struct NET_DISPLAY_MACHINE *machine;
+ struct NET_DISPLAY_USER *user = NULL;
+ struct NET_DISPLAY_GROUP *group = NULL;
+ struct NET_DISPLAY_MACHINE *machine = NULL;
printf("testing NetQueryDisplayInformation level %d\n", level);
diff --git a/source3/lib/netapi/tests/netuser.c b/source3/lib/netapi/tests/netuser.c
index de5f0a102d9..ad2bb53f18c 100644
--- a/source3/lib/netapi/tests/netuser.c
+++ b/source3/lib/netapi/tests/netuser.c
@@ -265,8 +265,8 @@ static NET_API_STATUS test_netusergetgroups(const char *hostname,
uint8_t *buffer = NULL;
int i;
- struct GROUP_USERS_INFO_0 *i0;
- struct GROUP_USERS_INFO_1 *i1;
+ struct GROUP_USERS_INFO_0 *i0 = NULL;
+ struct GROUP_USERS_INFO_1 *i1 = NULL;
printf("testing NetUserGetGroups level %d\n", level);
--
2.19.1
>From fc65a9de59b76c73c087fed04866eb1bc63e6d72 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Tue, 20 Nov 2018 10:37:01 +0100
Subject: [PATCH 4/5] lib:util: Always include unistd.h for setgroups
This is needed to pass configure checks
Signed-off-by: Andreas Schneider <asn at samba.org>
---
lib/util/setid.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/util/setid.c b/lib/util/setid.c
index eb7511083f0..10014618def 100644
--- a/lib/util/setid.c
+++ b/lib/util/setid.c
@@ -34,6 +34,9 @@
#include <sys/types.h>
#include <errno.h>
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h>
+#endif
#ifdef HAVE_SYS_PRIV_H
#include <sys/priv.h>
#endif
@@ -57,9 +60,6 @@ int samba_setgroups(size_t setlen, const gid_t *gidset);
#endif
#if defined(HAVE_LINUX_THREAD_CREDENTIALS)
-#if defined(HAVE_UNISTD_H)
-#include <unistd.h>
-#endif
#if defined(HAVE_SYSCALL_H)
#include <syscall.h>
#endif
--
2.19.1
>From 53984aae3633fcd2977b9c8129159d67e608874a Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn at samba.org>
Date: Tue, 20 Nov 2018 10:39:28 +0100
Subject: [PATCH 5/5] s3:lib: Do not redefine bool and use stdbool.h
Signed-off-by: Andreas Schneider <asn at samba.org>
---
source3/lib/util_sec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/source3/lib/util_sec.c b/source3/lib/util_sec.c
index 703c522d77b..94082697def 100644
--- a/source3/lib/util_sec.c
+++ b/source3/lib/util_sec.c
@@ -28,6 +28,7 @@
#if defined(HAVE_UNISTD_H)
#include <unistd.h>
#endif
+#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
@@ -42,7 +43,6 @@
#define DEBUG(x, y) printf y
#define smb_panic(x) exit(1)
-#define bool int
#endif
/* are we running as non-root? This is used by the regresison test code,
--
2.19.1
More information about the samba-technical
mailing list