Blame SOURCES/0108-lnstat_util-Simplify-alloc_and_open-a-bit.patch

36cfb7
From 5cdf4d78d15b127d0f4a7a09e4700d7df16dda19 Mon Sep 17 00:00:00 2001
36cfb7
From: Andrea Claudi <aclaudi@redhat.com>
36cfb7
Date: Mon, 29 Apr 2019 20:08:08 +0200
36cfb7
Subject: [PATCH] lnstat_util: Simplify alloc_and_open() a bit
36cfb7
36cfb7
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1465646
36cfb7
Upstream Status: iproute2.git commit bc27878d21909
36cfb7
36cfb7
commit bc27878d21909b110dd21eea0c3505d023f29dc2
36cfb7
Author: Phil Sutter <phil@nwl.cc>
36cfb7
Date:   Thu Aug 24 11:51:48 2017 +0200
36cfb7
36cfb7
    lnstat_util: Simplify alloc_and_open() a bit
36cfb7
36cfb7
    Relying upon callers and using unsafe strcpy() is probably not the best
36cfb7
    idea. Aside from that, using snprintf() allows to format the string for
36cfb7
    lf->path in one go.
36cfb7
36cfb7
    Signed-off-by: Phil Sutter <phil@nwl.cc>
36cfb7
---
36cfb7
 misc/lnstat_util.c | 7 ++-----
36cfb7
 1 file changed, 2 insertions(+), 5 deletions(-)
36cfb7
36cfb7
diff --git a/misc/lnstat_util.c b/misc/lnstat_util.c
36cfb7
index cc54598fe1bef..ec19238c24b94 100644
36cfb7
--- a/misc/lnstat_util.c
36cfb7
+++ b/misc/lnstat_util.c
36cfb7
@@ -180,11 +180,8 @@ static struct lnstat_file *alloc_and_open(const char *path, const char *file)
36cfb7
 	}
36cfb7
 
36cfb7
 	/* initialize */
36cfb7
-	/* de->d_name is guaranteed to be <= NAME_MAX */
36cfb7
-	strcpy(lf->basename, file);
36cfb7
-	strcpy(lf->path, path);
36cfb7
-	strcat(lf->path, "/");
36cfb7
-	strcat(lf->path, lf->basename);
36cfb7
+	snprintf(lf->basename, sizeof(lf->basename), "%s", file);
36cfb7
+	snprintf(lf->path, sizeof(lf->path), "%s/%s", path, file);
36cfb7
 
36cfb7
 	/* initialize to default */
36cfb7
 	lf->interval.tv_sec = 1;
36cfb7
-- 
e138d9
2.21.0
36cfb7