]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: ist: only store NUL byte on succeeded alloc
authorWilly Tarreau <w@1wt.eu>
Fri, 23 Feb 2024 18:51:54 +0000 (19:51 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 23 Feb 2024 18:51:54 +0000 (19:51 +0100)
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.

include/import/ist.h

index aff799dcb4227adc144a4c925c8f779aea77a6c3..e4e1425d6fd984c58ff569327e308d34c723a979 100644 (file)
@@ -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;
 }