From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4D9B46A8D2 for ; Tue, 9 Apr 2024 06:23:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712643834; cv=none; b=E+q8evPxDJsfQJd/69pR2tyGytktQQArXS3Acxw8W6RzLudnx42nAFt4uDnlo+VF6jKQAVG5G6ym3lPx91m31FoM7VP+YUOuHbv/ZNgctsk8DcIMIz4RO3Gdue6gcI2Jmc67f5R6fcdY9RCuGV8MWLx171F7QhJOm1cdqM+AsiU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712643834; c=relaxed/simple; bh=4FCqcdUY4noIr3hyXGLjsXuMQ28NOckQh0S4mytZc+w=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WDbKlUyza/LIJI0x62OTYBUO1gB8BtPqj6iEi1qgHQSOhUyPSCp7M520tse2ZZikcm8odP8edvOEhQOIQgm56zXQx+QFoQX1o3x2JB580fPjENito2yRyAN7hCUW2j//ycL5cuvsrF5EUQSMTQuf6r4vqTQOz7l04pIBiaFRCtU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=clg42iu6; arc=none smtp.client-ip=209.85.208.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="clg42iu6" Received: by mail-lj1-f172.google.com with SMTP id 38308e7fff4ca-2d8743ecebdso32471741fa.1 for ; Mon, 08 Apr 2024 23:23:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712643830; x=1713248630; darn=lists.linux.dev; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ZGaOLMAwWEbHzlVvJbIY7WaGUlj5DXjFn2iEaNlsiUw=; b=clg42iu6veBlSCbZePqcFSRYiJvB0YyTclJG2FJJidXYjZb4FDcIAW3srs0D3jCYki aNJW1WkLYMes1UAmy4QmIgNsHJIJv/zGIvpoEKd7KRNAmCqD+UnR9eEutY8cbvSQUzos gZTuc7lRQE6/GtK80wNaKziUxOB4RahnghiK1liQv/Nyr9yDN80d7K450d+5Zk9/1bQb aG6nVzh/YjzeUVqgC7GfvDhBcqQWg28xJWBo7p52ZlyAFvbjzosfW0ZUWu8zCwaWqixS ov50+XNaQfadTpOIY12nybApsPkmLKGPor6uF28jVFtXR5/J0h25ruaeFwnDVZrY3t3B iUDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712643830; x=1713248630; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ZGaOLMAwWEbHzlVvJbIY7WaGUlj5DXjFn2iEaNlsiUw=; b=WVoGhNqPji0o0koKUle3219udytgSWF5QyC/hGu9x/EdK8LPrrkQHtkgqLrQkmmngP QgnyWF2NY8DWYD8NFGWeLNgcBs5YGUnQbzidgocygj+oswQTQytdzXQjOQdfPLrTadQj nJUED5tn59jC1vCkEmC9Ea0xLJqhx3CxHm7t/LQ8KeJ3AVZtTNsQrqfuKInbwc/0z1n6 8ybW5l3z3HmpA7hRbDrmvbfu4oD30JEqIs1Ez6YWAM2dRTWBSVlRLwD56mfgJOTpTZom xxWCZu7raJj7uKjau8So5sVTQHMR0sL0NcjGU8cHTTvQnQvQraPypEbC/Hhz+TkAQXSR biow== X-Forwarded-Encrypted: i=1; AJvYcCWPzuOqwDUnPPR1sMzoJsMSxBxdE4KLNkNlc215XXHI4adobgFLeWXf01W5CcV2Rdn7YNGAninOexLxW3jrBbblqk1sZxEn7fjAHmUf2g== X-Gm-Message-State: AOJu0YxOHpylwFKK/4N5oQAsgWsMaDguqcDmWX/lUAQ6eo+ZzXxRI5C/ dYu+lg//qlY99ib1YbZRJ+oGDjV45KSDTxWJP4xCegg6v9pYmGuo/NKMh8ElpS8= X-Google-Smtp-Source: AGHT+IHic/ZFaZhwMq0y4OXitpFTOZ7AWtJP5xJ2fYwTZegcmgvKhST0G6zJfdaUu3/vRXpLi4IcoA== X-Received: by 2002:ac2:59d0:0:b0:513:30fb:d64 with SMTP id x16-20020ac259d0000000b0051330fb0d64mr8012172lfn.44.1712643830122; Mon, 08 Apr 2024 23:23:50 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id b93-20020a509f66000000b0056e0376286bsm5021838edf.24.2024.04.08.23.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 23:23:49 -0700 (PDT) Date: Tue, 9 Apr 2024 09:23:45 +0300 From: Dan Carpenter To: Arnd Bergmann Cc: Greg Kroah-Hartman , Justin Stitt , Arnd Bergmann , linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] [v2] staging: rts5208: replace weird strncpy() with memcpy() Message-ID: References: <20240408194821.3183462-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-staging@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240408194821.3183462-1-arnd@kernel.org> On Mon, Apr 08, 2024 at 09:48:09PM +0200, Arnd Bergmann wrote: > From: Arnd Bergmann > > When -Wstringop-truncation is enabled, gcc finds a function that > always does a short copy: > > In function 'inquiry', > inlined from 'rtsx_scsi_handler' at drivers/staging/rts5208/rtsx_scsi.c:3210:12: > drivers/staging/rts5208/rtsx_scsi.c:526:17: error: 'strncpy' output truncated copying between 1 and 28 bytes from a string of length 28 [-Werror=stringop-truncation] > 526 | strncpy(buf + 8, inquiry_string, sendbytes - 8); > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > The code originally had a memcpy() that would overread the source string, > and commit 88a5b39b69ab ("staging/rts5208: Fix read overflow in memcpy") > fixed this but introduced the warning about truncation in the process. > > As Dan points out, the final space in the inquiry_string always gets > cut off, so remove it here for clarity, leaving exactly the 28 non-NUL > characters that can get copied into the output. In the 'pro_formatter_flag' > this is followed by another 20 bytes from the 'formatter_inquiry_str' > array, but there the output never contains a NUL-termination, and the > length is known, so memcpy() is the more logical choice. > > Cc: Dan Carpenter > Link: https://lore.kernel.org/lkml/695be581-548f-4e5e-a211-5f3b95568e77@moroto.mountain/ > Signed-off-by: Arnd Bergmann > --- > v2: remove unneeded space byte from input string for clarity, > rework changelog text Reviewed-by: Dan Carpenter regards, dan carpenter