svn commit: samba r23518 - in branches: SAMBA_3_0/source/lib SAMBA_3_0/source/smbd SAMBA_3_0_26/source/lib SAMBA_3_0_26/source/smbd

vlendec at samba.org vlendec at samba.org
Sat Jun 16 11:48:13 GMT 2007


Author: vlendec
Date: 2007-06-16 11:48:11 +0000 (Sat, 16 Jun 2007)
New Revision: 23518

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=23518

Log:
Remove the silly assumption that string_replace requires a pstring.

Jeremy, I am always very confused about the different length arguments
in convert_string and friends. Can you take a look at the change in
string_replace and verify it's ok? Thanks!

While at it, remove the pstring limit for strhasupper and strhaslower.


Modified:
   branches/SAMBA_3_0/source/lib/util_str.c
   branches/SAMBA_3_0/source/smbd/notify.c
   branches/SAMBA_3_0_26/source/lib/util_str.c
   branches/SAMBA_3_0_26/source/smbd/notify.c


Changeset:
Modified: branches/SAMBA_3_0/source/lib/util_str.c
===================================================================
--- branches/SAMBA_3_0/source/lib/util_str.c	2007-06-16 10:02:51 UTC (rev 23517)
+++ branches/SAMBA_3_0/source/lib/util_str.c	2007-06-16 11:48:11 UTC (rev 23518)
@@ -126,8 +126,6 @@
 	return ret;	
 }
 
-static uint16 tmpbuf[sizeof(pstring)];
-
 void set_first_token(char *ptr)
 {
 	last_ptr = ptr;
@@ -394,9 +392,11 @@
  NOTE: oldc and newc must be 7 bit characters
 **/
 
-void string_replace( pstring s, char oldc, char newc )
+void string_replace( char *s, char oldc, char newc )
 {
 	char *p;
+	smb_ucs2_t *tmp;
+	size_t src_len, len;
 
 	/* this is quite a common operation, so we want it to be
 	   fast. We optimise for the ascii case, knowing that all our
@@ -418,9 +418,14 @@
 	/* With compose characters we must restart from the beginning. JRA. */
 	p = s;
 #endif
-	push_ucs2(NULL, tmpbuf, p, sizeof(tmpbuf), STR_TERMINATE);
-	string_replace_w(tmpbuf, UCS2_CHAR(oldc), UCS2_CHAR(newc));
-	pull_ucs2(NULL, p, tmpbuf, -1, sizeof(tmpbuf), STR_TERMINATE);
+	src_len = strlen(p);
+	len = push_ucs2_allocate(&tmp, p);
+	if (len == -1) {
+		return;
+	}
+	string_replace_w(tmp, UCS2_CHAR(oldc), UCS2_CHAR(newc));
+	pull_ucs2(NULL, p, tmp, src_len+1, -1, STR_TERMINATE);
+	SAFE_FREE(tmp);
 }
 
 /**
@@ -584,12 +589,22 @@
 
 BOOL strhasupper(const char *s)
 {
-	smb_ucs2_t *ptr;
-	push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
-	for(ptr=tmpbuf;*ptr;ptr++)
-		if(isupper_w(*ptr))
-			return True;
-	return(False);
+	smb_ucs2_t *tmp, *p;
+	BOOL ret;
+
+	if (push_ucs2_allocate(&tmp, s) == -1) {
+		return False;
+	}
+
+	for(p = tmp; *p != 0; p++) {
+		if(isupper_w(*p)) {
+			break;
+		}
+	}
+
+	ret = (*p != 0);
+	SAFE_FREE(tmp);
+	return ret;
 }
 
 /**
@@ -598,12 +613,22 @@
 
 BOOL strhaslower(const char *s)
 {
-	smb_ucs2_t *ptr;
-	push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
-	for(ptr=tmpbuf;*ptr;ptr++)
-		if(islower_w(*ptr))
-			return True;
-	return(False);
+	smb_ucs2_t *tmp, *p;
+	BOOL ret;
+
+	if (push_ucs2_allocate(&tmp, s) == -1) {
+		return False;
+	}
+
+	for(p = tmp; *p != 0; p++) {
+		if(islower_w(*p)) {
+			break;
+		}
+	}
+
+	ret = (*p != 0);
+	SAFE_FREE(tmp);
+	return ret;
 }
 
 /**
@@ -2628,7 +2653,7 @@
 char *escape_shell_string(const char *src)
 {
 	size_t srclen = strlen(src);
-	char *ret = SMB_MALLOC((srclen * 2) + 1);
+	char *ret = SMB_MALLOC_ARRAY(char, (srclen * 2) + 1);
 	char *dest = ret;
 	BOOL in_s_quote = False;
 	BOOL in_d_quote = False;

Modified: branches/SAMBA_3_0/source/smbd/notify.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/notify.c	2007-06-16 10:02:51 UTC (rev 23517)
+++ branches/SAMBA_3_0/source/smbd/notify.c	2007-06-16 11:48:11 UTC (rev 23518)
@@ -328,7 +328,7 @@
 static void notify_fsp(files_struct *fsp, uint32 action, const char *name)
 {
 	struct notify_change *change, *changes;
-	pstring name2;
+	char *tmp;
 
 	if (fsp->notify == NULL) {
 		/*
@@ -337,9 +337,6 @@
 		return;
 	}
 
-	pstrcpy(name2, name);
-	string_replace(name2, '/', '\\');
-
 	/*
 	 * Someone has triggered a notify previously, queue the change for
 	 * later.
@@ -370,11 +367,14 @@
 
 	change = &(fsp->notify->changes[fsp->notify->num_changes]);
 
-	if (!(change->name = talloc_strdup(changes, name2))) {
+	if (!(tmp = talloc_strdup(changes, name))) {
 		DEBUG(0, ("talloc_strdup failed\n"));
 		return;
 	}
 
+	string_replace(tmp, '/', '\\');
+	change->name = tmp;	
+
 	change->action = action;
 	fsp->notify->num_changes += 1;
 

Modified: branches/SAMBA_3_0_26/source/lib/util_str.c
===================================================================
--- branches/SAMBA_3_0_26/source/lib/util_str.c	2007-06-16 10:02:51 UTC (rev 23517)
+++ branches/SAMBA_3_0_26/source/lib/util_str.c	2007-06-16 11:48:11 UTC (rev 23518)
@@ -126,8 +126,6 @@
 	return ret;	
 }
 
-static uint16 tmpbuf[sizeof(pstring)];
-
 void set_first_token(char *ptr)
 {
 	last_ptr = ptr;
@@ -397,6 +395,8 @@
 void string_replace( pstring s, char oldc, char newc )
 {
 	char *p;
+	smb_ucs2_t *tmp;
+	size_t len;
 
 	/* this is quite a common operation, so we want it to be
 	   fast. We optimise for the ascii case, knowing that all our
@@ -418,9 +418,13 @@
 	/* With compose characters we must restart from the beginning. JRA. */
 	p = s;
 #endif
-	push_ucs2(NULL, tmpbuf, p, sizeof(tmpbuf), STR_TERMINATE);
-	string_replace_w(tmpbuf, UCS2_CHAR(oldc), UCS2_CHAR(newc));
-	pull_ucs2(NULL, p, tmpbuf, -1, sizeof(tmpbuf), STR_TERMINATE);
+	len = push_ucs2_allocate(&tmp, p);
+	if (len == -1) {
+		return;
+	}
+	string_replace_w(tmp, UCS2_CHAR(oldc), UCS2_CHAR(newc));
+	pull_ucs2(NULL, p, tmp, len/2, -1, STR_TERMINATE);
+	SAFE_FREE(tmp);
 }
 
 /**
@@ -584,12 +588,22 @@
 
 BOOL strhasupper(const char *s)
 {
-	smb_ucs2_t *ptr;
-	push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
-	for(ptr=tmpbuf;*ptr;ptr++)
-		if(isupper_w(*ptr))
-			return True;
-	return(False);
+	smb_ucs2_t *tmp, *p;
+	BOOL ret;
+
+	if (push_ucs2_allocate(&tmp, s) == -1) {
+		return False;
+	}
+
+	for(p = tmp; *p != 0; p++) {
+		if(isupper_w(*p)) {
+			break;
+		}
+	}
+
+	ret = (*p != 0);
+	SAFE_FREE(tmp);
+	return ret;
 }
 
 /**
@@ -598,12 +612,22 @@
 
 BOOL strhaslower(const char *s)
 {
-	smb_ucs2_t *ptr;
-	push_ucs2(NULL, tmpbuf,s, sizeof(tmpbuf), STR_TERMINATE);
-	for(ptr=tmpbuf;*ptr;ptr++)
-		if(islower_w(*ptr))
-			return True;
-	return(False);
+	smb_ucs2_t *tmp, *p;
+	BOOL ret;
+
+	if (push_ucs2_allocate(&tmp, s) == -1) {
+		return False;
+	}
+
+	for(p = tmp; *p != 0; p++) {
+		if(islower_w(*p)) {
+			break;
+		}
+	}
+
+	ret = (*p != 0);
+	SAFE_FREE(tmp);
+	return ret;
 }
 
 /**
@@ -2628,7 +2652,7 @@
 char *escape_shell_string(const char *src)
 {
 	size_t srclen = strlen(src);
-	char *ret = SMB_MALLOC((srclen * 2) + 1);
+	char *ret = SMB_MALLOC_ARRAY(char, (srclen * 2) + 1);
 	char *dest = ret;
 	BOOL in_s_quote = False;
 	BOOL in_d_quote = False;

Modified: branches/SAMBA_3_0_26/source/smbd/notify.c
===================================================================
--- branches/SAMBA_3_0_26/source/smbd/notify.c	2007-06-16 10:02:51 UTC (rev 23517)
+++ branches/SAMBA_3_0_26/source/smbd/notify.c	2007-06-16 11:48:11 UTC (rev 23518)
@@ -327,7 +327,7 @@
 static void notify_fsp(files_struct *fsp, uint32 action, const char *name)
 {
 	struct notify_change *change, *changes;
-	pstring name2;
+	char *tmp;
 
 	if (fsp->notify == NULL) {
 		/*
@@ -336,9 +336,6 @@
 		return;
 	}
 
-	pstrcpy(name2, name);
-	string_replace(name2, '/', '\\');
-
 	/*
 	 * Someone has triggered a notify previously, queue the change for
 	 * later.
@@ -369,11 +366,14 @@
 
 	change = &(fsp->notify->changes[fsp->notify->num_changes]);
 
-	if (!(change->name = talloc_strdup(changes, name2))) {
+	if (!(tmp = talloc_strdup(changes, name))) {
 		DEBUG(0, ("talloc_strdup failed\n"));
 		return;
 	}
 
+	string_replace(tmp, '/', '\\');
+	change->name = tmp;	
+
 	change->action = action;
 	fsp->notify->num_changes += 1;
 



More information about the samba-cvs mailing list