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