diff options
author | Andrew Tridgell <tridge@samba.org> | 2002-04-16 12:07:12 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2002-04-16 12:07:12 +0000 |
commit | b66932e1a5dc3a368474e6e110c5a88a251465f5 (patch) | |
tree | 3c8ed799fc19b11c24e8bdf57ae1b28724db4a23 | |
parent | 02f84c6bd0c06c3dacc93d6413d6645367f42744 (diff) | |
download | samba-b66932e1a5dc3a368474e6e110c5a88a251465f5.tar.gz samba-b66932e1a5dc3a368474e6e110c5a88a251465f5.tar.bz2 samba-b66932e1a5dc3a368474e6e110c5a88a251465f5.zip |
fixed the handling of STR_TERMINATE
(This used to be commit dbc6b137a83cf9fe0558625dd32f92f15296fba6)
-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 |