[PATCH 2/2] nl-pkt-lookup: Be safe and use ARRAY_SIZE() and strncpy()

Thomas Graf tgraf at suug.ch
Wed Aug 27 03:26:37 PDT 2014


Signed-off-by: Thomas Graf <tgraf at suug.ch>
---
 src/nl-pktloc-lookup.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/nl-pktloc-lookup.c b/src/nl-pktloc-lookup.c
index 17c867b..b4e8147 100644
--- a/src/nl-pktloc-lookup.c
+++ b/src/nl-pktloc-lookup.c
@@ -73,8 +73,8 @@ static char *get_align_txt(struct rtnl_pktloc *loc)
 {
 	static char buf[16];
 
-	if (loc->align <= 4)
-		strcpy(buf, align_txt[loc->align]);
+	if (loc->align < ARRAY_SIZE(align_txt))
+		strncpy(buf, align_txt[loc->align], sizeof(buf) - 1);
 	else
 		snprintf(buf, sizeof(buf), "%u", loc->align);
 
-- 
1.9.3




More information about the libnl mailing list