From: Willy Tarreau Date: Fri, 23 Feb 2024 18:51:54 +0000 (+0100) Subject: BUG/MINOR: ist: only store NUL byte on succeeded alloc X-Git-Tag: v3.0-dev4~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4d44250ebda83aac986d94e49004c470a19681e;p=thirdparty%2Fhaproxy.git BUG/MINOR: ist: only store NUL byte on succeeded alloc The trailing NUL added at the end of istdup() by recent commit de0216758 ("BUG/MINOR: ist: allocate nul byte on istdup") was placed outside of the pointer validity test, rightfully showing null deref warnings. This fix should be backported along with the fix above, to the same versions. --- diff --git a/include/import/ist.h b/include/import/ist.h index aff799dcb4..e4e1425d6f 100644 --- a/include/import/ist.h +++ b/include/import/ist.h @@ -944,8 +944,8 @@ static inline struct ist istdup(const struct ist src) if (isttest(dst)) { istcpy(&dst, src, src.len); + dst.ptr[dst.len] = '\0'; } - dst.ptr[dst.len] = '\0'; return dst; }