Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1538301imm; Tue, 2 Oct 2018 09:45:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV63Tw2cuWFpUx4pKvz09F8/NOzuz0xr/4GV/KzxDNG68sfLYsNtI5CdZnANCRDRYY8HjCqVz X-Received: by 2002:a17:902:b10c:: with SMTP id q12-v6mr17677001plr.37.1538498743830; Tue, 02 Oct 2018 09:45:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538498743; cv=none; d=google.com; s=arc-20160816; b=BEahSsPOu9EH5cKjwLqYGQTFm8IKGkY2Esb4eTKV/uMhNDlzZOD71O2ao4LxWPKOYv m64roFbOLPSUF+VhIfkvNucqeyQ8cLxRDCifso/BAciF7szgbjCNjPfvIV9/X+ih5cDb ca7uc32roBveXraV7038owoQJbxoqQJOP7EnfWHMuPJ4ESwA3IaETfkL8yrxJK5iVvE2 BH5L5fK6Vv+8PYd5yuwyr5e2+fpPaOAkfFnRpJ/VuBT3Lb+nJ/c07BQZwtTYzQ2nH4Fb yADjcIwz817Ow+hMuGcBX1dDSBafi4TEq7Sr/CJodBhTB4a9+AlYHTrUqViAFgw5qd3G nlTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=PkBrxHh+dQETCSWOYREyl9ZaCa2nOFIlFDPzVtD0lFw=; b=BctARNYi7mvTRwkynZnwGeoD/LoOBm+zWgr1SxKws1Mw3y1BcjbEoYYQ6CgCbP+7Wn NhTOzSINNVCMF7s77PCI5GiOi9fMG2zwduUc4cBWAWYhFVC6MSxl6QR8zPAliUNmhwtY kCByyBc6YIEaRKx/Ak2h5OXnMebcNLP1qmoOKVKlyUFKQZ9Hx8GbZZPN2t4kixlBrAMw QqbobJVN0wWqLIHqrhGhmvlU9mPWeqenXGBK05Qg8L62NNpWvpIazMHblw+O0BOAwcR8 aPtud2q5hR7W0NWa1u3pwr8kUhtpxu/g2SouhEJnftNq3dlnx86qXfwjx976uIBeTN5G 1EKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W3KjGQRN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z138-v6si17834278pfc.181.2018.10.02.09.45.28; Tue, 02 Oct 2018 09:45:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W3KjGQRN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728836AbeJBWhX (ORCPT + 99 others); Tue, 2 Oct 2018 18:37:23 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:43720 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726819AbeJBWhW (ORCPT ); Tue, 2 Oct 2018 18:37:22 -0400 Received: by mail-wr1-f65.google.com with SMTP id n1-v6so2815658wrt.10 for ; Tue, 02 Oct 2018 08:53:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=PkBrxHh+dQETCSWOYREyl9ZaCa2nOFIlFDPzVtD0lFw=; b=W3KjGQRNW5XdieM3wmkmtoG86n1YA6Wnt0XpqzTipISw502dcmcZZC+FoBaYmb0Dlg qMJULchDD+5L3y3b/L6fG21/mq6FdQplBhwNq9VUGHZipqe51BeDks1lga95TCnm9gyw C12SQ4bD5+RDqvGdrR4+Dx42unG8UFBjP+Izc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=PkBrxHh+dQETCSWOYREyl9ZaCa2nOFIlFDPzVtD0lFw=; b=EiWAIh20b2JaWM9XtA2MiVjOhpr3li8xi/Sylzx9X22VfgSQu7uzgQzgcunwYsa1tE ZC5sDP/SngopU6hVTCKQBd1Q8T0vXoG4yJ1G3NCVuxl8zAkFpmk1qrI/KNBVskyV2g/l 5cE4mYbm+7k1ULXHDwpFqmdIl/Rizl57+nx2EYQZZoA563yWJhTtIhxKF17lkot3oQ5H cVqt7naZ1M/VsiTpILdqIT3wKLl0KTEKkOkSL1TzlQ3XUAkkxraKr9KKZliat/ZIJINv 81JGtMtQbvsni8iOhQyK8YXvo5/Ocp1wVYEvIFsTL9lRwU9Cgs+1zzCZawNUaLtT99Pg Cqdg== X-Gm-Message-State: ABuFfojbx2qav7V77szYByNTNLn9KeWf2wusvVP1pdexSaBgDuOUansc PAMEFPHBotHIa2ZSgJJR4UFCpQ== X-Received: by 2002:adf:ae09:: with SMTP id x9-v6mr5899756wrc.102.1538495598484; Tue, 02 Oct 2018 08:53:18 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.googlemail.com with ESMTPSA id s10-v6sm18011715wmd.22.2018.10.02.08.53.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Oct 2018 08:53:17 -0700 (PDT) Subject: Re: [PATCH v2] kdb: Use strscpy with destination buffer size To: Prarit Bhargava , linux-kernel@vger.kernel.org Cc: Jonathan Toppins , Jason Wessel , kgdb-bugreport@lists.sourceforge.net References: <20180920125914.17920-1-prarit@redhat.com> From: Daniel Thompson Message-ID: <9192af58-7966-c023-8b19-5b291839a228@linaro.org> Date: Tue, 2 Oct 2018 16:53:16 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <20180920125914.17920-1-prarit@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20/09/2018 13:59, Prarit Bhargava wrote: > gcc 8.1.0 warns with: > > kernel/debug/kdb/kdb_support.c: In function ‘kallsyms_symbol_next’: > kernel/debug/kdb/kdb_support.c:239:4: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=] > strncpy(prefix_name, name, strlen(name)+1); > ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > kernel/debug/kdb/kdb_support.c:239:31: note: length computed here > > Use strscpy() with the destination buffer size, and use ellipses when > displaying truncated symbols. > > v2: Use strscpy() > > Signed-off-by: Prarit Bhargava > Cc: Jonathan Toppins > Cc: Jason Wessel > Cc: Daniel Thompson > Cc: kgdb-bugreport@lists.sourceforge.net > --- > kernel/debug/kdb/kdb_io.c | 15 +++++++++------ > kernel/debug/kdb/kdb_private.h | 2 +- > kernel/debug/kdb/kdb_support.c | 10 +++++----- > 3 files changed, 15 insertions(+), 12 deletions(-) > > diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c > index ed5d34925ad0..6a4b41484afe 100644 > --- a/kernel/debug/kdb/kdb_io.c > +++ b/kernel/debug/kdb/kdb_io.c > @@ -216,7 +216,7 @@ static char *kdb_read(char *buffer, size_t bufsize) > int count; > int i; > int diag, dtab_count; > - int key; > + int key, buf_size, ret; > > > diag = kdbgetintenv("DTABCOUNT", &dtab_count); > @@ -336,9 +336,8 @@ static char *kdb_read(char *buffer, size_t bufsize) > else > p_tmp = tmpbuffer; > len = strlen(p_tmp); > - count = kallsyms_symbol_complete(p_tmp, > - sizeof(tmpbuffer) - > - (p_tmp - tmpbuffer)); > + buf_size = sizeof(tmpbuffer) - (p_tmp - tmpbuffer); > + count = kallsyms_symbol_complete(p_tmp, buf_size); > if (tab == 2 && count > 0) { > kdb_printf("\n%d symbols are found.", count); > if (count > dtab_count) { > @@ -350,9 +349,13 @@ static char *kdb_read(char *buffer, size_t bufsize) > } > kdb_printf("\n"); > for (i = 0; i < count; i++) { > - if (WARN_ON(!kallsyms_symbol_next(p_tmp, i))) > + ret = kallsyms_symbol_next(p_tmp, i, buf_size); > + if (WARN_ON(!ret)) > break; I'm getting confused by having two different branches on ret. Don't get a WARN_ON() when ret == -E2BIG? Daniel. > - kdb_printf("%s ", p_tmp); > + if (ret != -E2BIG) > + kdb_printf("%s ", p_tmp); > + else > + kdb_printf("%s... ", p_tmp); > *(p_tmp + len) = '\0'; > } > if (i >= dtab_count)