From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by dpdk.org (Postfix) with ESMTP id C2A691B505 for ; Mon, 7 Jan 2019 21:22:35 +0100 (CET) Received: by mail-pl1-f169.google.com with SMTP id p8so684136plo.2 for ; Mon, 07 Jan 2019 12:22:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tC0EitVnRs5SM83dxSdlWIk8W2il3QguQIotfdT/UWA=; b=h8LMzgG/lZ0r8kPqjEG+6Q/b9hiiQaKkn7Sepf4PUXyx/VrPFzQWDd3Y2OCT6vKvBx 5mACcx1XILXBFaqCgUTCG/saasDK68IME6ticRB6EEAIJn6IkfgabT3c3D5gIlZ9Ep/M h4uZz++AjqAs+t5jFzXdrcuDEFA5ufv17alRh1slFrRxFC7mHfQH5D/axSKQ23Zsjg58 8I2Y5fcgrQ+Bdsn0YnpP5XuzH4pVWmy6KZ4ZhoWMD8VhJVX1WV9xlSzJ+1InQS4t25NN UUTT8ye0aJfXKN/CHYokpPfaODQdLSFZ94FXlzpXpLNmz7jujpqP1EmfOtWLUetjWAEm lUXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tC0EitVnRs5SM83dxSdlWIk8W2il3QguQIotfdT/UWA=; b=Wnrgzo7Q8zhk4PZ+LBBDTYBShnnq0X9l3eYVu29dyzLl+vpAFLOii9GWLp+01sIh1O XyT8Fl1E1H9DA2egLVJUe/bWV5glY/XmbrPt3xAg0Py3+oqDExlFGuAIiScmc5hxi1s1 3pSQMn5PbnnufKORSRKbgnS5H+h8M+6M1tF0+rMUCfLmatjaS6hP4rYWjFERJ29NCl8B Rxk87hhlNf5rbFcTIO1vnu6CoxaWK/HBfdP/odgyuWHx/CWmadNkrTsbunTfTq4yToaQ Yu6nLIqsI9oD+rakRIZWLkymkrqkblM3+jyDiyVwpuA3nZm0RVEz6hK73oCjkMmzN7Xx D9Yw== X-Gm-Message-State: AJcUukev/7rYA5+5bJr0cfIaLPpvOf903bepaCAbISgHG350OJwfeCTv 3P+PPUhz9yJv7FExD2cXlcF1+LWCwi0= X-Google-Smtp-Source: ALg8bN7m7iW1ltugQRUKnHEiPWO+4zZ09MnxYggMQGiDpVTSlLHcaAb67jo0M9KRex6y3eD70gPt3w== X-Received: by 2002:a17:902:b90b:: with SMTP id bf11mr61930199plb.284.1546892554069; Mon, 07 Jan 2019 12:22:34 -0800 (PST) Received: from hermes.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id 4sm110701409pfq.10.2019.01.07.12.22.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Jan 2019 12:22:32 -0800 (PST) From: Stephen Hemminger X-Google-Original-From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 7 Jan 2019 12:22:25 -0800 Message-Id: <20190107202225.4249-1-sthemmin@microsoft.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH] [pktgen] Fix string truncation warnings X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jan 2019 20:22:39 -0000 From: Stephen Hemminger The strncatf macro will cause warnings with latest GCC if the sizeof the destination buffer is smaller than the temporary buffer. Resolve by adjusting buffer sizes. Such as: git/pktgen-dpdk/app/pktgen-capture.c: In function ‘pktgen_set_capture’: git/pktgen-dpdk/app/pktgen-log.h:114:3: error: ‘strncat’ output may be truncated copying between 0 and 255 bytes from a string of length 1022 [-Werror=stringop-truncation] strncat(dest, _buff, sizeof(dest) - strlen(dest) - 1); \ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ git/pktgen-dpdk/app/pktgen-capture.c:246:7: note: in expansion of macro ‘strncatf’ strncatf(status, "%d%%", pct); ^~~~~~~~ cc1: all warnings being treated as errors Signed-off-by: Stephen Hemminger --- app/pktgen-capture.c | 2 +- app/pktgen-log.h | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/pktgen-capture.c b/app/pktgen-capture.c index aee4ff9bd650..0f3f42bdc488 100644 --- a/app/pktgen-capture.c +++ b/app/pktgen-capture.c @@ -200,7 +200,7 @@ found_rx_lid: size_t mem_dumped = 0; unsigned int pct = 0; - char status[256]; + char status[1024]; sprintf( status, "\r Dumping ~%.2fMB of captured data to disk: 0%%", diff --git a/app/pktgen-log.h b/app/pktgen-log.h index 46e347b72b3f..8d132d88c748 100644 --- a/app/pktgen-log.h +++ b/app/pktgen-log.h @@ -108,11 +108,11 @@ extern "C" { * arguments. It formats the string and appends it to the existing string, while * avoiding possible buffer overruns. */ -#define strncatf(dest, fmt, ...) do { \ - char _buff[1024]; \ - snprintf(_buff, sizeof(_buff), fmt, ## __VA_ARGS__); \ - strncat(dest, _buff, sizeof(dest) - strlen(dest) - 1); \ -} while (0) +#define strncatf(dest, fmt, ...) do { \ + char _buff[1023]; \ + snprintf(_buff, sizeof(_buff), fmt, ## __VA_ARGS__); \ + strncat(dest, _buff, sizeof(dest) - strlen(dest) - 1); \ + } while (0) /* Initialize log data structures */ void pktgen_init_log(void); -- 2.20.1