[PATCH] lib: fwts_framework: ensure we don't truncate null names
Colin King
colin.king at canonical.com
Tue May 7 09:10:25 UTC 2013
From: Colin Ian King <colin.king at canonical.com>
Coverity CID #997295: Dereference after null check
minor_test->name may be null, so the call
fwts_framework_strtrunc(namebuf, minor_test->name, sizeof(namebuf))
can cause problems. Make fwts_framework_strtrunc handle null strings.
Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
src/lib/src/fwts_framework.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
index 857b54e..adb46c8 100644
--- a/src/lib/src/fwts_framework.c
+++ b/src/lib/src/fwts_framework.c
@@ -291,7 +291,10 @@ static void fwts_framework_show_tests(fwts_framework *fw, bool full)
*/
static void fwts_framework_strtrunc(char *dest, const char *src, size_t max)
{
- strncpy(dest, src, max);
+ if (src)
+ strncpy(dest, src, max);
+ else
+ strncpy(dest, "", max);
if ((strlen(src) > max) && (max > 3)) {
dest[max-1] = 0;
--
1.8.1.2
More information about the fwts-devel
mailing list