* [PATCH] Documentation: Fix size parameter for snprintf (reported by cppcheck)
@ 2013-12-30 11:35 Stefan Weil
0 siblings, 0 replies; only message in thread
From: Stefan Weil @ 2013-12-30 11:35 UTC (permalink / raw)
To: trivial; +Cc: Rob Landley, linux-doc, linux-kernel, Stefan Weil
cppcheck reports this error:
Documentation/laptops/hpfall.c:33]: (error)
Dangerous usage of 'devname' (strncpy doesn't always 0-terminate it)
The terminating '\0' is needed for the global char array unload_heads_path,
so never write the last array entry (which is initially '\0').
Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
This is only code in the documentation, nevertheless even there a correction
might help other users.
Cheers and happy new year
Stefan Weil
Documentation/laptops/hpfall.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Documentation/laptops/hpfall.c b/Documentation/laptops/hpfall.c
index a4a8fc5..b85dbba 100644
--- a/Documentation/laptops/hpfall.c
+++ b/Documentation/laptops/hpfall.c
@@ -29,7 +29,7 @@ int set_unload_heads_path(char *device)
return -EINVAL;
strncpy(devname, device + 5, sizeof(devname));
- snprintf(unload_heads_path, sizeof(unload_heads_path),
+ snprintf(unload_heads_path, sizeof(unload_heads_path) - 1,
"/sys/block/%s/device/unload_heads", devname);
return 0;
}
--
1.7.10.4
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2013-12-30 11:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-30 11:35 [PATCH] Documentation: Fix size parameter for snprintf (reported by cppcheck) Stefan Weil
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®