diff options
-rw-r--r-- | source3/configure.in | 2 | ||||
-rw-r--r-- | source3/lib/charcnv.c | 24 | ||||
-rw-r--r-- | source3/lib/util_str.c | 12 |
3 files changed, 34 insertions, 4 deletions
diff --git a/source3/configure.in b/source3/configure.in index bbfdc2e382..91ea0ff99e 100644 --- a/source3/configure.in +++ b/source3/configure.in @@ -601,7 +601,7 @@ else RUNPROG="" fi -AC_CHECK_FUNCS(dlopen dlclose dlsym dlerror waitpid getcwd strdup strndup strtoul strerror chown fchown chmod fchmod chroot link mknod mknod64) +AC_CHECK_FUNCS(dlopen dlclose dlsym dlerror waitpid getcwd strdup strndup strnlen strtoul strerror chown fchown chmod fchmod chroot link mknod mknod64) AC_CHECK_FUNCS(fstat strchr utime utimes getrlimit fsync bzero memset strlcpy strlcat setpgid) AC_CHECK_FUNCS(memmove vsnprintf snprintf asprintf vasprintf setsid glob strpbrk pipe crypt16 getauthuid) AC_CHECK_FUNCS(strftime sigprocmask sigblock sigaction sigset innetgr setnetgrent getnetgrent endnetgrent) diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index be7701237e..803cda36c8 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -354,7 +354,13 @@ int pull_ascii(char *dest, const void *src, int dest_len, int src_len, int flags dest_len = sizeof(pstring); } - if (src_len == -1 && (flags & STR_TERMINATE)) src_len = strlen(src)+1; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen(src)+1; + } else { + src_len = strnlen(src, src_len) + 1; + } + } ret = convert_string(CH_DOS, CH_UNIX, src, src_len, dest, dest_len); @@ -543,7 +549,13 @@ int pull_ucs2(const void *base_ptr, char *dest, const void *src, int dest_len, i if (src_len > 0) src_len--; } - if (src_len == -1 && (flags & STR_TERMINATE)) src_len = strlen_w(src)*2+2; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen_w(src)*2+2; + } else { + src_len = strnlen_w(src, src_len/2)*2+2; + } + } /* ucs2 is always a multiple of 2 bytes */ src_len &= ~1; @@ -609,7 +621,13 @@ int pull_utf8(char *dest, const void *src, int dest_len, int src_len, int flags) dest_len = sizeof(pstring); } - if (src_len == -1 && (flags & STR_TERMINATE)) src_len = strlen(src)+1; + if (flags & STR_TERMINATE) { + if (src_len == -1) { + src_len = strlen(src)+1; + } else { + src_len = strnlen(src, src_len) + 1; + } + } ret = convert_string(CH_UTF8, CH_UNIX, src, src_len, dest, dest_len); if (dest_len) dest[MIN(ret, dest_len-1)] = 0; diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index 6fdca658cd..9a841a36b3 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1001,3 +1001,15 @@ some platforms don't have strndup return ret; } #endif + +#ifndef HAVE_STRNLEN +/******************************************************************* +some platforms don't have strndup +********************************************************************/ + size_t strnlen(const char *s, size_t n) +{ + int i; + for (i=0; s[i] && i<n; i++) /* noop */ ; + return i; +} +#endif |