1 |
commit: 8dbdabcc5e0df8ac36722a4ba7bfe30664cc9919 |
2 |
Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com> |
3 |
AuthorDate: Fri Feb 16 20:04:40 2018 +0000 |
4 |
Commit: William Hubbs <williamh <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Feb 16 20:04:40 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=8dbdabcc |
7 |
|
8 |
start-stop-daemon: clean up string handling |
9 |
|
10 |
src/rc/start-stop-daemon.c | 33 +++++++++++++++++---------------- |
11 |
1 file changed, 17 insertions(+), 16 deletions(-) |
12 |
|
13 |
diff --git a/src/rc/start-stop-daemon.c b/src/rc/start-stop-daemon.c |
14 |
index 54b89b2a..88b1e091 100644 |
15 |
--- a/src/rc/start-stop-daemon.c |
16 |
+++ b/src/rc/start-stop-daemon.c |
17 |
@@ -254,6 +254,7 @@ int main(int argc, char **argv) |
18 |
#endif |
19 |
|
20 |
int opt; |
21 |
+ size_t size = 0; |
22 |
bool start = false; |
23 |
bool stop = false; |
24 |
bool oknodo = false; |
25 |
@@ -287,10 +288,10 @@ int main(int argc, char **argv) |
26 |
char *tmp, *newpath, *np; |
27 |
char *p; |
28 |
char *token; |
29 |
- char exec_file[PATH_MAX]; |
30 |
+ char *exec_file = NULL; |
31 |
struct passwd *pw; |
32 |
struct group *gr; |
33 |
- char line[130]; |
34 |
+ char *line = NULL; |
35 |
FILE *fp; |
36 |
size_t len; |
37 |
mode_t numask = 022; |
38 |
@@ -577,26 +578,22 @@ int main(int argc, char **argv) |
39 |
if (*exec == '/' || *exec == '.') { |
40 |
/* Full or relative path */ |
41 |
if (ch_root) |
42 |
- snprintf(exec_file, sizeof(exec_file), |
43 |
- "%s/%s", ch_root, exec); |
44 |
+ xasprintf(&exec_file, "%s/%s", ch_root, exec); |
45 |
else |
46 |
- snprintf(exec_file, sizeof(exec_file), |
47 |
- "%s", exec); |
48 |
+ xasprintf(&exec_file, "%s", exec); |
49 |
} else { |
50 |
/* Something in $PATH */ |
51 |
p = tmp = xstrdup(getenv("PATH")); |
52 |
- *exec_file = '\0'; |
53 |
+ exec_file = NULL; |
54 |
while ((token = strsep(&p, ":"))) { |
55 |
if (ch_root) |
56 |
- snprintf(exec_file, sizeof(exec_file), |
57 |
- "%s/%s/%s", |
58 |
- ch_root, token, exec); |
59 |
+ xasprintf(&exec_file, "%s/%s/%s", ch_root, token, exec); |
60 |
else |
61 |
- snprintf(exec_file, sizeof(exec_file), |
62 |
- "%s/%s", token, exec); |
63 |
- if (exists(exec_file)) |
64 |
+ xasprintf(&exec_file, "%s/%s", token, exec); |
65 |
+ if (exec_file && exists(exec_file)) |
66 |
break; |
67 |
- *exec_file = '\0'; |
68 |
+ free(exec_file); |
69 |
+ exec_file = NULL; |
70 |
} |
71 |
free(tmp); |
72 |
} |
73 |
@@ -604,6 +601,7 @@ int main(int argc, char **argv) |
74 |
if (start && !exists(exec_file)) { |
75 |
eerror("%s: %s does not exist", applet, |
76 |
*exec_file ? exec_file : exec); |
77 |
+ free(exec_file); |
78 |
exit(EXIT_FAILURE); |
79 |
|
80 |
} |
81 |
@@ -617,7 +615,9 @@ int main(int argc, char **argv) |
82 |
if (interpreted && !pidfile) { |
83 |
fp = fopen(exec_file, "r"); |
84 |
if (fp) { |
85 |
- p = fgets(line, sizeof(line), fp); |
86 |
+ line = NULL; |
87 |
+ getline(&line, &size, fp); |
88 |
+ p = line; |
89 |
fclose(fp); |
90 |
if (p != NULL && line[0] == '#' && line[1] == '!') { |
91 |
p = line + 2; |
92 |
@@ -629,7 +629,8 @@ int main(int argc, char **argv) |
93 |
if (p[len] == '\n') |
94 |
p[len] = '\0'; |
95 |
token = strsep(&p, " "); |
96 |
- strncpy(exec_file, token, sizeof(exec_file)); |
97 |
+ free(exec_file); |
98 |
+ xasprintf(&exec_file, "%s", token); |
99 |
opt = 0; |
100 |
for (nav = argv; *nav; nav++) |
101 |
opt++; |