Commit 7d561af4235ffc6c0203fc66d4998c74384c7fa8
allocate listen[] before writing to it...
Yves Rutschle committed on 4/18/2017, 7:04:30 PMParent: cce42c68822f605ff7297c136312af50bfd5fdad
Files changed
systemd-sslh-generator.c | changed |
systemd-sslh-generator.c | ||
---|---|---|
@@ -16,9 +16,9 @@ | ||
16 | 16 | |
17 | 17 | } |
18 | 18 | |
19 | 19 | |
20 | -static int get_listen_from_conf(const char *filename, char **listen) { | |
20 | +static int get_listen_from_conf(const char *filename, char **listen[]) { | |
21 | 21 | config_t config; |
22 | 22 | config_setting_t *setting, *addr; |
23 | 23 | const char *hostname, *port; |
24 | 24 | int len = 0; |
@@ -38,8 +38,9 @@ | ||
38 | 38 | } else { |
39 | 39 | setting = config_lookup(&config, "listen"); |
40 | 40 | if (setting) { |
41 | 41 | len = config_setting_length(setting); |
42 | + *listen = malloc(len * sizeof(**listen)); | |
42 | 43 | for (int i = 0; i < len; i++) { |
43 | 44 | addr = config_setting_get_elem(setting, i); |
44 | 45 | if (! (config_setting_lookup_string(addr, "host", &hostname) && |
45 | 46 | config_setting_lookup_string(addr, "port", &port))) { |
@@ -47,10 +48,10 @@ | ||
47 | 48 | "line %d:Incomplete specification (hostname and port required)\n", |
48 | 49 | config_setting_source_line(addr)); |
49 | 50 | return -1; |
50 | 51 | } else { |
51 | - listen[i] = malloc(strlen(resolve_listen(hostname, port))); | |
52 | - strcpy(listen[i], resolve_listen(hostname, port)); | |
52 | + (*listen)[i] = malloc(strlen(resolve_listen(hostname, port))); | |
53 | + strcpy((*listen)[i], resolve_listen(hostname, port)); | |
53 | 54 | } |
54 | 55 | } |
55 | 56 | } |
56 | 57 | } |
@@ -58,9 +59,9 @@ | ||
58 | 59 | return len; |
59 | 60 | |
60 | 61 | } |
61 | 62 | |
62 | -static int write_socket_unit(FILE *socket, char **listen, int num_addr, const char *source) { | |
63 | +static int write_socket_unit(FILE *socket, char *listen[], int num_addr, const char *source) { | |
63 | 64 | |
64 | 65 | fprintf(socket, |
65 | 66 | "# Automatically generated by systemd-sslh-generator\n\n" |
66 | 67 | "[Unit]\n" |
@@ -99,10 +100,9 @@ | ||
99 | 100 | } |
100 | 101 | |
101 | 102 | fclose(config); |
102 | 103 | |
103 | - | |
104 | - num_addr = get_listen_from_conf(sslh_conf, listen); | |
104 | + num_addr = get_listen_from_conf(sslh_conf, &listen); | |
105 | 105 | if (num_addr < 0) |
106 | 106 | return -1; |
107 | 107 | |
108 | 108 | /* If this is run by systemd directly write to the location told to |
Built with git-ssb-web