]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: stats: use strncmp() instead of memcmp() on health states
authorWilly Tarreau <w@1wt.eu>
Tue, 11 Aug 2020 08:26:36 +0000 (10:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 11 Aug 2020 08:26:36 +0000 (10:26 +0200)
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.

src/stats.c

index 562cd82733a50f4db734f6fc5477aa4fb4f14917..5248a6c2f9f03dd77219e4046e24ad09c3e101b5 100644 (file)
@@ -935,7 +935,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, "<tr class=\"maintain\">");
                else
                        chunk_appendf(out,
@@ -1107,15 +1107,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, "<i>no check</i>");
                }
                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, " &uarr;");
                        }
@@ -1123,7 +1123,7 @@ static int stats_dump_fields_html(struct buffer *out,
                                chunk_strcat(out, " &darr;");
                }
 
-               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,
                                      "</td><td class=ac><u> %s",