From: Jeremy Harris Date: Sat, 21 Dec 2019 20:31:31 +0000 (+0000) Subject: Eximon: fix string-handling. Bug 2500 X-Git-Tag: exim-4.93.0.4~3 X-Git-Url: https://vcs.fsf.org/?p=exim.git;a=commitdiff_plain;h=f7be88fdcef970d66332dabe702a15fe3e1cdd9a Eximon: fix string-handling. Bug 2500 (cherry picked from commit 8aa16eb712afac844fb28ed465c6076c6b0ea22b) --- diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog index 812546e8c..727221f4d 100644 --- a/doc/doc-txt/ChangeLog +++ b/doc/doc-txt/ChangeLog @@ -40,6 +40,11 @@ JH/13 Bug 2498: Reset a counter used for ARC verify before handling another the following one did not, a crash could result when adding an Authentication-Results: header. +JH/14 Bug 2500: Rewind some of the common-coding in string handling between the + Exim main code and Exim-related utities. The introduction of taint + tracking also did many adjustments to string handling. Since then, eximon + frequently terminated with an assert failure. + Exim version 4.93 ----------------- diff --git a/src/OS/Makefile-Base b/src/OS/Makefile-Base index 1f42e0ec3..f4977614f 100644 --- a/src/OS/Makefile-Base +++ b/src/OS/Makefile-Base @@ -868,9 +868,9 @@ em_text.o: ../exim_monitor/em_text.c ../exim_monitor/em_hdr.h em_xs.o: ../exim_monitor/em_xs.c ../exim_monitor/em_hdr.h em_version.o: ../exim_monitor/em_version.c ../exim_monitor/em_hdr.h $(MONBIN): $(HDRS) - @echo "$(CC) exim_monitor/`echo $@ | sed 's/o$$/c/'`" - $(FE)$(CC) -o $@ -c $(CFLAGS) -I. -I../exim_monitor $(INCLUDE) $(XINCLUDE) \ - ../exim_monitor/`echo $@ | sed 's/o$$/c/'` + @echo "$(CC) exim_monitor/$(@:.o=.c)" + $(FE)$(CC) -o $@ -c $(CFLAGS) -DCOMPILE_UTILITY -I. -I../exim_monitor $(INCLUDE) $(XINCLUDE) \ + ../exim_monitor/$(@:.o=.c) # Targets for the various libraries that Exim uses. diff --git a/src/src/exim_dbmbuild.c b/src/src/exim_dbmbuild.c index 85bc3fd88..1185cfa44 100644 --- a/src/src/exim_dbmbuild.c +++ b/src/src/exim_dbmbuild.c @@ -56,6 +56,11 @@ string_vformat_trc(gstring * g, const uschar * func, unsigned line, uschar * string_sprintf_trc(const char * a, const uschar * b, unsigned c, ...) { return NULL; } +BOOL +string_format_trc(uschar * buf, int len, const uschar * func, unsigned line, + const char * fmt, ...) +{ return FALSE; } + struct global_flags f; unsigned int log_selector[1]; diff --git a/src/src/exim_dbutil.c b/src/src/exim_dbutil.c index 80f656530..a86fcbbdc 100644 --- a/src/src/exim_dbutil.c +++ b/src/src/exim_dbutil.c @@ -59,6 +59,10 @@ string_vformat_trc(gstring * g, const uschar * func, unsigned line, uschar * string_sprintf_trc(const char * fmt, const uschar * func, unsigned line, ...) { return NULL; } +BOOL +string_format_trc(uschar * buf, int len, const uschar * func, unsigned line, + const char * fmt, ...) +{ return FALSE; } struct global_flags f; unsigned int log_selector[1]; diff --git a/src/src/functions.h b/src/src/functions.h index f4fcd1e19..87d1a04d8 100644 --- a/src/src/functions.h +++ b/src/src/functions.h @@ -902,9 +902,18 @@ return string_sprintf("%s/%s/%s/%s/%s%s", static inline uschar * spool_fname(const uschar * purpose, const uschar * subdir, const uschar * fname, - const uschar * suffix) + const uschar * suffix) { +#ifdef COMPILE_UTILITY /* version avoiding string-extension */ +int len = Ustrlen(spool_directory) + 1 + Ustrlen(queue_name) + 1 + Ustrlen(purpose) + 1 + + Ustrlen(subdir) + 1 + Ustrlen(fname) + Ustrlen(suffix) + 1; +uschar * buf = store_get(len, FALSE); +string_format(buf, len, "%s/%s/%s/%s/%s%s", + spool_directory, queue_name, purpose, subdir, fname, suffix); +return buf; +#else return spool_q_fname(purpose, queue_name, subdir, fname, suffix); +#endif } static inline void diff --git a/src/src/string.c b/src/src/string.c index a20807054..49a028343 100644 --- a/src/src/string.c +++ b/src/src/string.c @@ -678,12 +678,20 @@ Returns: pointer to fresh piece of store containing sprintf'ed string uschar * string_sprintf_trc(const char *format, const uschar * func, unsigned line, ...) { -gstring * g; -va_list ap; +#ifdef COMPILE_UTILITY +uschar buffer[STRING_SPRINTF_BUFFER_SIZE]; +gstring gs = { .size = STRING_SPRINTF_BUFFER_SIZE, .ptr = 0, .s = buffer }; +gstring * g = &gs; +unsigned flags = 0; +#else +gstring * g = NULL; +unsigned flags = SVFMT_REBUFFER|SVFMT_EXTEND; +#endif +va_list ap; va_start(ap, line); -g = string_vformat_trc(NULL, func, line, STRING_SPRINTF_BUFFER_SIZE, - SVFMT_REBUFFER|SVFMT_EXTEND, format, ap); +g = string_vformat_trc(g, func, line, STRING_SPRINTF_BUFFER_SIZE, + flags, format, ap); va_end(ap); if (!g) @@ -692,8 +700,12 @@ if (!g) " called from %s %d\n", STRING_SPRINTF_BUFFER_SIZE, format, func, line); +#ifdef COMPILE_UTILITY +return string_copyn(g->s, g->ptr); +#else gstring_release_unused(g); return string_from_gstring(g); +#endif }