git ssb

0+

cel / sslh



Commit 7d561af4235ffc6c0203fc66d4998c74384c7fa8

allocate listen[] before writing to it...

Yves Rutschle committed on 4/18/2017, 7:04:30 PM
Parent: cce42c68822f605ff7297c136312af50bfd5fdad

Files changed

systemd-sslh-generator.cchanged
systemd-sslh-generator.cView
@@ -16,9 +16,9 @@
1616
1717 }
1818
1919
20-static int get_listen_from_conf(const char *filename, char **listen) {
20+static int get_listen_from_conf(const char *filename, char **listen[]) {
2121 config_t config;
2222 config_setting_t *setting, *addr;
2323 const char *hostname, *port;
2424 int len = 0;
@@ -38,8 +38,9 @@
3838 } else {
3939 setting = config_lookup(&config, "listen");
4040 if (setting) {
4141 len = config_setting_length(setting);
42+ *listen = malloc(len * sizeof(**listen));
4243 for (int i = 0; i < len; i++) {
4344 addr = config_setting_get_elem(setting, i);
4445 if (! (config_setting_lookup_string(addr, "host", &hostname) &&
4546 config_setting_lookup_string(addr, "port", &port))) {
@@ -47,10 +48,10 @@
4748 "line %d:Incomplete specification (hostname and port required)\n",
4849 config_setting_source_line(addr));
4950 return -1;
5051 } 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));
5354 }
5455 }
5556 }
5657 }
@@ -58,9 +59,9 @@
5859 return len;
5960
6061 }
6162
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) {
6364
6465 fprintf(socket,
6566 "# Automatically generated by systemd-sslh-generator\n\n"
6667 "[Unit]\n"
@@ -99,10 +100,9 @@
99100 }
100101
101102 fclose(config);
102103
103-
104- num_addr = get_listen_from_conf(sslh_conf, listen);
104+ num_addr = get_listen_from_conf(sslh_conf, &listen);
105105 if (num_addr < 0)
106106 return -1;
107107
108108 /* If this is run by systemd directly write to the location told to

Built with git-ssb-web