]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
C26: add explicit casts where const must be stripped for mutation
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)
For cases where code intentionally writes through a pointer returned by
strchr/strrchr/strstr, add explicit discard_const_p casts or adjust variable
types to non-const to make the mutability intent clear.

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>
36 files changed:
auth/credentials/credentials.c
examples/libsmbclient/testacl.c
lib/printer_driver/printer_driver.c
lib/tdb/tools/tdbtool.c
lib/util/charset/util_str.c
libcli/nbt/nbtname.c
nsswitch/libwbclient/tests/wbclient.c
nsswitch/libwbclient/wbc_sid.c
source3/auth/auth_util.c
source3/lib/netapi/examples/common.c
source3/lib/netapi/tests/common.c
source3/libads/kerberos_keytab.c
source3/libads/util.c
source3/libsmb/libsmb_path.c
source3/printing/nt_printing_migrate.c
source3/printing/print_iprint.c
source3/rpc_server/fss/srv_fss_agent.c
source3/rpc_server/ntsvcs/srv_ntsvcs_nt.c
source3/rpc_server/rpc_host.c
source3/rpc_server/spoolss/srv_spoolss_nt.c
source3/smbd/mangle_hash.c
source3/smbd/msdfs.c
source3/torture/torture.c
source3/utils/net_lookup.c
source3/utils/net_rpc.c
source3/winbindd/idmap_nss.c
source3/winbindd/idmap_tdb.c
source4/client/client.c
source4/dsdb/samdb/ldb_modules/encrypted_secrets.c
source4/lib/socket/interface.c
source4/nbt_server/wins/winsdb.c
source4/ntvfs/posix/pvfs_resolve.c
source4/torture/krb5/kdc-canon-heimdal.c
source4/torture/krb5/kdc-canon-mit.c
source4/torture/rpc/spoolss.c
source4/torture/smbtorture.c

index 63efdcd43cc1065da13fadfc5f0ae5ae270ac179..ef2952f5c89735ad0bc3c4bc388b351e73f561f6 100644 (file)
@@ -1439,13 +1439,16 @@ _PUBLIC_ bool cli_credentials_guess(struct cli_credentials *cred,
                size_t len = strlen(env);
 
                if (len > 0 && len <= 1024) {
-                       char *p = NULL;
+                       const char *p = NULL;
 
                        (void)cli_credentials_parse_string(cred,
                                                           env,
                                                           CRED_GUESS_ENV);
-                       if ((p = strchr_m(env, '%'))) {
-                               memset(p, '\0', strlen(cred->password));
+                       p = strchr_m(env, '%');
+                       if (p != NULL) {
+                               memset(discard_const_p(char, p),
+                                      '\0',
+                                      strlen(cred->password));
                        }
                }
        }
index 89d766d50642db183522e9b78d5cd0af6c3cf1db..656eb64f954b15b639555661636dce046b538e25 100644 (file)
@@ -297,7 +297,7 @@ int main(int argc, const char *argv[])
                debugstr = "set attributes";
 
        do_set:
-               if ((p = strchr(the_acl, ':')) == NULL)
+               if ((p = (char *)(uintptr_t)strchr(the_acl, ':')) == NULL)
                {
                        printf("Missing value.  ACL must be name:value pair\n");
                        return 1;
index 352b6f57ca050bc3592705896b835d76a3fb6ae7..b13d44c7f98bea7eac45a4d290377bdc9a50b344 100644 (file)
@@ -150,7 +150,7 @@ static NTSTATUS find_manufacturer_name(struct gp_inifile_context *ctx,
                return NT_STATUS_NO_MEMORY;
        }
 
-       p = strchr_m(s, ':');
+       p = discard_const_p(char, 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_m(keys[0], ':');
+       p = discard_const_p(char, 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_m(file, ',');
+       p = discard_const_p(char, 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_m(s, ':');
+                               p = discard_const_p(char, 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_m(keys[i], ':');
+                               p = discard_const_p(char, 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_m(s, ',');
+               p = discard_const_p(char, 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_m(str, ',');
+       p = discard_const_p(char, strchr_m(str, ','));
        if (p) {
                *p = '\0';
                p++;
index 6f2dcd19a0bd6f166d9de27a7614c5041bb7783b..2a05f7dbe012e0459c098ebb8f06d754df956a93 100644 (file)
@@ -903,7 +903,7 @@ int main(int argc, char *argv[])
                /* Interactive mode */
                while ((cmdname = tdb_getline("tdb> "))) {
                        arg2 = arg1 = NULL;
-                       if ((arg1 = strchr((const char *)cmdname,' ')) != NULL) {
+                       if ((arg1 = strchr(discard_const_p(char, cmdname),' ')) != NULL) {
                                arg1++;
                                arg2 = arg1;
                                while (*arg2) {
index c214cb1a796955545391bf2a17e9e8bde98e41b2..34789c617bd61ab5385a8db6cd2fc3b62a9bd0f5 100644 (file)
@@ -367,7 +367,8 @@ _PUBLIC_ const char *strchr_m_const(const char *src, char c)
        /* characters below 0x3F are guaranteed to not appear in
           non-initial position in multi-byte charsets */
        if ((c & 0xC0) == 0) {
-               return strchr(src, c);
+               s = strchr(src, c);
+               return discard_const_p(char, s);
        }
 
        /* this is quite a common operation, so we want it to be
@@ -417,7 +418,8 @@ _PUBLIC_ const char *strrchr_m_const(const char *s, char c)
        /* characters below 0x3F are guaranteed to not appear in
           non-initial position in multi-byte charsets */
        if ((c & 0xC0) == 0) {
-               return strrchr(s, c);
+               const char *t = strrchr(s, c);
+               return discard_const_p(char, t);
        }
 
        /* this is quite a common operation, so we want it to be
index a2b0d346c265fd501d0b753eb0635502a63a8969..c751aa268f61722302319fbd36371d1c3ce652eb 100644 (file)
@@ -108,7 +108,7 @@ static uint8_t *compress_name(TALLOC_CTX *mem_ctx,
 */
 _PUBLIC_ enum ndr_err_code ndr_pull_nbt_name(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct nbt_name *r)
 {
-       uint8_t *scope;
+       char *scope;
        char *cname;
        const char *s;
        bool ok;
@@ -118,18 +118,17 @@ _PUBLIC_ enum ndr_err_code ndr_pull_nbt_name(struct ndr_pull *ndr, ndr_flags_typ
        }
 
        NDR_CHECK(ndr_pull_nbt_string(ndr, ndr_flags, &s));
+       cname = discard_const_p(char, s);
 
-       scope = (uint8_t *)strchr(s, '.');
+       scope = strchr(cname, '.');
        if (scope) {
                *scope = 0;
-               r->scope = talloc_strdup(ndr->current_mem_ctx, (const char *)&scope[1]);
+               r->scope = talloc_strdup(ndr->current_mem_ctx, &scope[1]);
                NDR_ERR_HAVE_NO_MEMORY(r->scope);
        } else {
                r->scope = NULL;
        }
 
-       cname = discard_const_p(char, s);
-
        /* the first component is limited to 16 bytes in the DOS charset,
           which is 32 in the 'compressed' form */
        if (strlen(cname) > 32) {
index 25dfed7a2d97a4515b7a56c47c0a5aeb978cda03..982e4de08bd374acb62b2c8e0df2c9fc1ee14c75 100644 (file)
@@ -337,7 +337,7 @@ static bool test_wbc_users(struct torture_context *tctx)
                const char *user;
                char *c;
 
-               c = strchr_m(users[i], separator);
+               c = discard_const_p(char, 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_m(groups[i], separator);
+               c = discard_const_p(char, strchr_m(groups[i], separator));
 
                if (c == NULL) {
                        /*
index 72173cfbb644c68e91aaf16cb6ab28f3deb8da65..50f3f241f2861d7d2ffc65f9b5d949109cf3f0fb 100644 (file)
@@ -674,7 +674,7 @@ wbcErr wbcCtxLookupUserSids(struct wbcContext *ctx,
                            struct wbcDomainSid **_sids)
 {
        uint32_t i;
-       const char *s;
+       char *s = NULL;
        struct winbindd_request request;
        struct winbindd_response response;
        struct wbcDomainSid *sids = NULL;
@@ -715,7 +715,7 @@ wbcErr wbcCtxLookupUserSids(struct wbcContext *ctx,
                NULL);
        BAIL_ON_PTR_ERROR(sids, wbc_status);
 
-       s = (const char *)response.extra_data.data;
+       s = (char *)response.extra_data.data;
        for (i = 0; i < response.data.num_entries; i++) {
                char *n = strchr(s, '\n');
                if (n) {
@@ -771,7 +771,7 @@ wbcErr wbcCtxGetSidAliases(struct wbcContext *ctx,
                           uint32_t *num_alias_rids)
 {
        uint32_t i;
-       const char *s;
+       char *s = NULL;
        struct winbindd_request request;
        struct winbindd_response response;
        ssize_t extra_data_len = 0;
@@ -846,7 +846,7 @@ wbcErr wbcCtxGetSidAliases(struct wbcContext *ctx,
                                             sizeof(uint32_t), NULL);
        BAIL_ON_PTR_ERROR(rids, wbc_status);
 
-       s = (const char *)response.extra_data.data;
+       s = (char *)response.extra_data.data;
        for (i = 0; i < response.data.num_entries; i++) {
                char *n = strchr(s, '\n');
                if (n) {
@@ -895,7 +895,7 @@ wbcErr wbcCtxListUsers(struct wbcContext *ctx,
        struct winbindd_response response;
        uint32_t num_users = 0;
        const char **users = NULL;
-       const char *next;
+       char *next = NULL;
 
        /* Initialise request */
 
@@ -919,10 +919,10 @@ wbcErr wbcCtxListUsers(struct wbcContext *ctx,
 
        /* Look through extra data */
 
-       next = (const char *)response.extra_data.data;
+       next = (char *)response.extra_data.data;
        while (next) {
-               const char *current;
-               char *k;
+               char *current = NULL;
+               char *k = NULL;
 
                if (num_users >= response.data.num_entries) {
                        wbc_status = WBC_ERR_INVALID_RESPONSE;
@@ -979,7 +979,7 @@ wbcErr wbcCtxListGroups(struct wbcContext *ctx,
        struct winbindd_response response;
        uint32_t num_groups = 0;
        const char **groups = NULL;
-       const char *next;
+       char *next = NULL;
 
        /* Initialise request */
 
@@ -1003,10 +1003,10 @@ wbcErr wbcCtxListGroups(struct wbcContext *ctx,
 
        /* Look through extra data */
 
-       next = (const char *)response.extra_data.data;
+       next = (char *)response.extra_data.data;
        while (next) {
-               const char *current;
-               char *k;
+               char *current = NULL;
+               char *k = NULL;
 
                if (num_groups >= response.data.num_entries) {
                        wbc_status = WBC_ERR_INVALID_RESPONSE;
index b0d879956daf168009c3a0a125f001719a964ba2..3c0baaf9d8c1a0adcebb2488614fef953ace2228 100644 (file)
@@ -1976,7 +1976,7 @@ struct passwd *smb_getpwnam( TALLOC_CTX *mem_ctx, const char *domuser,
                return NULL;
        }
 
-       p = strchr_m( username, *lp_winbind_separator() );
+       p = discard_const_p(char, strchr_m(username, *lp_winbind_separator()));
 
        /* code for a DOMAIN\user string */
 
index 3e5664424ef964c0009f79a2eab1357522d1b93a..cb6cf82625325ad152e8ed3b26b076905b6cae45 100644 (file)
@@ -42,12 +42,15 @@ void popt_common_callback(poptContext con,
                        char *p = NULL;
 
                        if ((p = strchr(puser,'%'))) {
+                               const char *cp = NULL;
                                size_t len;
                                *p = 0;
                                libnetapi_set_username(ctx, puser);
                                libnetapi_set_password(ctx, p+1);
                                len = strlen(p+1);
-                               memset(strchr(arg,'%')+1,'X',len);
+                               cp = strchr(arg, '%');
+                               p = (char *)(uintptr_t)(const void *)cp;
+                               memset(p+1,'X',len);
                        } else {
                                libnetapi_set_username(ctx, puser);
                        }
index a01a8704bb2aecbb4ac61b26fc0bebd5bd0404e8..8d25f0be58c432b5151ddbcfc6214f382bdfb118 100644 (file)
@@ -51,12 +51,15 @@ void popt_common_callback(poptContext con,
                        char *p = NULL;
 
                        if ((p = strchr(puser,'%'))) {
+                               const char *cp = NULL;
                                size_t len;
                                *p = 0;
                                libnetapi_set_username(ctx, puser);
                                libnetapi_set_password(ctx, p+1);
                                len = strlen(p+1);
-                               memset(strchr(arg,'%')+1,'X',len);
+                               cp = strchr(arg, '%');
+                               p = (char *)(uintptr_t)(const void *)cp;
+                               memset(p+1,'X',len);
                        } else {
                                libnetapi_set_username(ctx, puser);
                        }
index 364d8421bda4cf91420c3233186c769e233f56b4..20cb21e2e9364731087a9518f28ef566cd87499e 100644 (file)
@@ -153,7 +153,7 @@ static ADS_STATUS pw2kt_scan_spec(TALLOC_CTX *ctx,
                return ADS_SUCCESS;
        }
 
-       vals = strchr_m(option, '=');
+       vals = discard_const_p(char, strchr_m(option, '='));
        if (vals != NULL) {
                *vals = 0;
                vals++;
index 360e556ab9bbf7756307095653e21f977e27f0c7..d770b9f6e2af388895d829b855e7da7b431422dd 100644 (file)
@@ -189,7 +189,7 @@ struct spn_struct *parse_spn(TALLOC_CTX *ctx, const char *srvprinc)
        }
        result->port = -1;
 
-       tmp = strchr_m(result->serviceclass, '/');
+       tmp = discard_const_p(char, strchr_m(result->serviceclass, '/'));
        if (tmp == NULL) {
                /* illegal */
                DBG_ERR("Failed to parse spn %s, no host definition\n",
index cc1b9ccfacc73cb829e830ed5224b0cf5b33d993..e15aac6878a00132f015e1ed013446a3822214d8 100644 (file)
@@ -267,7 +267,8 @@ SMBC_parse_path(TALLOC_CTX *ctx,
        p += 2;  /* Skip the double slash */
 
         /* See if any options were specified */
-        if ((q = strrchr_m(p, '?')) != NULL ) {
+        q = discard_const_p(char, strrchr_m(p, '?'));
+        if (q != NULL) {
                 /* There are options.  Null terminate here and point to them */
                 *q++ = '\0';
 
@@ -301,8 +302,8 @@ SMBC_parse_path(TALLOC_CTX *ctx,
         */
 
        /* check that '@' occurs before '/', if '/' exists at all */
-       q = strchr_m(p, '@');
-       r = strchr_m(p, '/');
+       q = discard_const_p(char, strchr_m(p, '@'));
+       r = discard_const_p(char, strchr_m(p, '/'));
        if (q && (!r || q < r)) {
                char *userinfo = NULL;
                const char *u;
index f56aa702bf16308a40e484436c0518614d77b3f5..c6c8b242777469ac92ac1f93dcfe99d8832b2ef9 100644 (file)
@@ -307,13 +307,13 @@ NTSTATUS printing_tdb_migrate_printer(TALLOC_CTX *mem_ctx,
        /* migrate printerdata */
        for (j = 0; j < r.count; j++) {
                char *valuename;
-               const char *keyname;
+               char *keyname;
 
                if (r.printer_data[j].type == REG_NONE) {
                        continue;
                }
 
-               keyname = r.printer_data[j].name;
+               keyname = discard_const_p(char, r.printer_data[j].name);
                valuename = strchr(keyname, '\\');
                if (valuename == NULL) {
                        continue;
index 52649d94e4b58a37d2befd81c29e99dd3004703b..05539aa1a9c7a0bee8ddb3227341d4658e9971a9 100644 (file)
@@ -186,7 +186,8 @@ static int iprint_get_server_version(http_t *http, char* serviceUri)
                if ((os = strstr(ippGetString(attr, 0, NULL),
                                   NOVELL_SERVER_SYSNAME)) != NULL) {
                        os += strlen(NOVELL_SERVER_SYSNAME);
-                       if ((temp = strchr(os,'<')) != NULL)
+                       temp = discard_const_p(char, os);
+                       if ((temp = strchr(temp,'<')) != NULL)
                                *temp = '\0';
                        if (strcmp(os,NOVELL_SERVER_SYSNAME_NETWARE))
                                osFlag = 1; /* 1 for non-NetWare systems */
index 41e99bd93ece2a50be7dd53eb8db0643a572e6e9..55e18ffee53deff2d236e408b6a82ecee9aa7f93 100644 (file)
@@ -100,7 +100,7 @@ static NTSTATUS fss_unc_parse(TALLOC_CTX *mem_ctx,
                return NT_STATUS_INVALID_PARAMETER;
        }
 
-       s = strstr_m(unc, "\\\\");
+       s = discard_const_p(char, strstr_m(unc, "\\\\"));
        if (s == NULL) {
                return NT_STATUS_INVALID_PARAMETER;
        }
index cfa2336afd921686175981aaaec6dcf8571a0a12..c007c47bbe2eaabf1725962385f37e22fd343eb8 100644 (file)
@@ -140,12 +140,16 @@ WERROR _PNP_GetDeviceRegProp(struct pipes_struct *p,
 
                /* just parse the service name from the device path and then
                   lookup the display name */
-               if ( !(ptr = strrchr_m( r->in.devicepath, '\\' )) )
+               ptr = discard_const_p(char, strrchr_m(r->in.devicepath, '\\'));
+               if (ptr == NULL) {
                        return WERR_GEN_FAILURE;
+               }
                *ptr = '\0';
 
-               if ( !(ptr = strrchr_m( r->in.devicepath, '_' )) )
+               ptr = discard_const_p(char, strrchr_m(r->in.devicepath, '_'));
+               if (ptr == NULL) {
                        return WERR_GEN_FAILURE;
+               }
                ptr++;
 
                mem_ctx = talloc_stackframe();
index 5d1df962c88c5d779def4f7afd2978046f3421de..29d5cb2342c10bbb8e7b8abc4b81e10f7d9cb9b3 100644 (file)
@@ -314,7 +314,7 @@ static struct rpc_host_iface_name *rpc_exe_parse_iface_line(
                return NULL;
        }
 
-       name = strchr_m(line, ' ');
+       name = discard_const_p(char, strchr_m(line, ' '));
        if (name == NULL) {
                return NULL;
        }
index 00a17023ce517a08c74eeafa82f8718fcb07da5b..fb11107929823365221901fe3e72b60714d8b282 100644 (file)
@@ -561,7 +561,8 @@ static WERROR set_printer_hnd_name(TALLOC_CTX *mem_ctx,
        aprinter = discard_const_p(char, handlename);
        if ( *handlename == '\\' ) {
                servername = canon_servername(handlename);
-               if ( (aprinter = strchr_m( servername, '\\' )) != NULL ) {
+               aprinter = discard_const_p(char, strchr_m(servername, '\\'));
+               if (aprinter != NULL) {
                        *aprinter = '\0';
                        aprinter++;
                }
@@ -10164,7 +10165,7 @@ WERROR _spoolss_SetPrinterDataEx(struct pipes_struct *p,
 
        /* check for OID in valuename */
 
-       oid_string = strchr_m(r->in.value_name, ',');
+       oid_string = discard_const_p(char, strchr_m(r->in.value_name, ','));
        if (oid_string) {
                *oid_string = '\0';
                oid_string++;
index f3c87df97f757d7342ffe632712ec9f924f55fb6..7fdf72be6799e7702b8b424d7823aed9c5aa48b2 100644 (file)
@@ -802,7 +802,8 @@ static void cache_mangled_name( const char mangled_name[13],
        TDB_DATA data_val;
        char mangled_name_key[13];
        char *s1 = NULL;
-       char *s2 = NULL;
+       const char *s2 = NULL;
+       char *tmp_non_const_dot = NULL;
 
        /* If the cache isn't initialized, give up. */
        if( !tdb_mangled_cache )
@@ -829,7 +830,8 @@ static void cache_mangled_name( const char mangled_name[13],
                         * put it back once we've used it.
                         * JRA
                         */
-                       *s2 = '\0';
+                       tmp_non_const_dot = discard_const_p(char, s2);
+                       *tmp_non_const_dot = '\0';
                }
        }
 
@@ -841,8 +843,8 @@ static void cache_mangled_name( const char mangled_name[13],
                DEBUG(5,("cache_mangled_name: Stored entry %s -> %s\n", mangled_name_key, raw_name));
        }
        /* Restore the change we made to the const string. */
-       if (s2) {
-               *s2 = '.';
+       if (tmp_non_const_dot != NULL) {
+               *tmp_non_const_dot = '.';
        }
 }
 
index 5b5f38f846a5136e50c82cd64a89246db20b4dc4..ca50a285bd7fc5f8a6875d9f1abf631c176e82e5 100644 (file)
@@ -71,7 +71,7 @@ NTSTATUS parse_dfs_path_strict(TALLOC_CTX *ctx,
        char *pathname_local = NULL;
        char *p = NULL;
        const char *hostname = NULL;
-       const char *servicename = NULL;
+       char *servicename = NULL;
        const char *reqpath = NULL;
        bool my_hostname = false;
        NTSTATUS status;
index c6d4c23ef1845cf26a00b7de3aa0a0445798bb9c..31d43afbfa46e0ba6e540f355be456e1333e22a0 100644 (file)
@@ -14129,7 +14129,7 @@ static NTSTATUS split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
 
        DEBUG(10, ("split_ntfs_stream_name called for [%s]\n", fname));
 
-       sname = strchr_m(fname, ':');
+       sname = discard_const_p(char, strchr_m(fname, ':'));
 
        if (sname == NULL) {
                if (pbase != NULL) {
index 570135a44358c22cff5b71dd51ba663a7290a77c..9211fa4a79707bb9b06bfce70b511d4c9fa3432e 100644 (file)
@@ -55,7 +55,7 @@ static int net_lookup_host(struct net_context *c, int argc, const char **argv)
        if (argc == 0)
                return net_lookup_usage(c, argc, argv);
 
-       p = strchr_m(name,'#');
+       p = discard_const_p(char, strchr_m(name, '#'));
        if (p) {
                *p = '\0';
                sscanf(++p,"%x",&name_type);
index f19c57ac8675b6ce56558aed0874ef6bb111821b..3b539c6b4beece92cd86d7a8ac14675222496727 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_m(users[i], *lp_winbind_separator());
+               p = discard_const_p(char, strchr_m(users[i], *lp_winbind_separator()));
 
                DEBUG(3, ("%s\n", users[i]));
 
index 0af2536221906396e64f38955e7b9c2258bf8499..7aef463342050738935f60dec402717a685448bf 100644 (file)
@@ -198,7 +198,7 @@ static NTSTATUS idmap_nss_unixids_to_sids(struct idmap_domain *dom, struct id_ma
        for (i = 0; ids[i]; i++) {
                struct passwd *pw;
                struct group *gr;
-               const char *name;
+               char *name;
                struct dom_sid sid;
                enum lsa_SidType type;
 
index f2b7672939c79300121fdf42b54d362d7f0395b8..3cef7586fd603b94697a8cb682a0df46fa7c916a 100644 (file)
@@ -75,7 +75,7 @@ static int convert_fn(struct db_record *rec, void *private_data)
 
        DEBUG(10,("Converting %s\n", (const char *)key.dptr));
 
-       p = strchr((const char *)key.dptr, '/');
+       p = strchr((char *)key.dptr, '/');
        if (!p)
                return 0;
 
index 5047abc46c8fce1b5d573d0a201fd107a92ce58b..09dd4ec2a825ab52dfd2bf36a071727aaf9d3f0a 100644 (file)
@@ -3510,10 +3510,13 @@ int main(int argc, char *argv[])
 
        DEBUG( 3, ( "Client started (version %s).\n", SAMBA_VERSION_STRING ) );
 
-       if (query_host && (p=strchr_m(query_host,'#'))) {
-               *p = 0;
-               p++;
-               sscanf(p, "%x", &name_type);
+       if (query_host) {
+               p = discard_const_p(char, strchr_m(query_host, '#'));
+               if (p) {
+                       *p = 0;
+                       p++;
+                       sscanf(p, "%x", &name_type);
+               }
        }
 
        if (query_host) {
index 1f04389d55a644f5650cfd36cae4246c0a859ab4..c4bf381bcd2efe86cd1036dfd57a698f04873273 100644 (file)
@@ -94,7 +94,7 @@ static const char* get_key_directory(TALLOC_CTX *ctx, struct ldb_context *ldb)
 {
 
        const char *sam_ldb_path = NULL;
-       const char *private_dir  = NULL;
+       char *private_dir  = NULL;
        char *p = NULL;
 
 
index 4899ef69b9f8f5f70dc486cf41840963e4600b45..a8848520fc95808d93f4a3423d7bca745611bdd5 100644 (file)
@@ -176,7 +176,7 @@ static void interpret_interface(TALLOC_CTX *mem_ctx,
                return;
        }
 
-       p = strchr_m(token, ';');
+       p = discard_const_p(char, strchr_m(token, ';'));
        if (p != NULL) {
                /*
                 * skip smbd-specific extra data:
@@ -186,7 +186,7 @@ static void interpret_interface(TALLOC_CTX *mem_ctx,
        }
 
        /* maybe it is a DNS name */
-       p = strchr_m(token,'/');
+       p = discard_const_p(char, strchr_m(token, '/'));
        if (p == NULL) {
                if (!interpret_string_addr(&ss, token, 0)) {
                        DEBUG(2, ("interpret_interface: Can't find address "
index 734e44400adb5518a4f5c93ce6c0196f4755d40d..866ad9b5bda9cae0d9177facb56de5f3b87dbf1a 100644 (file)
@@ -232,7 +232,7 @@ static NTSTATUS winsdb_addr_decode(struct winsdb_handle *h, struct winsdb_record
 
        address = (char *)val->data;
 
-       p = strchr_m(address, ';');
+       p = discard_const_p(char, 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_m(wins_owner, ';');
+       p = discard_const_p(char, 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_m(expire_time, ';');
+       p = discard_const_p(char, strchr_m(expire_time, ';'));
        if (!p) {
                status = NT_STATUS_INTERNAL_DB_CORRUPTION;
                goto failed;
index fbd8c7de1f5d37b8ab092918cac486abd666e04d..841abfd7356ab56ff95a046f5393669eb33dcef8 100644 (file)
@@ -721,7 +721,7 @@ NTSTATUS pvfs_resolve_name_handle(struct pvfs_state *pvfs,
                                char *delim;
                                char *full_name = discard_const_p(char, name);
 
-                               delim = strrchr(name, '/');
+                               delim = strrchr(full_name, '/');
                                if (!delim) {
                                        talloc_free(lck);
                                        return NT_STATUS_INTERNAL_ERROR;
index a7f35efb214631450b993229f2c9400ff115866f..bc92b4e5751d32bc25f677a06b21d5bc5ab234f3 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_m(test_data->username, '@');
+               p = discard_const_p(char, strchr_m(test_data->username, '@'));
                if (p) {
                        *p = '\0';
                        p++;
@@ -391,7 +391,7 @@ static bool torture_krb5_as_req_canon(struct torture_context *tctx, const void *
        if (test_data->removedollar) {
                char *p;
 
-               p = strchr_m(test_data->username, '$');
+               p = discard_const_p(char, strchr_m(test_data->username, '$'));
                torture_assert(tctx, p != NULL, talloc_asprintf(tctx,
                               "username[%s] contains no '$'\n",
                               test_data->username));
index e37684fb6e4908612b5cbab53e6714652a0a6ac8..9f3fd441495cd0274ecb2f377a31859cb029ca81 100644 (file)
@@ -293,7 +293,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 = discard_const_p(char, strchr(test_data->username, '@'));
                if (p) {
                        *p = '\0';
                        p++;
@@ -337,7 +337,7 @@ static bool torture_krb5_as_req_canon(struct torture_context *tctx, const void *
        if (test_data->removedollar) {
                char *p;
 
-               p = strchr_m(test_data->username, '$');
+               p = discard_const_p(char, strchr_m(test_data->username, '$'));
                torture_assert(tctx, p != NULL, talloc_asprintf(tctx,
                               "username[%s] contains no '$'\n",
                               test_data->username));
index 113a302e136a2f66a377b8c086a500eb18d884fd..63b84e3311183e9153df0529396a76b93feef43b 100644 (file)
@@ -5462,7 +5462,7 @@ static bool test_SetPrinterDataEx_keys(struct torture_context *tctx,
        for (i=0; i < ARRAY_SIZE(keys); i++) {
 
                char *c;
-               const char *key;
+               char *key;
                enum winreg_Type type;
                DATA_BLOB blob_in, blob_out;
                const char **subkeys;
index 2aa1acdabab16da876a9f34fc6356e3291dfa9a4..b1baf5e299a81a8ca22af343bc8104c52c51fd5e 100644 (file)
@@ -225,7 +225,7 @@ static void parse_dns(struct loadparm_context *lp_ctx, const char *dns)
        char *p, *d;
 
        /* retrieve the userdn */
-       p = strchr_m(dns, '#');
+       p = discard_const_p(char, strchr_m(dns, '#'));
        if (!p) {
                lpcfg_set_cmdline(lp_ctx, "torture:ldap_userdn", "");
                lpcfg_set_cmdline(lp_ctx, "torture:ldap_basedn", "");