Copy the 3.2 version of string_replace to 3.0
authorVolker Lendecke <vl@samba.org>
Tue, 22 Jan 2008 10:54:31 +0000 (11:54 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 22 Jan 2008 10:59:09 +0000 (11:59 +0100)
There are several callers in 3.0 that don't give a pstring to string_replace,
thus it will end up in segfaults like the one reported by Sergio Pires
<suporte@grupovdl.com.br> on samba@samba.org. The 3.2 version of string_replace
does not have the pstring assumption anymore.

Jeremy, Jerry, please check!

Thanks,

Volker

source/lib/util_str.c

index 52cdbfceddc694ff95424a313e4c4c171ea0c960..b734495b835d745c219b27e9d0cc0dc8dd0f72c9 100644 (file)
@@ -394,7 +394,11 @@ BOOL strisnormal(const char *s, int case_default)
  NOTE: oldc and newc must be 7 bit characters
 **/
 
-void string_replace( pstring s, char oldc, char newc )
+/**
+ String replace.
+ NOTE: oldc and newc must be 7 bit characters
+**/
+void string_replace( char *s, char oldc, char newc )
 {
        char *p;
 
@@ -406,8 +410,9 @@ void string_replace( pstring s, char oldc, char newc )
        for (p = s; *p; p++) {
                if (*p & 0x80) /* mb string - slow path. */
                        break;
-               if (*p == oldc)
+               if (*p == oldc) {
                        *p = newc;
+               }
        }
 
        if (!*p)
@@ -418,9 +423,18 @@ void string_replace( pstring s, char oldc, char newc )
        /* 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);
+
+       while (*p) {
+               size_t c_size;
+               next_codepoint(p, &c_size);
+
+               if (c_size == 1) {
+                       if (*p == oldc) {
+                               *p = newc;
+                       }
+               }
+               p += c_size;
+       }
 }
 
 /**