]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: stats: make field_str() return an empty string on NULL
authorWilly Tarreau <w@1wt.eu>
Sat, 26 Nov 2016 14:55:59 +0000 (15:55 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 26 Nov 2016 14:58:37 +0000 (15:58 +0100)
It already returns an empty string when the field is empty, but as a
preventive measure we should do the same when the string itself is a
NULL. While it is not supposed to happen, it will make the code more
resistant against failed allocations and unexpected results.

This fix should be backported to 1.7.

include/proto/stats.h

index 7fab87d07c41f705dd6f06311b2bcafde6ed8586..ac893b843c189e2fef03864a02b3697c28affc7b 100644 (file)
@@ -50,7 +50,7 @@ static inline enum field_nature field_nature(const struct field *f, int e)
 
 static inline const char *field_str(const struct field *f, int e)
 {
-       return (field_format(f, e) == FF_STR) ? f[e].u.str : "";
+       return (field_format(f, e) == FF_STR && f[e].u.str) ? f[e].u.str : "";
 }
 
 static inline struct field mkf_s32(uint32_t type, int32_t value)