[PATCH] lib: fwts_args: use safer strncat than strcat

Colin King colin.king at canonical.com
Fri Jan 15 13:47:05 UTC 2016


From: Colin Ian King <colin.king at canonical.com>

Fix warning from static analysis that was complaining that strcat
is not safe, and use strncat instead.  Replace a strncat with
a few simply char ptr assignments since we know at that point
this is safe (we have enough buffer space) and we only have a few
chars to set.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/lib/src/fwts_args.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
index 1d7a4a0..43c8ee8 100644
--- a/src/lib/src/fwts_args.c
+++ b/src/lib/src/fwts_args.c
@@ -284,6 +284,7 @@ void fwts_args_show_options(void)
 		char buffer[80];
 		char *ptr = buffer;
 		fwts_option *option = fwts_list_data(fwts_option *, item);
+		size_t n = sizeof(buffer) - 1;
 
 		/* Format up short name, skip over : fields */
 		*ptr = '\0';
@@ -296,11 +297,14 @@ void fwts_args_show_options(void)
 					*ptr++ = ',';
 					*ptr++ = ' ';
 					*ptr = '\0';
+					n -= 4;
 				}
 			}
 		}
-		strcat(ptr, "--");
-		strcat(ptr, option->long_name);
+		*ptr++ = '-';
+		*ptr++ = '-';
+		*ptr = '\0';
+		strncat(ptr, option->long_name, n - 2);
 
 		fwts_args_show_option(width, buffer, option->explanation);
 	}
-- 
2.7.0.rc3




More information about the fwts-devel mailing list