From: Jeremy Harris Date: Sun, 12 Jan 2020 14:52:00 +0000 (+0000) Subject: string handling: strlen for gstring X-Git-Url: https://git.exim.org/users/jgh/exim.git/commitdiff_plain/ba5120a469a78ca316916e7be98c5fcb0ddd0d33 string handling: strlen for gstring --- diff --git a/src/src/acl.c b/src/src/acl.c index 3166069ba..13cda1ab4 100644 --- a/src/src/acl.c +++ b/src/src/acl.c @@ -1022,8 +1022,8 @@ for (p = q; *p; p = q) if (!*hptr) { /* The header_line struct itself is not tainted, though it points to - tainted data. */ - header_line *h = store_get(sizeof(header_line), FALSE); + possibly tainted data. */ + header_line * h = store_get(sizeof(header_line), FALSE); h->text = hdr; h->next = NULL; h->type = newtype; diff --git a/src/src/arc.c b/src/src/arc.c index 94365498f..b453e171c 100644 --- a/src/src/arc.c +++ b/src/src/arc.c @@ -1192,7 +1192,7 @@ static gstring * arc_sign_append_aar(gstring * g, arc_ctx * ctx, const uschar * identity, int instance, blob * ar) { -int aar_off = g ? g->ptr : 0; +int aar_off = gstring_length(g); arc_set * as = store_get(sizeof(arc_set) + sizeof(arc_line) + sizeof(header_line), FALSE); arc_line * al = (arc_line *)(as+1); diff --git a/src/src/expand.c b/src/src/expand.c index 55aaf53ca..7986bbd14 100644 --- a/src/src/expand.c +++ b/src/src/expand.c @@ -1630,8 +1630,8 @@ for (header_line * h = header_list; h; h = h->next) /* Trim the header roughly if we're approaching limits */ inc = t - s; - if ((g ? g->ptr : 0) + inc > header_insert_maxlen) - inc = header_insert_maxlen - (g ? g->ptr : 0); + if (gstring_length(g) + inc > header_insert_maxlen) + inc = header_insert_maxlen - gstring_length(g); /* For raw just copy the data; for a list, add the data as a colon-sep list-element; for comma-list add as an unchecked comma,newline sep @@ -1643,17 +1643,12 @@ for (header_line * h = header_list; h; h = h->next) if (flags & FH_WANT_LIST) g = string_append_listele_n(g, ':', s, (unsigned)inc); else if (flags & FH_WANT_RAW) - { g = string_catn(g, s, (unsigned)inc); - (void) string_from_gstring(g); - } else if (inc > 0) - if (comma) - g = string_append2_listele_n(g, US",\n", s, (unsigned)inc); - else - g = string_append2_listele_n(g, US"\n", s, (unsigned)inc); + g = string_append2_listele_n(g, comma ? US",\n" : US"\n", + s, (unsigned)inc); - if (g && g->ptr >= header_insert_maxlen) break; + if (gstring_length(g) >= header_insert_maxlen) break; } if (!found) return NULL; /* No header found */ @@ -1663,7 +1658,7 @@ if (!g) return US""; *newsize = g->size; if (flags & FH_WANT_RAW) - return g->s; + return string_from_gstring(g); /* Otherwise do RFC 2047 decoding, translating the charset if requested. The rfc2047_decode2() function can return an error with decoded data if the @@ -1671,16 +1666,12 @@ charset translation fails. If decoding fails, it returns NULL. */ else { - uschar *decoded, *error; - - decoded = rfc2047_decode2(g->s, check_rfc2047_length, charset, '?', NULL, - newsize, &error); + uschar * error, * decoded = rfc2047_decode2(string_from_gstring(g), + check_rfc2047_length, charset, '?', NULL, newsize, &error); if (error) - { DEBUG(D_any) debug_printf("*** error in RFC 2047 decoding: %s\n" " input was: %s\n", error, g->s); - } - return decoded ? decoded : g->s; + return decoded ? decoded : string_from_gstring(g); } } diff --git a/src/src/functions.h b/src/src/functions.h index fe15cc573..7677a3cd9 100644 --- a/src/src/functions.h +++ b/src/src/functions.h @@ -820,6 +820,12 @@ g->s[g->ptr] = '\0'; return g->s; } +static inline unsigned +gstring_length(const gstring * g) +{ +return g ? (unsigned)g->ptr : 0; +} + #define gstring_release_unused(g) \ gstring_release_unused_trc(g, __FUNCTION__, __LINE__)