[SCM] Samba Shared Repository - branch v3-5-test updated

Karolin Seeger kseeger at samba.org
Thu Nov 15 03:58:22 MST 2012


The branch, v3-5-test has been updated
       via  05f151c lib/replace: replace all *printf function if we replace snprintf (bug #9390)
       via  27405fb libreplace: Fix symbol names for snprintf/asprintf/vasprintf.
       via  fa16d0e libreplace: fixed declaration of dprintf() on FreeBSD (cherry picked from commit a599319d0a389ff0c31dae8068cd7a78352aa9e7)
       via  4bf8dc4 libreplace: added replacements for dprintf() and vdprintf()
       via  4205779 libreplace: some systems don't have memmem()
      from  92292ac Another fix needed for bug #9236 - ACL masks incorrectly applied when setting ACLs.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-5-test


- Log -----------------------------------------------------------------
commit 05f151c041e407514c1b35619b2f2454aa4d614b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Tue Nov 13 14:07:11 2012 +0100

    lib/replace: replace all *printf function if we replace snprintf (bug #9390)
    
    This fixes segfaults in log level = 10 on Solaris.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Signed-off-by: Björn Jacke <bj at sernet.de>
    
    Autobuild-User(master): Björn Jacke <bj at sernet.de>
    Autobuild-Date(master): Wed Nov 14 19:41:14 CET 2012 on sn-devel-104
    (cherry picked from commit a15da3625850d97b3da1b02308c870f820007c52)
    
    The last 5 patches address bug #9390 - Solaris printf doesn't allow %s, NULL.

commit 27405fb8cfaa56f3a39cdcd2fd635fd37af629f9
Author: Jelmer Vernooij <jelmer at samba.org>
Date:   Sun May 13 03:21:34 2012 +0200

    libreplace: Fix symbol names for snprintf/asprintf/vasprintf.
    
    Autobuild-User: Jelmer Vernooij <jelmer at samba.org>
    Autobuild-Date: Sun May 13 05:16:28 CEST 2012 on sn-devel-104
    (cherry picked from commit cf67da70c9a63c4dc63f287059321d6c36d1e19e)

commit fa16d0e4c2329fad8edde5a5e8d626a90caba6d9
Author: Andrew Tridgell <tridge at freebsd.home.tridgell.net>
Date:   Wed Mar 24 05:06:25 2010 +1100

    libreplace: fixed declaration of dprintf() on FreeBSD (cherry picked from commit a599319d0a389ff0c31dae8068cd7a78352aa9e7)

commit 4bf8dc438318e06ee96dc1b6084dddd8700739e7
Author: Andrew Tridgell <tridge at samba.org>
Date:   Thu Feb 11 20:18:50 2010 +1100

    libreplace: added replacements for dprintf() and vdprintf()
    
    these are very useful for writing files with formatted writes
    
    Pair-Programmed-With: Andrew Bartlett <abartlet at samba.org>
    (cherry picked from commit d6fb64c51244529388b1f79ba8220ff608e1e4de)

commit 42057793ebb3ccdc4e63f59753bca8dd677e9748
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sat Jan 2 10:01:11 2010 +1100

    libreplace: some systems don't have memmem()
    
    added rep_memmem() and a testsuite
    (cherry picked from commit fef3c910da421e890925e5e61275fc457da87f6e)

-----------------------------------------------------------------------

Summary of changes:
 lib/replace/libreplace.m4    |    4 ++-
 lib/replace/replace.c        |   54 ++++++++++++++++++++++++++++++++++++++++++
 lib/replace/replace.h        |   38 ++++++++++++++++++++++++++++-
 lib/replace/snprintf.c       |   17 ++++++-------
 lib/replace/test/testsuite.c |   37 ++++++++++++++++++++++++++++
 5 files changed, 138 insertions(+), 12 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/replace/libreplace.m4 b/lib/replace/libreplace.m4
index af85879..7a26deb 100644
--- a/lib/replace/libreplace.m4
+++ b/lib/replace/libreplace.m4
@@ -108,7 +108,7 @@ AC_CHECK_HEADERS(unix.h)
 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
 AC_CHECK_FUNCS(waitpid wait4 strlcpy strlcat initgroups memmove strdup)
-AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2)
+AC_CHECK_FUNCS(pread pwrite strndup strcasestr strtok_r mkdtemp dup2 dprintf vdprintf)
 AC_CHECK_FUNCS(isatty chown lchown link readlink symlink realpath)
 AC_HAVE_DECL(setresuid, [#include <unistd.h>])
 AC_HAVE_DECL(setresgid, [#include <unistd.h>])
@@ -228,6 +228,8 @@ AC_HAVE_DECL(environ, [#include <unistd.h>])
 AC_CHECK_FUNCS(strnlen)
 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
 
+AC_CHECK_FUNCS(memmem)
+
 # this test disabled as we don't actually need __VA_ARGS__ yet
 AC_TRY_CPP([
 #define eprintf(...) fprintf(stderr, __VA_ARGS__)
diff --git a/lib/replace/replace.c b/lib/replace/replace.c
index fc15717..85d0e36 100644
--- a/lib/replace/replace.c
+++ b/lib/replace/replace.c
@@ -681,3 +681,57 @@ char *rep_realpath(const char *path, char *resolved_path)
 	return NULL;
 }
 #endif
+
+
+#ifndef HAVE_MEMMEM
+void *rep_memmem(const void *haystack, size_t haystacklen,
+		 const void *needle, size_t needlelen)
+{
+	if (needlelen == 0) {
+		return discard_const(haystack);
+	}
+	while (haystacklen >= needlelen) {
+		char *p = memchr(haystack, *(const char *)needle,
+				 haystacklen-(needlelen-1));
+		if (!p) return NULL;
+		if (memcmp(p, needle, needlelen) == 0) {
+			return p;
+		}
+		haystack = p+1;
+		haystacklen -= (p - (const char *)haystack) + 1;
+	}
+	return NULL;
+}
+#endif
+
+#if !defined(HAVE_VDPRINTF) || !defined(HAVE_C99_VSNPRINTF)
+int rep_vdprintf(int fd, const char *format, va_list ap)
+{
+	char *s = NULL;
+	int ret;
+
+	vasprintf(&s, format, ap);
+	if (s == NULL) {
+		errno = ENOMEM;
+		return -1;
+	}
+	ret = write(fd, s, strlen(s));
+	free(s);
+	return ret;
+}
+#endif
+
+#if !defined(HAVE_DPRINTF) || !defined(HAVE_C99_VSNPRINTF)
+int rep_dprintf(int fd, const char *format, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, format);
+	ret = vdprintf(fd, format, ap);
+	va_end(ap);
+
+	return ret;
+}
+#endif
+
diff --git a/lib/replace/replace.h b/lib/replace/replace.h
index 6424d10..a028d7a 100644
--- a/lib/replace/replace.h
+++ b/lib/replace/replace.h
@@ -140,6 +140,12 @@ char *rep_strdup(const char *s);
 void *rep_memmove(void *dest,const void *src,int size);
 #endif
 
+#ifndef HAVE_MEMMEM
+#define memmem rep_memmem
+void *rep_memmem(const void *haystack, size_t haystacklen,
+		 const void *needle, size_t needlelen);
+#endif
+
 #ifndef HAVE_MKTIME
 #define mktime rep_mktime
 /* prototype is in "system/time.h" */
@@ -350,7 +356,17 @@ int rep_dlclose(void *handle);
 #endif
 #endif
 
-#ifndef HAVE_VASPRINTF
+#if !defined(HAVE_VDPRINTF) || !defined(HAVE_C99_VSNPRINTF)
+#define vdprintf rep_vdprintf
+int rep_vdprintf(int fd, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
+#endif
+
+#if !defined(HAVE_DPRINTF) || !defined(HAVE_C99_VSNPRINTF)
+#define dprintf rep_dprintf
+int rep_dprintf(int fd, const char *format, ...) PRINTF_ATTRIBUTE(2,3);
+#endif
+
+#if !defined(HAVE_VASPRINTF) || !defined(HAVE_C99_VSNPRINTF)
 #define vasprintf rep_vasprintf
 int rep_vasprintf(char **ptr, const char *format, va_list ap) PRINTF_ATTRIBUTE(2,0);
 #endif
@@ -365,11 +381,29 @@ int rep_snprintf(char *,size_t ,const char *, ...) PRINTF_ATTRIBUTE(3,4);
 int rep_vsnprintf(char *,size_t ,const char *, va_list ap) PRINTF_ATTRIBUTE(3,0);
 #endif
 
-#ifndef HAVE_ASPRINTF
+#if !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_VSNPRINTF)
 #define asprintf rep_asprintf
 int rep_asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
 #endif
 
+#if !defined(HAVE_C99_VSNPRINTF)
+#ifdef REPLACE_BROKEN_PRINTF
+/*
+ * We do not redefine printf by default
+ * as it breaks the build if system headers
+ * use __attribute__((format(printf, 3, 0)))
+ * instead of __attribute__((format(__printf__, 3, 0)))
+ */
+#define printf rep_printf
+#endif
+int rep_printf(const char *, ...) PRINTF_ATTRIBUTE(1,2);
+#endif
+
+#if !defined(HAVE_C99_VSNPRINTF)
+#define fprintf rep_fprintf
+int rep_fprintf(FILE *stream, const char *, ...) PRINTF_ATTRIBUTE(2,3);
+#endif
+
 #ifndef HAVE_VSYSLOG
 #ifdef HAVE_SYSLOG
 #define vsyslog rep_vsyslog
diff --git a/lib/replace/snprintf.c b/lib/replace/snprintf.c
index bca7742..6b4a711 100644
--- a/lib/replace/snprintf.c
+++ b/lib/replace/snprintf.c
@@ -1187,7 +1187,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list,
 	return max;
 }
 
- int vsnprintf (char *str, size_t count, const char *fmt, va_list args)
+ int rep_vsnprintf (char *str, size_t count, const char *fmt, va_list args)
 {
 	return dopr(str, count, fmt, args);
 }
@@ -1200,7 +1200,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list,
  * that doesn't work properly according to the autoconf test.
  */
 #if !defined(HAVE_SNPRINTF) || !defined(HAVE_C99_VSNPRINTF)
- int snprintf(char *str,size_t count,const char *fmt,...)
+ int rep_snprintf(char *str,size_t count,const char *fmt,...)
 {
 	size_t ret;
 	va_list ap;
@@ -1213,7 +1213,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list,
 #endif
 
 #ifndef HAVE_C99_VSNPRINTF
- int printf(const char *fmt, ...)
+ int rep_printf(const char *fmt, ...)
 {
 	va_list ap;
 	int ret;
@@ -1234,7 +1234,7 @@ static int add_cnk_list_entry(struct pr_chunk_x **list,
 #endif
 
 #ifndef HAVE_C99_VSNPRINTF
- int fprintf(FILE *stream, const char *fmt, ...)
+ int rep_fprintf(FILE *stream, const char *fmt, ...)
 {
 	va_list ap;
 	int ret;
@@ -1256,8 +1256,8 @@ static int add_cnk_list_entry(struct pr_chunk_x **list,
 
 #endif 
 
-#ifndef HAVE_VASPRINTF
- int vasprintf(char **ptr, const char *format, va_list ap)
+#if !defined(HAVE_VASPRINTF) || !defined(HAVE_C99_VSNPRINTF)
+ int rep_vasprintf(char **ptr, const char *format, va_list ap)
 {
 	int ret;
 	va_list ap2;
@@ -1278,9 +1278,8 @@ static int add_cnk_list_entry(struct pr_chunk_x **list,
 }
 #endif
 
-
-#ifndef HAVE_ASPRINTF
- int asprintf(char **ptr, const char *format, ...)
+#if !defined(HAVE_ASPRINTF) || !defined(HAVE_C99_VSNPRINTF)
+ int rep_asprintf(char **ptr, const char *format, ...)
 {
 	va_list ap;
 	int ret;
diff --git a/lib/replace/test/testsuite.c b/lib/replace/test/testsuite.c
index 7929f11..caa70d6 100644
--- a/lib/replace/test/testsuite.c
+++ b/lib/replace/test/testsuite.c
@@ -1015,6 +1015,42 @@ static int test_utimes(void)
 	return true;
 }
 
+static int test_memmem(void)
+{
+	char *s;
+
+	printf("test: memmem\n");
+
+	s = memmem("foo", 3, "fo", 2);
+	if (strcmp(s, "foo") != 0) {
+		printf(__location__ ": Failed memmem\n");
+		return false;
+	}
+
+	s = memmem("foo", 3, "", 0);
+	if (strcmp(s, "foo") != 0) {
+		printf(__location__ ": Failed memmem\n");
+		return false;
+	}
+
+	s = memmem("foo", 4, "o", 1);
+	if (strcmp(s, "oo") != 0) {
+		printf(__location__ ": Failed memmem\n");
+		return false;
+	}
+
+	s = memmem("foobarfodx", 11, "fod", 3);
+	if (strcmp(s, "fodx") != 0) {
+		printf(__location__ ": Failed memmem\n");
+		return false;
+	}
+
+	printf("success: memmem\n");
+
+	return true;
+}
+
+
 struct torture_context;
 bool torture_local_replace(struct torture_context *ctx)
 {
@@ -1065,6 +1101,7 @@ bool torture_local_replace(struct torture_context *ctx)
 	ret &= test_getifaddrs();
 	ret &= test_utime();
 	ret &= test_utimes();
+	ret &= test_memmem();
 
 	return ret;
 }


-- 
Samba Shared Repository


More information about the samba-cvs mailing list