Const-ification
authorJeremy Harris <jgh146exb@wizmail.org>
Thu, 20 Nov 2014 20:16:58 +0000 (20:16 +0000)
committerJeremy Harris <jgh146exb@wizmail.org>
Thu, 20 Nov 2014 20:16:58 +0000 (20:16 +0000)
src/src/acl.c
src/src/dns.c
src/src/exim.c
src/src/functions.h
src/src/local_scan.h
src/src/lookups/dnsdb.c
src/src/match.c
src/src/string.c

index fe1e254bdc4e0532ac7ee34d6265692891315567..4ee70bf319814c2bc9743a2dde295ed487320f12 100644 (file)
@@ -1550,7 +1550,7 @@ for (rr = dns_next_rr(&dnsa, &dnss, RESET_ANSWERS);
   assertion: legitimate SMTP clients are all explicitly authorized with CSA
   SRV records of their own. */
 
   assertion: legitimate SMTP clients are all explicitly authorized with CSA
   SRV records of their own. */
 
-  if (found != domain)
+  if (Ustrcmp(found, domain) != 0)
     {
     if (port & 1)
       return t->data.val = CSA_FAIL_EXPLICIT;
     {
     if (port & 1)
       return t->data.val = CSA_FAIL_EXPLICIT;
index 3d047abba11cbbbbe62ff8d60962b81b9830cfe1..66633f741facf71ee65e71a5fee08b435ef3b2fd 100644 (file)
@@ -46,7 +46,7 @@ Returns:      length of returned data, or -1 on error (h_errno set)
 */
 
 static int
 */
 
 static int
-fakens_search(uschar *domain, int type, uschar *answerptr, int size)
+fakens_search(const uschar *domain, int type, uschar *answerptr, int size)
 {
 int len = Ustrlen(domain);
 int asize = size;                  /* Locally modified */
 {
 int len = Ustrlen(domain);
 int asize = size;                  /* Locally modified */
@@ -443,7 +443,7 @@ Returns:    bool indicating presence of AD bit
 */
 
 BOOL
 */
 
 BOOL
-dns_is_secure(dns_answer *dnsa)
+dns_is_secure(const dns_answer *dnsa)
 {
 #ifdef DISABLE_DNSSEC
 DEBUG(D_dns)
 {
 #ifdef DISABLE_DNSSEC
 DEBUG(D_dns)
@@ -510,7 +510,7 @@ Returns:     the return code
 */
 
 static int
 */
 
 static int
-dns_return(uschar *name, int type, int rc)
+dns_return(const uschar * name, int type, int rc)
 {
 res_state resp = os_get_dns_resolver_res();
 tree_node *node = store_get_perm(sizeof(tree_node) + 290);
 {
 res_state resp = os_get_dns_resolver_res();
 tree_node *node = store_get_perm(sizeof(tree_node) + 290);
@@ -549,7 +549,7 @@ Returns:    DNS_SUCCEED   successful lookup
 */
 
 int
 */
 
 int
-dns_basic_lookup(dns_answer *dnsa, uschar *name, int type)
+dns_basic_lookup(dns_answer *dnsa, const uschar *name, int type)
 {
 #ifndef STAND_ALONE
 int rc = -1;
 {
 #ifndef STAND_ALONE
 int rc = -1;
@@ -597,7 +597,7 @@ For SRV records, we omit the initial _smtp._tcp. components at the start. */
 
 if (check_dns_names_pattern[0] != 0 && type != T_PTR && type != T_TXT)
   {
 
 if (check_dns_names_pattern[0] != 0 && type != T_PTR && type != T_TXT)
   {
-  uschar *checkname = name;
+  const uschar *checkname = name;
   int ovector[3*(EXPAND_MAXN+1)];
 
   if (regex_check_dns_names == NULL)
   int ovector[3*(EXPAND_MAXN+1)];
 
   if (regex_check_dns_names == NULL)
@@ -613,7 +613,7 @@ if (check_dns_names_pattern[0] != 0 && type != T_PTR && type != T_TXT)
     while (*checkname++ != '.');
     }
 
     while (*checkname++ != '.');
     }
 
-  if (pcre_exec(regex_check_dns_names, NULL, CS checkname, Ustrlen(checkname),
+  if (pcre_exec(regex_check_dns_names, NULL, CCS checkname, Ustrlen(checkname),
       0, PCRE_EOPT, ovector, sizeof(ovector)/sizeof(int)) < 0)
     {
     DEBUG(D_dns)
       0, PCRE_EOPT, ovector, sizeof(ovector)/sizeof(int)) < 0)
     {
     DEBUG(D_dns)
@@ -650,7 +650,7 @@ domains, and interfaces to a fake nameserver for certain special zones. */
 if (running_in_test_harness)
   dnsa->answerlen = fakens_search(name, type, dnsa->answer, MAXPACKET);
 else
 if (running_in_test_harness)
   dnsa->answerlen = fakens_search(name, type, dnsa->answer, MAXPACKET);
 else
-  dnsa->answerlen = res_search(CS name, C_IN, type, dnsa->answer, MAXPACKET);
+  dnsa->answerlen = res_search(CCS name, C_IN, type, dnsa->answer, MAXPACKET);
 
 if (dnsa->answerlen > MAXPACKET)
   {
 
 if (dnsa->answerlen > MAXPACKET)
   {
@@ -671,9 +671,9 @@ if (dnsa->answerlen < 0) switch (h_errno)
     name, dns_text_type(type));
 
   /* Cut this out for various test programs */
     name, dns_text_type(type));
 
   /* Cut this out for various test programs */
-  #ifndef STAND_ALONE
+#ifndef STAND_ALONE
   save = deliver_domain;
   save = deliver_domain;
-  deliver_domain = name;  /* set $domain */
+  deliver_domain = string_copy(name);  /* set $domain */
   rc = match_isinlist(name, &dns_again_means_nonexist, 0, NULL, NULL,
     MCL_DOMAIN, TRUE, NULL);
   deliver_domain = save;
   rc = match_isinlist(name, &dns_again_means_nonexist, 0, NULL, NULL,
     MCL_DOMAIN, TRUE, NULL);
   deliver_domain = save;
@@ -686,9 +686,9 @@ if (dnsa->answerlen < 0) switch (h_errno)
     "DNS_NOMATCH\n", name);
   return dns_return(name, type, DNS_NOMATCH);
 
     "DNS_NOMATCH\n", name);
   return dns_return(name, type, DNS_NOMATCH);
 
-  #else   /* For stand-alone tests */
+#else   /* For stand-alone tests */
   return dns_return(name, type, DNS_AGAIN);
   return dns_return(name, type, DNS_AGAIN);
-  #endif
+#endif
 
   case NO_RECOVERY:
   DEBUG(D_dns) debug_printf("DNS lookup of %s (%s) gave NO_RECOVERY\n"
 
   case NO_RECOVERY:
   DEBUG(D_dns) debug_printf("DNS lookup of %s (%s) gave NO_RECOVERY\n"
@@ -749,10 +749,11 @@ Returns:                DNS_SUCCEED   successful lookup
 */
 
 int
 */
 
 int
-dns_lookup(dns_answer *dnsa, uschar *name, int type, uschar **fully_qualified_name)
+dns_lookup(dns_answer *dnsa, const uschar *name, int type,
+  uschar **fully_qualified_name)
 {
 int i;
 {
 int i;
-uschar *orig_name = name;
+const uschar *orig_name = name;
 
 /* Loop to follow CNAME chains so far, but no further... */
 
 
 /* Loop to follow CNAME chains so far, but no further... */
 
@@ -816,7 +817,7 @@ for (i = 0; i < 10; i++)
 
   if (cname_rr.data == NULL) return DNS_FAIL;
   datalen = dn_expand(dnsa->answer, dnsa->answer + dnsa->answerlen,
 
   if (cname_rr.data == NULL) return DNS_FAIL;
   datalen = dn_expand(dnsa->answer, dnsa->answer + dnsa->answerlen,
-    cname_rr.data, (DN_EXPAND_ARG4_TYPE)data, 256);
+    cname_rr.data, (DN_EXPAND_ARG4_TYPE)data, sizeof(data));
   if (datalen < 0) return DNS_FAIL;
   name = data;
 
   if (datalen < 0) return DNS_FAIL;
   name = data;
 
@@ -858,7 +859,7 @@ Returns:                DNS_SUCCEED   successful lookup
 */
 
 int
 */
 
 int
-dns_special_lookup(dns_answer *dnsa, uschar *name, int type,
+dns_special_lookup(dns_answer *dnsa, const uschar *name, int type,
   uschar **fully_qualified_name)
 {
 if (type >= 0) return dns_lookup(dnsa, name, type, fully_qualified_name);
   uschar **fully_qualified_name)
 {
 if (type >= 0) return dns_lookup(dnsa, name, type, fully_qualified_name);
@@ -872,7 +873,7 @@ root servers. */
 
 if (type == T_ZNS)
   {
 
 if (type == T_ZNS)
   {
-  uschar *d = name;
+  const uschar *d = name;
   while (d != 0)
     {
     int rc = dns_lookup(dnsa, d, T_NS, fully_qualified_name);
   while (d != 0)
     {
     int rc = dns_lookup(dnsa, d, T_NS, fully_qualified_name);
@@ -905,7 +906,7 @@ if (type == T_CSA)
   rc = dns_lookup(dnsa, srvname, T_SRV, NULL);
   if (rc == DNS_SUCCEED || rc == DNS_AGAIN)
     {
   rc = dns_lookup(dnsa, srvname, T_SRV, NULL);
   if (rc == DNS_SUCCEED || rc == DNS_AGAIN)
     {
-    if (rc == DNS_SUCCEED) *fully_qualified_name = name;
+    if (rc == DNS_SUCCEED) *fully_qualified_name = string_copy(name);
     return rc;
     }
 
     return rc;
     }
 
index 32139bd339052283494d42da960c52cfa73edd27..3f7473776f0a2543d58aec15338955209aadafe2 100644 (file)
@@ -131,10 +131,11 @@ Returns:      TRUE or FALSE
 */
 
 BOOL
 */
 
 BOOL
-regex_match_and_setup(const pcre *re, uschar *subject, int options, int setup)
+regex_match_and_setup(const pcre *re, const uschar *subject, int options, int setup)
 {
 int ovector[3*(EXPAND_MAXN+1)];
 {
 int ovector[3*(EXPAND_MAXN+1)];
-int n = pcre_exec(re, NULL, CS subject, Ustrlen(subject), 0,
+uschar * s = string_copy(subject);     /* de-constifying */
+int n = pcre_exec(re, NULL, CS s, Ustrlen(s), 0,
   PCRE_EOPT | options, ovector, sizeof(ovector)/sizeof(int));
 BOOL yield = n >= 0;
 if (n == 0) n = EXPAND_MAXN + 1;
   PCRE_EOPT | options, ovector, sizeof(ovector)/sizeof(int));
 BOOL yield = n >= 0;
 if (n == 0) n = EXPAND_MAXN + 1;
@@ -144,7 +145,7 @@ if (yield)
   expand_nmax = (setup < 0)? 0 : setup + 1;
   for (nn = (setup < 0)? 0 : 2; nn < n*2; nn += 2)
     {
   expand_nmax = (setup < 0)? 0 : setup + 1;
   for (nn = (setup < 0)? 0 : 2; nn < n*2; nn += 2)
     {
-    expand_nstring[expand_nmax] = subject + ovector[nn];
+    expand_nstring[expand_nmax] = s + ovector[nn];
     expand_nlength[expand_nmax++] = ovector[nn+1] - ovector[nn];
     }
   expand_nmax--;
     expand_nlength[expand_nmax++] = ovector[nn+1] - ovector[nn];
     }
   expand_nmax--;
index 2074bb2f1b0620be178d1112337892f5ef643a11..f7d5449bd1490f1663fb9aad2e5d044e55d2c01d 100644 (file)
@@ -146,10 +146,10 @@ extern BOOL    dkim_transport_write_message(address_item *, int, int,
 extern dns_address *dns_address_from_rr(dns_answer *, dns_record *);
 extern void    dns_build_reverse(uschar *, uschar *);
 extern void    dns_init(BOOL, BOOL, BOOL);
 extern dns_address *dns_address_from_rr(dns_answer *, dns_record *);
 extern void    dns_build_reverse(uschar *, uschar *);
 extern void    dns_init(BOOL, BOOL, BOOL);
-extern int     dns_basic_lookup(dns_answer *, uschar *, int);
-extern BOOL    dns_is_secure(dns_answer *);
-extern int     dns_lookup(dns_answer *, uschar *, int, uschar **);
-extern int     dns_special_lookup(dns_answer *, uschar *, int, uschar **);
+extern int     dns_basic_lookup(dns_answer *, const uschar *, int);
+extern BOOL    dns_is_secure(const dns_answer *);
+extern int     dns_lookup(dns_answer *, const uschar *, int, uschar **);
+extern int     dns_special_lookup(dns_answer *, const uschar *, int, uschar **);
 extern dns_record *dns_next_rr(dns_answer *, dns_scan *, int);
 extern uschar *dns_text_type(int);
 extern void    dscp_list_to_stream(FILE *);
 extern dns_record *dns_next_rr(dns_answer *, dns_scan *, int);
 extern uschar *dns_text_type(int);
 extern void    dscp_list_to_stream(FILE *);
@@ -225,7 +225,7 @@ extern int     match_address_list(uschar *, BOOL, BOOL, uschar **,
 extern int     match_check_list(uschar **, int, tree_node **, unsigned int **,
                  int(*)(void *, uschar *, uschar **, uschar **), void *, int,
                  const uschar *, uschar **);
 extern int     match_check_list(uschar **, int, tree_node **, unsigned int **,
                  int(*)(void *, uschar *, uschar **, uschar **), void *, int,
                  const uschar *, uschar **);
-extern int     match_isinlist(uschar *, uschar **, int, tree_node **,
+extern int     match_isinlist(const uschar *, uschar **, int, tree_node **,
                  unsigned int *, int, BOOL, uschar **);
 extern int     match_check_string(uschar *, uschar *, int, BOOL, BOOL, BOOL,
                  uschar **);
                  unsigned int *, int, BOOL, uschar **);
 extern int     match_check_string(uschar *, uschar *, int, BOOL, BOOL, BOOL,
                  uschar **);
@@ -302,7 +302,7 @@ extern void    receive_swallow_smtp(void);
 #ifdef WITH_CONTENT_SCAN
 extern int     regex(uschar **);
 #endif
 #ifdef WITH_CONTENT_SCAN
 extern int     regex(uschar **);
 #endif
-extern BOOL    regex_match_and_setup(const pcre *, uschar *, int, int);
+extern BOOL    regex_match_and_setup(const pcre *, const uschar *, int, int);
 extern const pcre *regex_must_compile(uschar *, BOOL, BOOL);
 extern void    retry_add_item(address_item *, uschar *, int);
 extern BOOL    retry_check_address(uschar *, host_item *, uschar *, BOOL,
 extern const pcre *regex_must_compile(uschar *, BOOL, BOOL);
 extern void    retry_add_item(address_item *, uschar *, int);
 extern BOOL    retry_check_address(uschar *, host_item *, uschar *, BOOL,
@@ -392,7 +392,7 @@ extern uschar *string_base62(unsigned long int);
 extern uschar *string_cat(uschar *, int *, int *, const uschar *, int);
 extern uschar *string_copy_dnsdomain(uschar *);
 extern uschar *string_copy_malloc(uschar *);
 extern uschar *string_cat(uschar *, int *, int *, const uschar *, int);
 extern uschar *string_copy_dnsdomain(uschar *);
 extern uschar *string_copy_malloc(uschar *);
-extern uschar *string_copylc(uschar *);
+extern uschar *string_copylc(const uschar *);
 extern uschar *string_copynlc(uschar *, int);
 extern uschar *string_dequote(uschar **);
 extern BOOL    string_format(uschar *, int, const char *, ...) ALMOST_PRINTF(3,4);
 extern uschar *string_copynlc(uschar *, int);
 extern uschar *string_dequote(uschar **);
 extern BOOL    string_format(uschar *, int, const char *, ...) ALMOST_PRINTF(3,4);
index 770348a9b83308f0f77b4ce0c10fafcb16d4ba05..6df601af49a4ac53710cbcb01570bc8b9b8529d4 100644 (file)
@@ -191,7 +191,7 @@ extern int     smtp_fflush(void);
 extern void    smtp_printf(const char *, ...) PRINTF_FUNCTION(1,2);
 extern void    smtp_vprintf(const char *, va_list);
 extern uschar *string_copy(const uschar *);
 extern void    smtp_printf(const char *, ...) PRINTF_FUNCTION(1,2);
 extern void    smtp_vprintf(const char *, va_list);
 extern uschar *string_copy(const uschar *);
-extern uschar *string_copyn(uschar *, int);
+extern uschar *string_copyn(const uschar *, int);
 extern uschar *string_sprintf(const char *, ...) ALMOST_PRINTF(1,2);
 
 /* End of local_scan.h */
 extern uschar *string_sprintf(const char *, ...) ALMOST_PRINTF(1,2);
 
 /* End of local_scan.h */
index 5a82b340d7296b47a3256231c6bfd0eec2c3183d..7c2d1a540015a896dceff2199031e33aec07d4ae 100644 (file)
@@ -498,7 +498,7 @@ while ((domain = string_nextinlist(&keystring, &sep, buffer, sizeof(buffer)))
           the subdomain assertions in the port field, else analyse the direct
           authorization status in the weight field. */
 
           the subdomain assertions in the port field, else analyse the direct
           authorization status in the weight field. */
 
-          if (found != domain)
+          if (Ustrcmp(found, domain) != 0)
             {
             if (port & 1) *s = 'X';         /* explicit authorization required */
             else *s = '?';                  /* no subdomain assertions here */
             {
             if (port & 1) *s = 'X';         /* explicit authorization required */
             else *s = '?';                  /* no subdomain assertions here */
index 604157da3202af8f6e2831ffdf5d955972cc8050..97c4ea045b7f533681dacf7443be9b6f9c676575 100644 (file)
@@ -15,8 +15,8 @@
 strings, domains, and local parts. */
 
 typedef struct check_string_block {
 strings, domains, and local parts. */
 
 typedef struct check_string_block {
-  uschar *origsubject;               /* caseful; keep these two first, in */
-  uschar *subject;                   /* step with the block below */
+  const uschar *origsubject;           /* caseful; keep these two first, in */
+  const uschar *subject;               /* step with the block below */
   int    expand_setup;
   BOOL   use_partial;
   BOOL   caseless;
   int    expand_setup;
   BOOL   use_partial;
   BOOL   caseless;
@@ -94,7 +94,7 @@ Returns:       OK    if matched
 static int
 check_string(void *arg, uschar *pattern, uschar **valueptr, uschar **error)
 {
 static int
 check_string(void *arg, uschar *pattern, uschar **valueptr, uschar **error)
 {
-check_string_block *cb = (check_string_block *)arg;
+const check_string_block *cb = arg;
 int search_type, partial, affixlen, starflags;
 int expand_setup = cb->expand_setup;
 uschar *affix;
 int search_type, partial, affixlen, starflags;
 int expand_setup = cb->expand_setup;
 uschar *affix;
@@ -111,7 +111,7 @@ if (valueptr != NULL) *valueptr = NULL;  /* For non-lookup matches */
 it works if the pattern uses (?-i) to turn off case-independence, overriding
 "caseless". */
 
 it works if the pattern uses (?-i) to turn off case-independence, overriding
 "caseless". */
 
-s = (pattern[0] == '^')? cb->origsubject : cb->subject;
+s = string_copy(pattern[0] == '^' ? cb->origsubject : cb->subject);
 
 /* If required to set up $0, initialize the data but don't turn on by setting
 expand_nmax until the match is assured. */
 
 /* If required to set up $0, initialize the data but don't turn on by setting
 expand_nmax until the match is assured. */
@@ -131,7 +131,7 @@ if (pattern[0] == '^')
   {
   const pcre *re = regex_must_compile(pattern, cb->caseless, FALSE);
   return ((expand_setup < 0)?
   {
   const pcre *re = regex_must_compile(pattern, cb->caseless, FALSE);
   return ((expand_setup < 0)?
-           pcre_exec(re, NULL, CS s, Ustrlen(s), 0, PCRE_EOPT, NULL, 0) >= 0
+           pcre_exec(re, NULL, CCS s, Ustrlen(s), 0, PCRE_EOPT, NULL, 0) >= 0
            :
            regex_match_and_setup(re, s, 0, expand_setup)
          )?
            :
            regex_match_and_setup(re, s, 0, expand_setup)
          )?
@@ -366,7 +366,7 @@ Arguments:
   type         MCL_STRING, MCL_DOMAIN, MCL_HOST, MCL_ADDRESS, or MCL_LOCALPART
 */
 
   type         MCL_STRING, MCL_DOMAIN, MCL_HOST, MCL_ADDRESS, or MCL_LOCALPART
 */
 
-static uschar *
+static const uschar *
 get_check_key(void *arg, int type)
 {
 switch(type)
 get_check_key(void *arg, int type)
 {
 switch(type)
@@ -489,7 +489,7 @@ else
   if (type == MCL_DOMAIN && deliver_domain == NULL)
     {
     check_string_block *cb = (check_string_block *)arg;
   if (type == MCL_DOMAIN && deliver_domain == NULL)
     {
     check_string_block *cb = (check_string_block *)arg;
-    deliver_domain = cb->subject;
+    deliver_domain = string_copy(cb->subject);
     list = expand_string(*listptr);
     deliver_domain = NULL;
     }
     list = expand_string(*listptr);
     deliver_domain = NULL;
     }
@@ -701,7 +701,7 @@ while ((sss = string_nextinlist(&list, &sep, buffer, sizeof(buffer))) != NULL)
         cached = US" - cached";
         if (valueptr != NULL)
           {
         cached = US" - cached";
         if (valueptr != NULL)
           {
-          uschar *key = get_check_key(arg, type);
+          const uschar *key = get_check_key(arg, type);
           namedlist_cacheblock *p;
           for (p = nb->cache_data; p != NULL; p = p->next)
             {
           namedlist_cacheblock *p;
           for (p = nb->cache_data; p != NULL; p = p->next)
             {
@@ -952,7 +952,8 @@ Returns:         OK    if matched a non-negated item
 */
 
 int
 */
 
 int
-match_isinlist(uschar *s, uschar **listptr, int sep, tree_node **anchorptr,
+match_isinlist(const uschar *s, uschar **listptr, int sep,
+   tree_node **anchorptr,
   unsigned int *cache_bits, int type, BOOL caseless, uschar **valueptr)
 {
 unsigned int *local_cache_bits = cache_bits;
   unsigned int *cache_bits, int type, BOOL caseless, uschar **valueptr)
 {
 unsigned int *local_cache_bits = cache_bits;
index 775709dc6a4304566e9429f1d8351cffb59b4569..71c7f6f8e86188692f5da6a45620fa62607238cb 100644 (file)
@@ -457,7 +457,7 @@ Returns:  copy of string in new store, with letters lowercased
 */
 
 uschar *
 */
 
 uschar *
-string_copylc(uschar *s)
+string_copylc(const uschar *s)
 {
 uschar *ss = store_get(Ustrlen(s) + 1);
 uschar *p = ss;
 {
 uschar *ss = store_get(Ustrlen(s) + 1);
 uschar *p = ss;
@@ -483,7 +483,7 @@ Returns:    copy of string in new store
 */
 
 uschar *
 */
 
 uschar *
-string_copyn(uschar *s, int n)
+string_copyn(const uschar *s, int n)
 {
 uschar *ss = store_get(n + 1);
 Ustrncpy(ss, s, n);
 {
 uschar *ss = store_get(n + 1);
 Ustrncpy(ss, s, n);