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_94_RC0~199 X-Git-Url: https://vcs.fsf.org/?p=exim.git;a=commitdiff_plain;h=8aa16eb712afac844fb28ed465c6076c6b0ea22b;hp=4a3709fb2cfb1ec26ac60bcdb8bbc078d3377ddc Eximon: fix string-handling. Bug 2500 --- diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog index f4963389e..e200c5291 100644 --- a/doc/doc-txt/ChangeLog +++ b/doc/doc-txt/ChangeLog @@ -53,6 +53,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 36af8308d..7122bc019 100644 --- a/src/OS/Makefile-Base +++ b/src/OS/Makefile-Base @@ -870,9 +870,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/functions.h b/src/src/functions.h index ea3cf257c..475f2c496 100644 --- a/src/src/functions.h +++ b/src/src/functions.h @@ -906,9 +906,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 97d71d3a4..fbdc0246d 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 }