From: Willy Tarreau Date: Tue, 11 Aug 2020 08:26:36 +0000 (+0200) Subject: BUG/MINOR: stats: use strncmp() instead of memcmp() on health states X-Git-Tag: v2.1.9~43 X-Git-Url: http://git.haproxy.org/?a=commitdiff_plain;h=5e50d2c1f4c237dff5180a4882df88d03a301f69;p=haproxy-2.1.git BUG/MINOR: stats: use strncmp() instead of memcmp() on health states The reports for health states are checked using memcmp() in order to only focus on the first word and possibly ignore trailing %d/%d etc. This makes gcc unhappy about a potential use of "" as the string, which never happens since the string is always set. This resulted in commit c4e6460f6 ("MINOR: build: Disable -Wstringop-overflow.") to silence these messages. However some lengths are incorrect (though cannot cause trouble), and in the end strncmp() is just safer and cleaner. This can be backported to all stable branches as it will shut a warning with gcc 8 and above. (cherry picked from commit 7b52485f1afb7d420633d7794549ec0549d1e2d7) Signed-off-by: Willy Tarreau (cherry picked from commit af400cf0ec9a418ac1f127d9ed696e7807c2f33b) Signed-off-by: Willy Tarreau --- diff --git a/src/stats.c b/src/stats.c index 338987d..94b07eb 100644 --- a/src/stats.c +++ b/src/stats.c @@ -933,7 +933,7 @@ static int stats_dump_fields_html(struct buffer *out, style = "going_down"; } - if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) + if (strncmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) chunk_appendf(out, ""); else chunk_appendf(out, @@ -1097,15 +1097,15 @@ static int stats_dump_fields_html(struct buffer *out, */ - if (memcmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { + if (strncmp(field_str(stats, ST_F_STATUS), "MAINT", 5) == 0) { chunk_appendf(out, "%s MAINT", human_time(stats[ST_F_LASTCHG].u.u32, 1)); } - else if (memcmp(field_str(stats, ST_F_STATUS), "no check", 5) == 0) { + else if (strcmp(field_str(stats, ST_F_STATUS), "no check") == 0) { chunk_strcat(out, "no check"); } else { chunk_appendf(out, "%s %s", human_time(stats[ST_F_LASTCHG].u.u32, 1), field_str(stats, ST_F_STATUS)); - if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { + if (strncmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0) { if (stats[ST_F_CHECK_HEALTH].u.u32) chunk_strcat(out, " ↑"); } @@ -1113,7 +1113,7 @@ static int stats_dump_fields_html(struct buffer *out, chunk_strcat(out, " ↓"); } - if (memcmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && + if (strncmp(field_str(stats, ST_F_STATUS), "DOWN", 4) == 0 && stats[ST_F_AGENT_STATUS].type && !stats[ST_F_AGENT_HEALTH].u.u32) { chunk_appendf(out, " %s",