Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1581033

[PATCH v2 3/3] staging: fbtft: Add check on strlcpy() return value

From "Tobin C. Harding" <me@tobin.cc>
Newsgroups linux.kernel
Subject [PATCH v2 3/3] staging: fbtft: Add check on strlcpy() return value
Date 2017-02-15 04:30 +0100
Message-ID <taYs2-2jy-5@gated-at.bofh.it> (permalink)
References <taYs1-2jy-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Return value of strlcpy() is not checked. Name string is silently
truncated if longer that SPI_NAME_SIZE, whilst not detrimental to
the program logic it would be nice to notify the user. Module is
currently quite verbose, adding extra pr_warn() calls will not overly
impact this verbosity.

Check return value from call to strlcpy(). If source string is
truncated call pr_warn() to notify user.

Signed-off-by: Tobin C. Harding <me@tobin.cc>
---
 drivers/staging/fbtft/fbtft_device.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/fbtft/fbtft_device.c b/drivers/staging/fbtft/fbtft_device.c
index 5fbdd37..78baf46 100644
--- a/drivers/staging/fbtft/fbtft_device.c
+++ b/drivers/staging/fbtft/fbtft_device.c
@@ -1483,7 +1483,13 @@ static int __init fbtft_device_init(void)
 			displays[i].pdev->name = name;
 			displays[i].spi = NULL;
 		} else {
-			strlcpy(displays[i].spi->modalias, name, SPI_NAME_SIZE);
+			size_t len;
+
+			len = strlcpy(displays[i].spi->modalias, name,
+				SPI_NAME_SIZE);
+			if (len >= SPI_NAME_SIZE)
+				pr_warn("modalias (name) truncated to: %s\n",
+					displays[i].spi->modalias);
 			displays[i].pdev = NULL;
 		}
 	}
-- 
2.7.4

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[PATCH v2 0/3] staging: fbtft: Fix buffer overflow vulnerability "Tobin C. Harding" <me@tobin.cc> - 2017-02-15 04:30 +0100
  [PATCH v2 2/3] staging: fbtft: Replace magic number with constant "Tobin C. Harding" <me@tobin.cc> - 2017-02-15 04:30 +0100
    Re: [PATCH v2 2/3] staging: fbtft: Replace magic number with  constant Joe Perches <joe@perches.com> - 2017-02-15 04:40 +0100
  [PATCH v2 3/3] staging: fbtft: Add check on strlcpy() return value "Tobin C. Harding" <me@tobin.cc> - 2017-02-15 04:30 +0100

csiph-web