[exim-cvs] Eximon: fix string-handling. Bug 2500

Top Page
Delete this message
Reply to this message
Author: Exim Git Commits Mailing List
Date:  
To: exim-cvs
Subject: [exim-cvs] Eximon: fix string-handling. Bug 2500
Gitweb: https://git.exim.org/exim.git/commitdiff/8aa16eb712afac844fb28ed465c6076c6b0ea22b
Commit:     8aa16eb712afac844fb28ed465c6076c6b0ea22b
Parent:     4a3709fb2cfb1ec26ac60bcdb8bbc078d3377ddc
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Sat Dec 21 20:31:31 2019 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Sat Dec 21 20:31:31 2019 +0000


    Eximon: fix string-handling.  Bug 2500
---
 doc/doc-txt/ChangeLog |  5 +++++
 src/OS/Makefile-Base  |  6 +++---
 src/src/functions.h   | 11 ++++++++++-
 src/src/string.c      | 20 ++++++++++++++++----
 4 files changed, 34 insertions(+), 8 deletions(-)


diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog
index f496338..e200c52 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 36af830..7122bc0 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 ea3cf25..475f2c4 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 97d71d3..fbdc024 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
}