[PATCH] Some fixes from trying to build on OpenBSD

Ralph Boehme rb at sernet.de
Wed Nov 18 15:07:05 UTC 2015


Hi!

On Wed, Nov 18, 2015 at 02:55:33PM +0100, Volker Lendecke wrote:
> Unfortunately the patch breaks on sn-devel. We need
> memalign. On OpenBSD this does not exist, so libreplace
> replaces it. The wscript test in libreplace only checks
> whether memalign can link. Unfortunately in glibc memalign
> comes from malloc.h.
> 
> Attached find a new patch.
> 
> Review appreciated!

can we squash the malloc and the memalign commmit?

I'd also add a check whether el_size is 0 to the last commit.

Updated patchset attached, feel free to push.

Btw, what about the memalign check in source3/wscript?

-Ralph

-- 
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@sernet.de
-------------- next part --------------
From a0baffd37438776ec2bd9f54f726ae175b598257 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 30 Jun 2014 13:52:02 +0200
Subject: [PATCH 1/6] libreplace: Only check malloc.h once

Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 lib/replace/wscript | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/replace/wscript b/lib/replace/wscript
index 7bfe7ee..6f4f6bb 100644
--- a/lib/replace/wscript
+++ b/lib/replace/wscript
@@ -71,7 +71,7 @@ def configure(conf):
     conf.CHECK_HEADERS('valgrind.h valgrind/valgrind.h valgrind/memcheck.h')
     conf.CHECK_HEADERS('nss_common.h nsswitch.h ns_api.h')
     conf.CHECK_HEADERS('sys/extattr.h sys/ea.h sys/proplist.h sys/cdefs.h')
-    conf.CHECK_HEADERS('utmp.h utmpx.h lastlog.h malloc.h')
+    conf.CHECK_HEADERS('utmp.h utmpx.h lastlog.h')
     conf.CHECK_HEADERS('syscall.h sys/syscall.h inttypes.h')
     conf.CHECK_HEADERS('sys/atomic.h')
     conf.CHECK_HEADERS('libgen.h')
-- 
2.5.0


From 95cb320fe851b037a2b7ee229159486809665c69 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 30 Jun 2014 15:15:37 +0200
Subject: [PATCH 2/6] libreplace: Put the malloc.h check on a line of its own

Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 lib/replace/wscript | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/replace/wscript b/lib/replace/wscript
index 6f4f6bb..d6cddf5 100644
--- a/lib/replace/wscript
+++ b/lib/replace/wscript
@@ -43,7 +43,9 @@ def configure(conf):
     conf.CHECK_HEADERS('sys/id.h sys/ioctl.h sys/ipc.h sys/mman.h sys/mode.h sys/ndir.h sys/priv.h')
     conf.CHECK_HEADERS('sys/resource.h sys/security.h sys/shm.h sys/statfs.h sys/statvfs.h sys/termio.h')
     conf.CHECK_HEADERS('sys/vfs.h sys/xattr.h termio.h termios.h sys/file.h')
-    conf.CHECK_HEADERS('sys/ucontext.h sys/wait.h sys/stat.h malloc.h grp.h')
+    conf.CHECK_HEADERS('sys/ucontext.h sys/wait.h sys/stat.h')
+    conf.CHECK_HEADERS('malloc.h')
+    conf.CHECK_HEADERS('grp.h')
     conf.CHECK_HEADERS('sys/select.h setjmp.h utime.h sys/syslog.h syslog.h')
     conf.CHECK_HEADERS('stdarg.h vararg.h sys/mount.h mntent.h')
     conf.CHECK_HEADERS('stropts.h unix.h string.h strings.h sys/param.h limits.h')
-- 
2.5.0


From 90d8e670db5ae235ef24101b1de341ba1fb5d1a0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 30 Jun 2014 15:46:21 +0200
Subject: [PATCH 3/6] libreplace: Only check for malloc.h if needed

OpenBSD complains that malloc.h is deprecated on every gcc invocation.
That hides a lot of real warnings. malloc and friends nowadays are
typically defined in stdlib.h, only check there.

We need memalign. On OpenBSD this does not exist, so libreplace replaces
it. The wscript test in libreplace only checks whether memalign can
link. Unfortunately in glibc memalign comes from malloc.h.

Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 lib/replace/wscript | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lib/replace/wscript b/lib/replace/wscript
index d6cddf5..37cbbb7 100644
--- a/lib/replace/wscript
+++ b/lib/replace/wscript
@@ -44,7 +44,10 @@ def configure(conf):
     conf.CHECK_HEADERS('sys/resource.h sys/security.h sys/shm.h sys/statfs.h sys/statvfs.h sys/termio.h')
     conf.CHECK_HEADERS('sys/vfs.h sys/xattr.h termio.h termios.h sys/file.h')
     conf.CHECK_HEADERS('sys/ucontext.h sys/wait.h sys/stat.h')
-    conf.CHECK_HEADERS('malloc.h')
+
+    if not conf.CHECK_DECLS('malloc', headers='stdlib.h'):
+        conf.CHECK_HEADERS('malloc.h')
+
     conf.CHECK_HEADERS('grp.h')
     conf.CHECK_HEADERS('sys/select.h setjmp.h utime.h sys/syslog.h syslog.h')
     conf.CHECK_HEADERS('stdarg.h vararg.h sys/mount.h mntent.h')
@@ -247,6 +250,10 @@ def configure(conf):
     conf.CHECK_FUNCS('link readlink symlink realpath snprintf vsnprintf')
     conf.CHECK_FUNCS('asprintf vasprintf setenv unsetenv strnlen strtoull __strtoull')
     conf.CHECK_FUNCS('strtouq strtoll __strtoll strtoq memalign posix_memalign')
+
+    if conf.CONFIG_SET('HAVE_MEMALIGN'):
+        conf.CHECK_DECLS('memalign', headers='malloc.h')
+
     conf.CHECK_FUNCS('prctl dirname basename')
 
     # libbsd on some platforms provides strlcpy and strlcat
-- 
2.5.0


From 9a5be8ef9f633414d2ab9fe499d11a0448649453 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 16 Nov 2015 16:11:48 +0100
Subject: [PATCH 4/6] idl: Avoid // style comments

Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 librpc/idl/clusapi.idl | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/librpc/idl/clusapi.idl b/librpc/idl/clusapi.idl
index 3440047..5cd815b 100644
--- a/librpc/idl/clusapi.idl
+++ b/librpc/idl/clusapi.idl
@@ -2046,7 +2046,7 @@ import "winreg.idl", "misc.idl";
 #endif
 
 	typedef struct {
-		uint32 dwObjectType;	  // really of type CLUSTER_OBJECT_TYPE_RPC
+		uint32 dwObjectType;	  /* really of type CLUSTER_OBJECT_TYPE_RPC */
 		hyper FilterFlags;
 	} NOTIFY_FILTER_AND_TYPE_RPC;
 
@@ -2068,9 +2068,9 @@ import "winreg.idl", "misc.idl";
 	/*****************/
 	/* Function 0x89 */
 
-	//
-	// Notify interface V2 functions
-	//
+	/*
+	 * Notify interface V2 functions
+	 */
 #if 0
 	HNOTIFY_RPC
 	clusapi_CreateNotifyV2(
-- 
2.5.0


From 3a66b4cfdbf9e85e53e222ca8e86b194fd6bfb67 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Mon, 16 Nov 2015 16:23:10 +0100
Subject: [PATCH 5/6] idl: Some CC can't find indented #defines

Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 librpc/idl/clusapi.idl | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/librpc/idl/clusapi.idl b/librpc/idl/clusapi.idl
index 5cd815b..8c4a227 100644
--- a/librpc/idl/clusapi.idl
+++ b/librpc/idl/clusapi.idl
@@ -28,15 +28,15 @@ import "winreg.idl", "misc.idl";
 	typedef [context_handle] void *HNETINTERFACE_RPC;
 	typedef [context_handle] void *HBATCH_PORT_RPC;
 #else
-	#define HCLUSTER_RPC policy_handle
-	#define HNODE_RPC policy_handle
-	#define HGROUP_RPC policy_handle
-	#define HRES_RPC policy_handle
-	#define HKEY_RPC policy_handle
-	#define HNOTIFY_RPC policy_handle
-	#define HNETWORK_RPC policy_handle
-	#define HNETINTERFACE_RPC policy_handle
-	#define HBATCH_PORT_RPC policy_handle
+#define HCLUSTER_RPC policy_handle
+#define HNODE_RPC policy_handle
+#define HGROUP_RPC policy_handle
+#define HRES_RPC policy_handle
+#define HKEY_RPC policy_handle
+#define HNOTIFY_RPC policy_handle
+#define HNETWORK_RPC policy_handle
+#define HNETINTERFACE_RPC policy_handle
+#define HBATCH_PORT_RPC policy_handle
 #endif
 
 	typedef struct {
-- 
2.5.0


From 2d8285935133de8719cecec5425fbb814bf6ce87 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 18 Nov 2015 13:13:57 +0100
Subject: [PATCH 6/6] lib: Fix memalign_array overflow protection

Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Ralph Boehme <slow at samba.org>
---
 lib/util/util.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/util/util.c b/lib/util/util.c
index d8a84da..03edd7f 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -773,7 +773,7 @@ void *malloc_array(size_t el_size, unsigned int count)
 
 void *memalign_array(size_t el_size, size_t align, unsigned int count)
 {
-	if (count*el_size >= MAX_MALLOC_SIZE) {
+	if (el_size == 0 || count >= MAX_MALLOC_SIZE/el_size) {
 		return NULL;
 	}
 
-- 
2.5.0



More information about the samba-technical mailing list