]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
C26: use strchr_m/strrchr_m/strstr_m for multibyte-safe search
authorStefan Metzmacher <metze@samba.org>
Mon, 30 Mar 2026 15:17:47 +0000 (17:17 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 21 May 2026 17:25:33 +0000 (17:25 +0000)
Replace strchr/strrchr/strstr with their multibyte-aware
Samba equivalents where appropriate. These wrappers return
char * regardless of input constness.

Pair-Programmed-With: Andreas Schneider <asn@samba.org>

BUG: https://bugzilla.samba.org/show_bug.cgi?id=16006

Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
lib/printer_driver/printer_driver.c
nsswitch/libwbclient/tests/wbclient.c
source3/libsmb/libsmb_path.c
source3/rpc_server/rpc_host.c
source3/rpc_server/spoolss/srv_spoolss_nt.c
source3/utils/net_rpc.c
source4/nbt_server/wins/winsdb.c
source4/torture/krb5/kdc-canon-heimdal.c

index f04952eba64da3f256e0f2a8fbd23988ed62fa81..352b6f57ca050bc3592705896b835d76a3fb6ae7 100644 (file)
@@ -150,7 +150,7 @@ static NTSTATUS find_manufacturer_name(struct gp_inifile_context *ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       p = strchr(s, ':');
+       p = strchr_m(s, ':');
        if (p == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -205,7 +205,7 @@ static NTSTATUS find_manufacturer_url(struct gp_inifile_context *ctx,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       p = strchr(keys[0], ':');
+       p = strchr_m(keys[0], ':');
        if (p == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -300,7 +300,7 @@ static NTSTATUS add_dependent_driver_file(TALLOC_CTX *mem_ctx,
                file++;
        }
 
-       p = strchr(file, ',');
+       p = strchr_m(file, ',');
        if (p != NULL) {
                *p = '\0';
        }
@@ -392,7 +392,7 @@ static NTSTATUS enum_devices_in_toc(struct gp_inifile_context *ctx,
                                        return NT_STATUS_NO_MEMORY;
                                }
 
-                               p = strchr(s, ':');
+                               p = strchr_m(s, ':');
                                if (p == NULL) {
                                        return NT_STATUS_DRIVER_INTERNAL_ERROR;
                                }
@@ -506,7 +506,7 @@ static NTSTATUS process_driver_section_copyfiles(struct gp_inifile_context *ctx,
                status = gp_inifile_enum_section(ctx, str, &num_keys, &keys, &values);
                if (NT_STATUS_IS_OK(status)) {
                        for (i = 0; i < num_keys; i++) {
-                               p = strchr(keys[i], ':');
+                               p = strchr_m(keys[i], ':');
                                if (p == NULL) {
                                        return NT_STATUS_INVALID_PARAMETER;
                                }
@@ -584,7 +584,7 @@ static NTSTATUS process_driver_section_printprocessor(struct gp_inifile_context
        if (NT_STATUS_IS_OK(status)) {
                s = get_string_unquote(s);
 
-               p = strchr(s, ',');
+               p = strchr_m(s, ',');
                if (p == NULL) {
                        return NT_STATUS_INVALID_PARAMETER;
                }
@@ -883,7 +883,7 @@ static NTSTATUS process_driver_driverver(struct gp_inifile_context *ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       p = strchr(str, ',');
+       p = strchr_m(str, ',');
        if (p) {
                *p = '\0';
                p++;
index 7617adc56d49be4b8b55f2334fd04fa0d5b71ceb..25dfed7a2d97a4515b7a56c47c0a5aeb978cda03 100644 (file)
@@ -337,7 +337,7 @@ static bool test_wbc_users(struct torture_context *tctx)
                const char *user;
                char *c;
 
-               c = strchr(users[i], separator);
+               c = strchr_m(users[i], separator);
 
                if (c == NULL) {
                        /*
@@ -470,7 +470,7 @@ static bool test_wbc_groups(struct torture_context *tctx)
                const char *group;
                char *c;
 
-               c = strchr(groups[i], separator);
+               c = strchr_m(groups[i], separator);
 
                if (c == NULL) {
                        /*
index 12bfd21065cd0333ae62c2ecb7f77d9d169749f3..cc1b9ccfacc73cb829e830ed5224b0cf5b33d993 100644 (file)
@@ -267,7 +267,7 @@ SMBC_parse_path(TALLOC_CTX *ctx,
        p += 2;  /* Skip the double slash */
 
         /* See if any options were specified */
-        if ((q = strrchr(p, '?')) != NULL ) {
+        if ((q = strrchr_m(p, '?')) != NULL ) {
                 /* There are options.  Null terminate here and point to them */
                 *q++ = '\0';
 
index f9bd07524e14cbfc6c8176f2443e686c2793ccb8..5d1df962c88c5d779def4f7afd2978046f3421de 100644 (file)
@@ -314,7 +314,7 @@ static struct rpc_host_iface_name *rpc_exe_parse_iface_line(
                return NULL;
        }
 
-       name = strchr(line, ' ');
+       name = strchr_m(line, ' ');
        if (name == NULL) {
                return NULL;
        }
index e80092bec89bc950cc70f404910ded89922fc59e..00a17023ce517a08c74eeafa82f8718fcb07da5b 100644 (file)
@@ -10164,7 +10164,7 @@ WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
 
        /* check for OID in valuename */
 
-       oid_string = strchr(r->in.value_name, ',');
+       oid_string = strchr_m(r->in.value_name, ',');
        if (oid_string) {
                *oid_string = '\0';
                oid_string++;
index 99dde46bec54fbb0d8d35dd8105a2908fb1574d9..f19c57ac8675b6ce56558aed0874ef6bb111821b 100644 (file)
@@ -5044,7 +5044,7 @@ static bool get_user_tokens(struct net_context *c, int *num_tokens,
 
                fstrcpy(result[i].name, users[i]);
 
-               p = strchr(users[i], *lp_winbind_separator());
+               p = strchr_m(users[i], *lp_winbind_separator());
 
                DEBUG(3, ("%s\n", users[i]));
 
index 7df40c331352e2647e5ae6c7fbe234761a572e91..734e44400adb5518a4f5c93ce6c0196f4755d40d 100644 (file)
@@ -232,7 +232,7 @@ static NTSTATUS winsdb_addr_decode(struct winsdb_handle *h, struct winsdb_record
 
        address = (char *)val->data;
 
-       p = strchr(address, ';');
+       p = strchr_m(address, ';');
        if (!p) {
                /* support old entries, with only the address */
                addr->address           = (const char *)talloc_steal(addr, val->data);
@@ -258,7 +258,7 @@ static NTSTATUS winsdb_addr_decode(struct winsdb_handle *h, struct winsdb_record
                goto failed;
        }
        wins_owner = p + 10;
-       p = strchr(wins_owner, ';');
+       p = strchr_m(wins_owner, ';');
        if (!p) {
                status = NT_STATUS_INTERNAL_DB_CORRUPTION;
                goto failed;
@@ -280,7 +280,7 @@ static NTSTATUS winsdb_addr_decode(struct winsdb_handle *h, struct winsdb_record
        }
 
        expire_time = p + 11;
-       p = strchr(expire_time, ';');
+       p = strchr_m(expire_time, ';');
        if (!p) {
                status = NT_STATUS_INTERNAL_DB_CORRUPTION;
                goto failed;
index d05572bafb0399208cfab05e1ecd6d3400861f58..a7f35efb214631450b993229f2c9400ff115866f 100644 (file)
@@ -347,7 +347,7 @@ static bool torture_krb5_as_req_canon(struct torture_context *tctx, const void *
        if (test_data->upn) {
                char *p;
                test_data->username = talloc_strdup(test_data, upn);
-               p = strchr(test_data->username, '@');
+               p = strchr_m(test_data->username, '@');
                if (p) {
                        *p = '\0';
                        p++;