batctl: Merge bugfixes from v2017.4
[feed/routing.git] / batctl / patches / 0012-batctl-Simplify-concatenation-of-pathnames.patch
1 From: Sven Eckelmann <sven.eckelmann@openmesh.com>
2 Date: Thu, 23 Nov 2017 15:04:44 +0100
3 Subject: [PATCH] batctl: Simplify concatenation of pathnames
4
5 The combination of strncpy and strncat is hard to read and it is rather
6 easy to introduce some kind of problems when using that. The usage of
7 snprintf simplifies it slightly.
8
9 Signed-off-by: Sven Eckelmann <sven.eckelmann@openmesh.com>
10 Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
11
12 Origin: upstream, https://git.open-mesh.org/batctl.git/commit/cfaec23c5f6f2cf649f3e0673b2e0c61bc01969f
13 ---
14 bat-hosts.c | 4 +---
15 functions.c | 8 ++------
16 2 files changed, 3 insertions(+), 9 deletions(-)
17
18 diff --git a/bat-hosts.c b/bat-hosts.c
19 index a4add34bbaf8c34f8357ba8d1583218fdaf4df93..66e8f05bd2277e5560be77a26b97245223fa72aa 100644
20 --- a/bat-hosts.c
21 +++ b/bat-hosts.c
22 @@ -194,9 +194,7 @@ void bat_hosts_init(int read_opt)
23 if (!homedir)
24 continue;
25
26 - strncpy(confdir, homedir, CONF_DIR_LEN);
27 - confdir[CONF_DIR_LEN - 1] = '\0';
28 - strncat(confdir, &bat_hosts_path[i][1], CONF_DIR_LEN - strlen(confdir) - 1);
29 + snprintf(confdir, CONF_DIR_LEN, "%s%s", homedir, &bat_hosts_path[i][1]);
30 } else {
31 strncpy(confdir, bat_hosts_path[i], CONF_DIR_LEN);
32 confdir[CONF_DIR_LEN - 1] = '\0';
33 diff --git a/functions.c b/functions.c
34 index 676012bb56f9f8aa757b4805e27d904181ee2d27..1c96e6241d01b83a136ff135bee8dd780629f7aa 100644
35 --- a/functions.c
36 +++ b/functions.c
37 @@ -208,9 +208,7 @@ int read_file(const char *dir, const char *fname, int read_opt,
38 if (read_opt & USE_BAT_HOSTS)
39 bat_hosts_init(read_opt);
40
41 - strncpy(full_path, dir, sizeof(full_path));
42 - full_path[sizeof(full_path) - 1] = '\0';
43 - strncat(full_path, fname, sizeof(full_path) - strlen(full_path) - 1);
44 + snprintf(full_path, sizeof(full_path), "%s%s", dir, fname);
45
46 open:
47 line = 0;
48 @@ -349,9 +347,7 @@ int write_file(const char *dir, const char *fname, const char *arg1,
49 char full_path[500];
50 ssize_t write_len;
51
52 - strncpy(full_path, dir, sizeof(full_path));
53 - full_path[sizeof(full_path) - 1] = '\0';
54 - strncat(full_path, fname, sizeof(full_path) - strlen(full_path) - 1);
55 + snprintf(full_path, sizeof(full_path), "%s%s", dir, fname);
56
57 fd = open(full_path, O_WRONLY);
58