*************************************************/
/* Copyright (c) University of Cambridge 1995 - 2018 */
-/* Copyright (c) The Exim Maintainers 2020 */
+/* Copyright (c) The Exim Maintainers 2020 - 2021 */
/* See the file NOTICE for conditions of use and distribution. */
*/
static uschar *
-find_header(uschar *name, int *newsize, unsigned flags, uschar *charset)
+find_header(uschar *name, int *newsize, unsigned flags, const uschar *charset)
{
BOOL found = !name;
int len = name ? Ustrlen(name) : 0;
#ifndef EXIM_HAVE_ABSTRACT_UNIX_SOCKETS
uschar * sname;
#endif
-fd_set fds;
-struct timeval tv;
if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
{
buf[0] = NOTIFY_QUEUE_SIZE_REQ;
if (send(fd, buf, 1, 0) < 0) { where = US"send"; goto bad; }
-FD_ZERO(&fds); FD_SET(fd, &fds);
-tv.tv_sec = 2; tv.tv_usec = 0;
-if (select(fd + 1, (SELECT_ARG2_TYPE *)&fds, NULL, NULL, &tv) != 1)
+if (poll_one_fd(fd, POLLIN, 2 * 1000) != 1)
{
DEBUG(D_expand) debug_printf("no daemon response; using local evaluation\n");
len = snprintf(CS buf, sizeof(buf), "%u", queue_count_cached());
something non-NULL if exists_only is TRUE
*/
-static uschar *
+static const uschar *
find_variable(uschar *name, BOOL exists_only, BOOL skipping, int *newsize)
{
var_entry * vp;
{
uschar *endptr;
int n = Ustrtoul(name + 4, &endptr, 10);
- if (*endptr == 0 && n != 0 && n <= AUTH_VARS)
- return !auth_vars[n-1] ? US"" : auth_vars[n-1];
+ if (!*endptr && n != 0 && n <= AUTH_VARS)
+ return auth_vars[n-1] ? auth_vars[n-1] : US"";
}
else if (Ustrncmp(name, "regex", 5) == 0)
{
uschar *endptr;
int n = Ustrtoul(name + 5, &endptr, 10);
- if (*endptr == 0 && n != 0 && n <= REGEX_VARS)
- return !regex_vars[n-1] ? US"" : regex_vars[n-1];
+ if (!*endptr && n != 0 && n <= REGEX_VARS)
+ return regex_vars[n-1] ? regex_vars[n-1] : US"";
}
/* For all other variables, search the table */
case ECOND_DEF:
{
- uschar * t;
+ const uschar * t;
if (*s != ':')
{
uschar errbuf[128];
pcre2_get_error_message(err, errbuf, sizeof(errbuf));
expand_string_message = string_sprintf("regular expression error in "
- "\"%s\": %s at offset %d", sub[1], errbuf, offset);
+ "\"%s\": %s at offset %ld", sub[1], errbuf, (long)offset);
return NULL;
}
srs_recipient = string_sprintf("%.*s%.*S%.*s@%.*S", /* lowercased */
quoting, "\"",
- ovec[9]-ovec[8], sub[0] + ovec[8], /* substring 4 */
+ (int) (ovec[9]-ovec[8]), sub[0] + ovec[8], /* substr 4 */
quoting, "\"",
- ovec[7]-ovec[6], sub[0] + ovec[6]); /* substring 3 */
+ (int) (ovec[7]-ovec[6]), sub[0] + ovec[6]); /* substr 3 */
/* If a zero-length secret was given, we're done. Otherwise carry on
and validate the given SRS local_part againt our secret. */
*/
static int
-save_expand_strings(uschar **save_expand_nstring, int *save_expand_nlength)
+save_expand_strings(const uschar **save_expand_nstring, int *save_expand_nlength)
{
for (int i = 0; i <= expand_nmax; i++)
{
*/
static void
-restore_expand_strings(int save_expand_nmax, uschar **save_expand_nstring,
+restore_expand_strings(int save_expand_nmax, const uschar **save_expand_nstring,
int *save_expand_nlength)
{
expand_nmax = save_expand_nmax;
const uschar * list;
int sep = 0;
uschar * item;
-uschar * suffix = US"";
BOOL needsep = FALSE;
#define LISTNAMED_BUF_SIZE 256
uschar b[LISTNAMED_BUF_SIZE];
}
else switch(*listtype) /* specific list-type version */
{
- case 'a': t = tree_search(addresslist_anchor, name); suffix = US"_a"; break;
- case 'd': t = tree_search(domainlist_anchor, name); suffix = US"_d"; break;
- case 'h': t = tree_search(hostlist_anchor, name); suffix = US"_h"; break;
- case 'l': t = tree_search(localpartlist_anchor, name); suffix = US"_l"; break;
+ case 'a': t = tree_search(addresslist_anchor, name); break;
+ case 'd': t = tree_search(domainlist_anchor, name); break;
+ case 'h': t = tree_search(hostlist_anchor, name); break;
+ case 'l': t = tree_search(localpartlist_anchor, name); break;
default:
expand_string_message = US"bad suffix on \"list\" operator";
return yield;
gstring * yield = string_get(Ustrlen(string) + 64);
int item_type;
const uschar *s = string;
-uschar *save_expand_nstring[EXPAND_MAXN+1];
+const uschar *save_expand_nstring[EXPAND_MAXN+1];
int save_expand_nlength[EXPAND_MAXN+1];
BOOL resetok = TRUE;
while (*s)
{
- uschar *value;
uschar name[256];
/* \ escapes the next character, which must exist, or else
if (isalpha((*(++s))))
{
+ const uschar * value;
int len;
int newsize = 0;
gstring * g = NULL;
unsigned flags = *name == 'r' ? FH_WANT_RAW
: *name == 'l' ? FH_WANT_RAW|FH_WANT_LIST
: 0;
- uschar * charset = *name == 'b' ? NULL : headers_charset;
+ const uschar * charset = *name == 'b' ? NULL : headers_charset;
s = read_header_name(name, sizeof(name), s);
value = find_header(name, &newsize, flags, charset);
But there is no error here - nothing gets inserted. */
if (!value)
- {
+ { /*{*/
if (Ustrchr(name, '}')) malformed_header = TRUE;
continue;
}
yield = g;
yield->size = newsize;
yield->ptr = len;
- yield->s = value;
+ yield->s = US value; /* known to be in new store i.e. a copy, so deconst safe */
}
else
yield = string_catn(yield, value, len);
uschar errbuf[128];
pcre2_get_error_message(err, errbuf, sizeof(errbuf));
expand_string_message = string_sprintf("regular expression error in "
- "\"%s\": %s at offset %l", sub[1], errbuf, (long)roffset);
+ "\"%s\": %s at offset %ld", sub[1], errbuf, (long)roffset);
goto EXPAND_FAILED;
}
md = pcre2_match_data_create(EXPAND_MAXN + 1, pcre_gen_ctx);
/*{*/
if (*s++ == '}')
{
+ const uschar * value;
int len;
int newsize = 0;
gstring * g = NULL;
yield = g;
yield->size = newsize;
yield->ptr = len;
- yield->s = value;
+ yield->s = US value; /* known to be in new store i.e. a copy, so deconst safe */
}
else
yield = string_catn(yield, value, len);
const uschar *var_data;
} err_ctx;
+/* Called via tree_walk, which allows nonconst name/data. Our usage is const. */
static void
assert_variable_notin(uschar * var_name, uschar * var_data, void * ctx)
{
tree_walk(acl_var_c, assert_variable_notin, &e);
tree_walk(acl_var_m, assert_variable_notin, &e);
-/* check auth<n> variables */
+/* check auth<n> variables.
+assert_variable_notin() treats as const, so deconst is safe. */
for (int i = 0; i < AUTH_VARS; i++) if (auth_vars[i])
- assert_variable_notin(US"auth<n>", auth_vars[i], &e);
+ assert_variable_notin(US"auth<n>", US auth_vars[i], &e);
-/* check regex<n> variables */
+/* check regex<n> variables. assert_variable_notin() treats as const. */
for (int i = 0; i < REGEX_VARS; i++) if (regex_vars[i])
- assert_variable_notin(US"regex<n>", regex_vars[i], &e);
+ assert_variable_notin(US"regex<n>", US regex_vars[i], &e);
/* check known-name variables */
for (var_entry * v = var_table; v < var_table + var_table_size; v++)