]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: tree-wide: remove strpcy() from constant strings
authorWilly Tarreau <w@1wt.eu>
Fri, 7 Apr 2023 16:11:39 +0000 (18:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 7 Apr 2023 16:14:28 +0000 (18:14 +0200)
These ones are genenerally harmless on modern compilers because the
compiler checks them. While gcc optimizes them away without even
referencing strcpy(), clang prefers to call strcpy(). Nevertheless they
prevent from enabling stricter checks so better remove them altogether.
They were all replaced by strlcpy2() and the size of the destination
which is always known there.

src/clock.c
src/frontend.c
src/proto_tcp.c
src/server.c
src/stats.c

index 59ec173c186f4a0cfc8d33783a7ad788d0028f14..e8520357936ff8fb8f4622af78e604f090691950 100644 (file)
@@ -415,7 +415,7 @@ char *timeofday_as_iso_us(int pad)
                get_localtime(new_date.tv_sec, &tm);
                offset = get_gmt_offset(new_date.tv_sec, &tm);
                if (unlikely(strftime(iso_time_str, sizeof(iso_time_str), "%Y-%m-%dT%H:%M:%S.000000+00:00", &tm) != 32))
-                       strcpy(iso_time_str, "YYYY-mm-ddTHH:MM:SS.000000-00:00"); // make the failure visible but respect format.
+                       strlcpy2(iso_time_str, "YYYY-mm-ddTHH:MM:SS.000000-00:00", sizeof(iso_time_str)); // make the failure visible but respect format.
                iso_time_str[26] = offset[0];
                iso_time_str[27] = offset[1];
                iso_time_str[28] = offset[2];
index 33d66df7bd62c1d16af8f33197a84871dcb1fbc3..0c2fb9cd08a6b5b4798e6465068bbac75e7749b4 100644 (file)
@@ -78,7 +78,7 @@ int frontend_accept(struct stream *s)
                                                addr_to_str(dst, sn, sizeof(sn));
                                                port = get_host_port(dst);
                                        } else {
-                                               strcpy(sn, "undetermined address");
+                                               strlcpy2(sn, "undetermined address", sizeof(sn));
                                                port = 0;
                                        }
                                        send_log(fe, LOG_INFO, "Connect from %s:%d to %s:%d (%s/%s)\n",
index 7a8d83070db620bed2c7294960800bf71664b21e..30c2e11dd755a571c409ce28ea83c4a469a4ac31 100644 (file)
@@ -709,7 +709,7 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
        if (listener->bind_conf->options & BC_O_DEF_ACCEPT) {
                struct accept_filter_arg accept;
                memset(&accept, 0, sizeof(accept));
-               strcpy(accept.af_name, "dataready");
+               strlcpy2(accept.af_name, sizeof(accept.af_name), "dataready");
                if (setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, &accept, sizeof(accept)) == -1) {
                        chunk_appendf(msg, "%scannot enable ACCEPT_FILTER", msg->data ? ", " : "");
                        err |= ERR_WARN;
index f18fc5b2b1d1423c545f88bc096e5a1d4373cfa6..add9d77e106630db17f3d315fa6d9489b3e9d901 100644 (file)
@@ -3182,7 +3182,7 @@ int srv_update_addr(struct server *s, void *ip, int ip_sin_family, const char *u
                        inet_ntop(s->addr.ss_family, &((struct sockaddr_in6 *)&s->addr)->sin6_addr, oldip, INET6_ADDRSTRLEN);
                        break;
                default:
-                       strcpy(oldip, "(none)");
+                       strlcpy2(oldip, "(none)", sizeof(oldip));
                        break;
                };
 
index a90a39c43748253af62846b8d508593fc7560655..18a5f017995cd6ff716cd2c63e4144d9613d58f0 100644 (file)
@@ -2994,7 +2994,7 @@ static void stats_dump_html_px_hdr(struct stconn *sc, struct proxy *px)
                if (ctx->scope_len) {
                        const char *scope_ptr = stats_scope_ptr(appctx, sc);
 
-                       strcpy(scope_txt, STAT_SCOPE_PATTERN);
+                       strlcpy2(scope_txt, STAT_SCOPE_PATTERN, sizeof(scope_txt));
                        memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, ctx->scope_len);
                        scope_txt[strlen(STAT_SCOPE_PATTERN) + ctx->scope_len] = 0;
                }
@@ -3645,7 +3645,7 @@ static void stats_dump_html_info(struct stconn *sc, struct uri_auth *uri)
        /* scope_txt = search pattern + search query, ctx->scope_len is always <= STAT_SCOPE_TXT_MAXLEN */
        scope_txt[0] = 0;
        if (ctx->scope_len) {
-               strcpy(scope_txt, STAT_SCOPE_PATTERN);
+               strlcpy2(scope_txt, STAT_SCOPE_PATTERN, sizeof(scope_txt));
                memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, ctx->scope_len);
                scope_txt[strlen(STAT_SCOPE_PATTERN) + ctx->scope_len] = 0;
        }
@@ -4395,7 +4395,7 @@ static int stats_send_http_redirect(struct stconn *sc, struct htx *htx)
        if (ctx->scope_len) {
                const char *scope_ptr = stats_scope_ptr(appctx, sc);
 
-               strcpy(scope_txt, STAT_SCOPE_PATTERN);
+               strlcpy2(scope_txt, STAT_SCOPE_PATTERN, sizeof(scope_txt));
                memcpy(scope_txt + strlen(STAT_SCOPE_PATTERN), scope_ptr, ctx->scope_len);
                scope_txt[strlen(STAT_SCOPE_PATTERN) + ctx->scope_len] = 0;
        }