public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Documentation: laptops: freefall.c:  Cleaning up missing null-terminate in conjunction with strncpy
@ 2014-07-27 14:40 Rickard Strandqvist
  2014-07-27 19:29 ` Pavel Machek
  2014-07-27 23:03 ` Randy Dunlap
  0 siblings, 2 replies; 7+ messages in thread
From: Rickard Strandqvist @ 2014-07-27 14:40 UTC (permalink / raw)
  To: Randy Dunlap, Rickard Strandqvist
  Cc: Pavel Machek, Pali Rohár, Stefan Weil, Jiri Kosina,
	linux-doc, linux-kernel

Added a guaranteed null-terminate after call to strncpy.

Signed-off-by: Rickard Strandqvist <rickard_strandqvist@spectrumdigital.se>
---
 Documentation/laptops/freefall.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Documentation/laptops/freefall.c b/Documentation/laptops/freefall.c
index aab2ff0..113d004 100644
--- a/Documentation/laptops/freefall.c
+++ b/Documentation/laptops/freefall.c
@@ -33,8 +33,10 @@ static int set_unload_heads_path(char *device)
 
 	if (strlen(device) <= 5 || strncmp(device, "/dev/", 5) != 0)
 		return -EINVAL;
-	strncpy(devname, device + 5, sizeof(devname) - 1);
-	strncpy(device_path, device, sizeof(device_path) - 1);
+	strncpy(devname, device + 5, sizeof(devname));
+	devname[sizeof(devname) - 1] = '\0';
+	strncpy(device_path, device, sizeof(device_path));
+	device_path[sizeof(device_path) - 1] = '\0';
 
 	snprintf(unload_heads_path, sizeof(unload_heads_path) - 1,
 				"/sys/block/%s/device/unload_heads", devname);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-07-29  0:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-27 14:40 [PATCH] Documentation: laptops: freefall.c: Cleaning up missing null-terminate in conjunction with strncpy Rickard Strandqvist
2014-07-27 19:29 ` Pavel Machek
2014-07-27 23:03 ` Randy Dunlap
2014-07-28 10:20   ` Pavel Machek
2014-07-28 11:10     ` [PATCHv2] Documentation: laptops: freefall.c: Fix missing null-termination Pavel Machek
2014-07-28 11:13     ` [PATCHv3] Documentation: laptops: freefall.c: simplify to avoid null-termination problems Pavel Machek
2014-07-29  0:17       ` Randy Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox