From: Stefan Metzmacher Date: Mon, 30 Mar 2026 15:17:47 +0000 (+0200) Subject: C26: use strchr_m/strrchr_m/strstr_m for multibyte-safe search X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=b5fd955ad5bf63b537076a9ef898c1954e767aad;p=thirdparty%2Fsamba.git C26: use strchr_m/strrchr_m/strstr_m for multibyte-safe search 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 BUG: https://bugzilla.samba.org/show_bug.cgi?id=16006 Signed-off-by: Andreas Schneider Signed-off-by: Stefan Metzmacher --- diff --git a/lib/printer_driver/printer_driver.c b/lib/printer_driver/printer_driver.c index f04952eba64..352b6f57ca0 100644 --- a/lib/printer_driver/printer_driver.c +++ b/lib/printer_driver/printer_driver.c @@ -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++; diff --git a/nsswitch/libwbclient/tests/wbclient.c b/nsswitch/libwbclient/tests/wbclient.c index 7617adc56d4..25dfed7a2d9 100644 --- a/nsswitch/libwbclient/tests/wbclient.c +++ b/nsswitch/libwbclient/tests/wbclient.c @@ -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) { /* diff --git a/source3/libsmb/libsmb_path.c b/source3/libsmb/libsmb_path.c index 12bfd21065c..cc1b9ccfacc 100644 --- a/source3/libsmb/libsmb_path.c +++ b/source3/libsmb/libsmb_path.c @@ -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'; diff --git a/source3/rpc_server/rpc_host.c b/source3/rpc_server/rpc_host.c index f9bd07524e1..5d1df962c88 100644 --- a/source3/rpc_server/rpc_host.c +++ b/source3/rpc_server/rpc_host.c @@ -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; } diff --git a/source3/rpc_server/spoolss/srv_spoolss_nt.c b/source3/rpc_server/spoolss/srv_spoolss_nt.c index e80092bec89..00a17023ce5 100644 --- a/source3/rpc_server/spoolss/srv_spoolss_nt.c +++ b/source3/rpc_server/spoolss/srv_spoolss_nt.c @@ -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++; diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c index 99dde46bec5..f19c57ac867 100644 --- a/source3/utils/net_rpc.c +++ b/source3/utils/net_rpc.c @@ -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])); diff --git a/source4/nbt_server/wins/winsdb.c b/source4/nbt_server/wins/winsdb.c index 7df40c33135..734e44400ad 100644 --- a/source4/nbt_server/wins/winsdb.c +++ b/source4/nbt_server/wins/winsdb.c @@ -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; diff --git a/source4/torture/krb5/kdc-canon-heimdal.c b/source4/torture/krb5/kdc-canon-heimdal.c index d05572bafb0..a7f35efb214 100644 --- a/source4/torture/krb5/kdc-canon-heimdal.c +++ b/source4/torture/krb5/kdc-canon-heimdal.c @@ -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++;