From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4BB0148C55; Sun, 7 Dec 2025 20:13:28 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D0C0A40658; Sun, 7 Dec 2025 20:13:01 +0100 (CET) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by mails.dpdk.org (Postfix) with ESMTP id 155F940156 for ; Sun, 7 Dec 2025 20:13:00 +0100 (CET) Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-477b198f4bcso32070725e9.3 for ; Sun, 07 Dec 2025 11:13:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1765134780; x=1765739580; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zTtUKeUg/Ljll5X+Z97SOdDf/8WMPP7rUAcvn3wI2AI=; b=PoP2NA0H/JQC2Mr7XqUbUx6b8eu3cp8myZoCcFhmJItui0lcBs1LfCOK+to4ur+Uik Us+pdINPrlSAF2LsGlRcl4xyoJrqDZHs5/eiNciNrtxgBGTySvkN9JZMJOgyA8/5iXEu MyK48uz0Xp2TFeOrCZulweTeOYq8naNqNSNglmTsJlaN8Z7B3c5iW7gSFFExCVoyvP30 4qxPBydW/zPjR3YlXfG9MUfd86LF2uFVpQpUD38El3F4jMO+WQOGUa68GbhLlMV5f0RZ urqyF5vr+UuhgUI952qZ8IlIOTYNKbV7wXkQosfmX4XjrSmk40Brmqrf+azd8o44bClK ZiIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765134780; x=1765739580; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:c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nI7OdBjYPEIrR3TZFcZDn5BmS0ItUyYvUzzCQ/HR+Rm X-Google-Smtp-Source: AGHT+IGqtd+mkqrTcPj5R5Rxpvn9I/r2AIGyIBPmoe06OpJQkDH/sJWnwzYB60N0wZRR3XvFH7IgWg== X-Received: by 2002:a05:600c:3b8b:b0:477:af07:dd17 with SMTP id 5b1f17b1804b1-47939e3897cmr85403755e9.24.1765134779627; Sun, 07 Dec 2025 11:12:59 -0800 (PST) Received: from phoenix.lan (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-479310b8e70sm205124205e9.5.2025.12.07.11.12.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Dec 2025 11:12:59 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Bruce Richardson Subject: [PATCH v5 06/17] telemetry: avoid possible string overflow Date: Sun, 7 Dec 2025 11:11:57 -0800 Message-ID: <20251207191242.165619-7-stephen@networkplumber.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251207191242.165619-1-stephen@networkplumber.org> References: <20251205022948.327743-1-stephen@networkplumber.org> <20251207191242.165619-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When registering client the input parameter could have a too large unix domain path. Improve the string handling by avoiding temporary buffer, and check the length. Signed-off-by: Stephen Hemminger --- lib/telemetry/telemetry_legacy.c | 37 +++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/telemetry/telemetry_legacy.c b/lib/telemetry/telemetry_legacy.c index 89ec750c09..24f663eee7 100644 --- a/lib/telemetry/telemetry_legacy.c +++ b/lib/telemetry/telemetry_legacy.c @@ -82,34 +82,41 @@ static int register_client(const char *cmd __rte_unused, const char *params, char *buffer __rte_unused, int buf_len __rte_unused) { + const char *colon = strchr(params, ':'); + + if (colon == NULL) { + fprintf(stderr, "Invalid client data: missing colon\n"); + return -1; + } + #ifndef RTE_EXEC_ENV_WINDOWS pthread_t th; - char data[BUF_SIZE]; - int fd; - int rc; - struct sockaddr_un addrs; -#endif /* !RTE_EXEC_ENV_WINDOWS */ + int fd, rc; + struct sockaddr_un addrs = { .sun_family = AF_UNIX }; - if (!strchr(params, ':')) { - fprintf(stderr, "Invalid data\n"); + if (colon[1] != '"') { + fprintf(stderr, "Invalid client data: missing quote\n"); return -1; } -#ifndef RTE_EXEC_ENV_WINDOWS - strlcpy(data, strchr(params, ':'), sizeof(data)); - memmove(data, &data[strlen(":\"")], strlen(data)); - if (!strchr(data, '\"')) { - fprintf(stderr, "Invalid client data\n"); + + const char *endquote = strchr(colon + 1, '"'); + if (endquote == NULL) { + fprintf(stderr, "Invalid client data: missing end quote\n"); + return -1; + } + + size_t len = endquote - colon + 1; + if (len == 0 || len >= sizeof(addrs.sun_path)) { + fprintf(stderr, "Invalid client data: path length\n"); return -1; } - *strchr(data, '\"') = 0; + strncpy(addrs.sun_path, colon + 1, len); fd = socket(AF_UNIX, SOCK_SEQPACKET, 0); if (fd < 0) { perror("Failed to open socket"); return -1; } - addrs.sun_family = AF_UNIX; - strlcpy(addrs.sun_path, data, sizeof(addrs.sun_path)); if (connect(fd, (struct sockaddr *)&addrs, sizeof(addrs)) == -1) { perror("\nClient connection error\n"); -- 2.51.0