[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Wed Mar 30 12:59:02 MDT 2011


The branch, master has been updated
       via  d546ade Change convert_string_internal() and convert_string_error() to bool return.
       via  048471d Fix the nstring calls to use the correct sizes.
       via  c964744 This doesn't look like it has anything to do with character set conversion, but it does :-).
      from  8f4e39f s3: Fix g_lock_lock after the select/poll conversion

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit d546adeab54af123eff66cee61a487c88b6ba61b
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Mar 30 10:27:04 2011 -0700

    Change convert_string_internal() and convert_string_error() to bool return.
    
    Move closer to makeing all convert_string_XXX functions return bool.
    
    Autobuild-User: Jeremy Allison <jra at samba.org>
    Autobuild-Date: Wed Mar 30 20:58:10 CEST 2011 on sn-devel-104

commit 048471d14b3ed65fe83e8f225e03af925aaf0c47
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Mar 30 10:13:01 2011 -0700

    Fix the nstring calls to use the correct sizes.

commit c964744001cd231e585c5c5c9016becda145340b
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Mar 30 09:58:22 2011 -0700

    This doesn't look like it has anything to do with character set conversion, but it does :-).
    
    Turns out one of the *really* significant differences between
    convert_string() in source4 and source3, is that the one in
    source3 will return 0 for byte length converted when called
    with dest_len = 0 whereas the one in source4 returns (size_t)-1
    and sets errno to E2BIG.
    
    Allow the ndr_string code to cope with the (arguably correct)
    way that the source4 implementation works. This code only gets
    excercised in the print spooler tests, which aren't run in source4,
    which is why this bug has lasted for so long.
    
    You don't want to know how long it took me to find this :-).
    
    Jeremy.

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

Summary of changes:
 librpc/ndr/ndr_string.c |   17 +++++---
 source3/include/proto.h |    2 +-
 source3/lib/charcnv.c   |   97 ++++++++++++++++++++++------------------------
 source3/lib/fstring.c   |   18 +++++----
 4 files changed, 67 insertions(+), 67 deletions(-)


Changeset truncated at 500 lines:

diff --git a/librpc/ndr/ndr_string.c b/librpc/ndr/ndr_string.c
index 402cf4e..9cc26da 100644
--- a/librpc/ndr/ndr_string.c
+++ b/librpc/ndr/ndr_string.c
@@ -705,17 +705,20 @@ _PUBLIC_ enum ndr_err_code ndr_push_charset(struct ndr_push *ndr, int ndr_flags,
 	required = byte_mul * length;
 	
 	NDR_PUSH_NEED_BYTES(ndr, required);
-	ret = convert_string(CH_UNIX, chset, 
+
+	if (required) {
+		ret = convert_string(CH_UNIX, chset, 
 			     var, strlen(var),
 			     ndr->data+ndr->offset, required);
-	if (ret == -1) {
-		return ndr_push_error(ndr, NDR_ERR_CHARCNV, 
+		if (ret == -1) {
+			return ndr_push_error(ndr, NDR_ERR_CHARCNV, 
 				      "Bad character conversion");
-	}
+		}
 
-	/* Make sure the remaining part of the string is filled with zeroes */
-	if (ret < required) {
-		memset(ndr->data+ndr->offset+ret, 0, required-ret);
+		/* Make sure the remaining part of the string is filled with zeroes */
+		if (ret < required) {
+			memset(ndr->data+ndr->offset+ret, 0, required-ret);
+		}
 	}
 
 	ndr->offset += required;
diff --git a/source3/include/proto.h b/source3/include/proto.h
index c19e3a4..94c9245 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -77,7 +77,7 @@ void init_iconv(void);
 size_t convert_string(charset_t from, charset_t to,
 		      void const *src, size_t srclen, 
 		      void *dest, size_t destlen);
-size_t convert_string_error(charset_t from, charset_t to,
+bool convert_string_error(charset_t from, charset_t to,
 			    void const *src, size_t srclen,
 			    void *dest, size_t destlen,
 			    size_t *converted_size);
diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c
index 7468540..76fa968 100644
--- a/source3/lib/charcnv.c
+++ b/source3/lib/charcnv.c
@@ -80,13 +80,15 @@ void init_iconv(void)
  * @param srclen length of the source string in bytes
  * @param dest pointer to destination string (multibyte or singlebyte)
  * @param destlen maximal length allowed for string
- * @returns the number of bytes occupied in the destination
+ * @param converted size is the number of bytes occupied in the destination
+ *
+ * @returns false and sets errno on fail, true on success.
  *
  * Ensure the srclen contains the terminating zero.
  *
  **/
 
-static size_t convert_string_internal(charset_t from, charset_t to,
+static bool convert_string_internal(charset_t from, charset_t to,
 		      void const *src, size_t srclen, 
 		      void *dest, size_t destlen, size_t *converted_size)
 {
@@ -112,16 +114,18 @@ static size_t convert_string_internal(charset_t from, charset_t to,
 
 	if (descriptor == (smb_iconv_t)-1 || descriptor == (smb_iconv_t)0) {
 		errno = EINVAL;
-		return (size_t)-1;
+		return false;
 	}
 
 	i_len=srclen;
 	o_len=destlen;
 
 	retval = smb_iconv(descriptor, &inbuf, &i_len, &outbuf, &o_len);
-	if (converted_size != NULL)
-		*converted_size = destlen-o_len;
-	return retval;
+	if (retval == (size_t)-1) {
+		return false;
+	}
+	*converted_size = destlen-o_len;
+	return true;
 }
 
 /**
@@ -132,7 +136,9 @@ static size_t convert_string_internal(charset_t from, charset_t to,
  * @param srclen length of the source string in bytes, or -1 for nul terminated.
  * @param dest pointer to destination string (multibyte or singlebyte)
  * @param destlen maximal length allowed for string - *NEVER* -1.
- * @returns the number of bytes occupied in the destination
+ * @param converted size is the number of bytes occupied in the destination
+ *
+ * @returns false and sets errno on fail, true on success.
  *
  * Ensure the srclen contains the terminating zero.
  *
@@ -140,7 +146,7 @@ static size_t convert_string_internal(charset_t from, charset_t to,
  * Don't change unless you really know what you are doing. JRA.
  **/
 
-size_t convert_string_error(charset_t from, charset_t to,
+bool convert_string_error(charset_t from, charset_t to,
 			    void const *src, size_t srclen,
 			    void *dest, size_t destlen,
 			    size_t *converted_size)
@@ -155,13 +161,11 @@ size_t convert_string_error(charset_t from, charset_t to,
 	SMB_ASSERT(destlen != (size_t)-1);
 #endif
 
-	if (converted_size) {
+	if (srclen == 0) {
 		*converted_size = 0;
+		return true;
 	}
 
-	if (srclen == 0)
-		return 0;
-
 	if (from != CH_UTF16LE && from != CH_UTF16BE && to != CH_UTF16LE && to != CH_UTF16BE) {
 		const unsigned char *p = (const unsigned char *)src;
 		unsigned char *q = (unsigned char *)dest;
@@ -185,26 +189,24 @@ size_t convert_string_error(charset_t from, charset_t to,
 #ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
 				goto general_case;
 #else
-				size_t ret = convert_string_internal(from, to, p, slen, q, dlen, converted_size);
-				if (converted_size) {
-					*converted_size += retval;
-				}
+				bool ret = convert_string_internal(from, to, p, slen, q, dlen, converted_size);
+				*converted_size += retval;
 				return ret;
 #endif
 			}
 		}
-		if (converted_size) {
-			*converted_size = retval;
-		}
+
+		*converted_size = retval;
+
 		if (!dlen) {
 			/* Even if we fast path we should note if we ran out of room. */
 			if (((slen != (size_t)-1) && slen) ||
 					((slen == (size_t)-1) && lastp)) {
 				errno = E2BIG;
-				return (size_t)-1;
+				return false;
 			}
 		}
-		return retval;
+		return true;
 	} else if (from == CH_UTF16LE && to != CH_UTF16LE) {
 		const unsigned char *p = (const unsigned char *)src;
 		unsigned char *q = (unsigned char *)dest;
@@ -229,26 +231,24 @@ size_t convert_string_error(charset_t from, charset_t to,
 #ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
 				goto general_case;
 #else
-				size_t ret = convert_string_internal(from, to, p, slen, q, dlen, converted_size);
-				if (converted_size) {
-					*converted_size += retval;
-				}
+				bool ret = convert_string_internal(from, to, p, slen, q, dlen, converted_size);
+				*converted_size += retval;
 				return ret;
 #endif
 			}
 		}
-		if (converted_size) {
-			*converted_size = retval;
-		}
+
+		*converted_size = retval;
+
 		if (!dlen) {
 			/* Even if we fast path we should note if we ran out of room. */
 			if (((slen != (size_t)-1) && slen) ||
 					((slen == (size_t)-1) && lastp)) {
 				errno = E2BIG;
-				return (size_t)-1;
+				return false;
 			}
 		}
-		return retval;
+		return true;
 	} else if (from != CH_UTF16LE && from != CH_UTF16BE && to == CH_UTF16LE) {
 		const unsigned char *p = (const unsigned char *)src;
 		unsigned char *q = (unsigned char *)dest;
@@ -273,26 +273,24 @@ size_t convert_string_error(charset_t from, charset_t to,
 #ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
 				goto general_case;
 #else
-				size_t ret = convert_string_internal(from, to, p, slen, q, dlen, converted_size);
-				if (converted_size) {
-					*converted_size += retval;
-				}
+				bool ret = convert_string_internal(from, to, p, slen, q, dlen, converted_size);
+				*converted_size += retval;
 				return ret;
 #endif
 			}
 		}
-		if (converted_size) {
-			*converted_size = retval;
-		}
+
+		*converted_size = retval;
+
 		if (!dlen) {
 			/* Even if we fast path we should note if we ran out of room. */
 			if (((slen != (size_t)-1) && slen) ||
 					((slen == (size_t)-1) && lastp)) {
 				errno = E2BIG;
-				return (size_t)-1;
+				return false;
 			}
 		}
-		return retval;
+		return true;
 	}
 
 #ifdef BROKEN_UNICODE_COMPOSE_CHARACTERS
@@ -303,17 +301,19 @@ size_t convert_string_error(charset_t from, charset_t to,
 
 size_t convert_string(charset_t from, charset_t to,
 		      void const *src, size_t srclen,
-		      void *dest, size_t destlen) {
+		      void *dest, size_t destlen)
+{
 	size_t converted_size;
-	size_t retval = convert_string_error(from, to, src, srclen, dest, destlen, &converted_size);
-	if(retval==(size_t)-1) {
+	bool ret = convert_string_error(from, to, src, srclen, dest, destlen, &converted_size);
+
+	if(ret==false) {
 		const char *reason="unknown error";
 		switch(errno) {
 			case EINVAL:
 				reason="Incomplete multibyte sequence";
 				DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",
 					 reason, (const char *)src));
-				return (size_t)-1;
+				break;
 			case E2BIG:
 			{
 				struct smb_iconv_handle *ic;
@@ -336,15 +336,15 @@ size_t convert_string(charset_t from, charset_t to,
 				reason="Illegal multibyte sequence";
 				DEBUG(3,("convert_string_internal: Conversion error: %s(%s)\n",
 					 reason, (const char *)src));
-				return (size_t)-1;
+				break;
 			default:
 				DEBUG(0,("convert_string_internal: Conversion error: %s(%s)\n",
 					 reason, (const char *)src));
-				return (size_t)-1;
+				break;
 		}
 		/* smb_panic(reason); */
 	}
-	return converted_size;
+	return ret ? converted_size : (size_t)-1;
 }
 
 
@@ -380,11 +380,6 @@ bool convert_string_talloc(TALLOC_CTX *ctx, charset_t from, charset_t to,
 
 	*dest = NULL;
 
-	if (!converted_size) {
-		errno = EINVAL;
-		return false;
-	}
-
 	if (src == NULL || srclen == (size_t)-1) {
 		errno = EINVAL;
 		return false;
diff --git a/source3/lib/fstring.c b/source3/lib/fstring.c
index 9c13b8d..50b0765 100644
--- a/source3/lib/fstring.c
+++ b/source3/lib/fstring.c
@@ -35,17 +35,19 @@ size_t push_ascii_fstring(void *dest, const char *src)
  this function uses convert_string_error() to avoid common debug
  warnings where is unable to convert strings to CH_DOS. The target
  string is truncated at the first character that cannot be converted
- The target is always null terminated. The resulting string size,
- without the null termination, it returned
+ The target is always null terminated.
 ********************************************************************/
 
 size_t push_ascii_nstring(void *dest, const char *src)
 {
-	ssize_t ret;
-	size_t converted_size;
-	ret = convert_string_error(CH_UNIX, CH_DOS, src, -1, dest, sizeof(nstring)-1, &converted_size);
-	SCVAL(dest, converted_size, 0);
-	return converted_size;
+	size_t converted_size = 0;
+	bool ret = convert_string_error(CH_UNIX, CH_DOS, src, -1, dest, sizeof(nstring), &converted_size);
+	if (ret) {
+		SCVAL(dest, sizeof(nstring)-1, 0);
+	} else {
+		SCVAL(dest, 0, 0);
+	}
+	return ret ? converted_size : (size_t)-1;
 }
 
 size_t pull_ascii_fstring(char *dest, const void *src)
@@ -57,7 +59,7 @@ size_t pull_ascii_fstring(char *dest, const void *src)
 
 size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src)
 {
-	return pull_ascii(dest, src, dest_len, sizeof(nstring)-1, STR_TERMINATE);
+	return pull_ascii(dest, src, dest_len, sizeof(nstring), STR_TERMINATE);
 }
 
 /**


-- 
Samba Shared Repository


More information about the samba-cvs mailing list