X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/d185889f47b9b27088e777f7d382295c51271586..32dfdf8baa8ccf091a0d5d4d75e8627424898756:/src/src/readconf.c diff --git a/src/src/readconf.c b/src/src/readconf.c index 045b992a4..1ed93eb64 100644 --- a/src/src/readconf.c +++ b/src/src/readconf.c @@ -395,7 +395,7 @@ options_from_list(optionlist_auths, optionlist_auths_size, US"AUTHENTICATORS", N for (ai = auths_available; ai->driver_name[0]; ai++) { - snprintf(buf, sizeof(buf), "_DRIVER_AUTHENTICATOR_%T", ai->driver_name); + spf(buf, sizeof(buf), "_DRIVER_AUTHENTICATOR_%T", ai->driver_name); builtin_macro_create(buf); options_from_list(ai->options, (unsigned)*ai->options_count, US"AUTHENTICATOR", ai->driver_name); } @@ -604,13 +604,13 @@ Args: macro_item * macro_create(const uschar * name, const uschar * val, BOOL command_line) { -unsigned namelen = Ustrlen(name); macro_item * m = store_get(sizeof(macro_item)); /* fprintf(stderr, "%s: '%s' '%s'\n", __FUNCTION__, name, val); */ m->next = NULL; m->command_line = command_line; -m->namelen = namelen; +m->namelen = Ustrlen(name); +m->replen = Ustrlen(val); m->name = name; m->replacement = val; mlast->next = m; @@ -701,7 +701,10 @@ if (m && m->command_line) return; if (redef) if (m) + { + m->replen = Ustrlen(s); m->replacement = string_copy(s); + } else log_write(0, LOG_CONFIG|LOG_PANIC_DIE, "can't redefine an undefined macro " "\"%s\"", name); @@ -825,24 +828,28 @@ for (;;) if (*s != '=') s = ss; /* Not a macro definition */ } + /* Skip leading chars which cannot start a macro name, to avoid multiple + pointless rescans in Ustrstr calls. */ + + while (*s && !isupper(*s) && *s != '_') s++; + /* For each defined macro, scan the line (from after XXX= if present), replacing all occurrences of the macro. */ macro_found = FALSE; for (m = macros; m; m = m->next) { - uschar *p, *pp; - uschar *t = s; + uschar * p, *pp; + uschar * t = s; while ((p = Ustrstr(t, m->name)) != NULL) { int moveby; - int replen = Ustrlen(m->replacement); -/* fprintf(stderr, "%s: matched '%s' in '%s'\n", __FUNCTION__, m->name, t); */ +/* fprintf(stderr, "%s: matched '%s' in '%s'\n", __FUNCTION__, m->name, ss); */ /* Expand the buffer if necessary */ - while (newlen - m->namelen + replen + 1 > big_buffer_size) + while (newlen - m->namelen + m->replen + 1 > big_buffer_size) { int newsize = big_buffer_size + BIG_BUFFER_SIZE; uschar *newbuffer = store_malloc(newsize); @@ -861,13 +868,14 @@ for (;;) same macro. */ pp = p + m->namelen; - if ((moveby = replen - m->namelen) != 0) + if ((moveby = m->replen - m->namelen) != 0) { - memmove(p + replen, pp, (big_buffer + newlen) - pp + 1); + memmove(p + m->replen, pp, (big_buffer + newlen) - pp + 1); newlen += moveby; } - Ustrncpy(p, m->replacement, replen); - t = p + replen; + Ustrncpy(p, m->replacement, m->replen); + t = p + m->replen; + while (*t && !isupper(*t) && *t != '_') t++; macro_found = TRUE; } } @@ -2290,10 +2298,10 @@ t /= 24; d = t % 7; w = t/7; -if (w > 0) { sprintf(CS p, "%dw", w); while (*p) p++; } -if (d > 0) { sprintf(CS p, "%dd", d); while (*p) p++; } -if (h > 0) { sprintf(CS p, "%dh", h); while (*p) p++; } -if (m > 0) { sprintf(CS p, "%dm", m); while (*p) p++; } +if (w > 0) p += sprintf(CS p, "%dw", w); +if (d > 0) p += sprintf(CS p, "%dd", d); +if (h > 0) p += sprintf(CS p, "%dh", h); +if (m > 0) p += sprintf(CS p, "%dm", m); if (s > 0 || p == time_buffer) sprintf(CS p, "%ds", s); return time_buffer;