-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlightning-addr.patch
66 lines (60 loc) · 2.61 KB
/
lightning-addr.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
diff --git a/cli/lightning-cli.c b/cli/lightning-cli.c
index c6996e6d8..889d256c6 100644
--- a/cli/lightning-cli.c
+++ b/cli/lightning-cli.c
@@ -694,10 +694,11 @@ int main(int argc, char *argv[])
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (strlen(rpc_filename) + 1 > sizeof(addr.sun_path))
errx(ERROR_USAGE, "rpc filename '%s' too long", rpc_filename);
- strcpy(addr.sun_path, rpc_filename);
+ addr.sun_path[0] = '\0';
+ strcpy(addr.sun_path + 1, rpc_filename);
addr.sun_family = AF_UNIX;
- if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) != 0)
+ if (connect(fd, (struct sockaddr *)&addr, sizeof(addr.sun_family) + strlen(rpc_filename) + 1) != 0)
err(ERROR_TALKING_TO_LIGHTNINGD,
"Connecting to '%s'", rpc_filename);
diff --git a/lightningd/jsonrpc.c b/lightningd/jsonrpc.c
index 585fa4014..2e825ab61 100644
--- a/lightningd/jsonrpc.c
+++ b/lightningd/jsonrpc.c
@@ -1179,18 +1179,19 @@ void jsonrpc_listen(struct jsonrpc *jsonrpc, struct lightningd *ld)
}
if (strlen(rpc_filename) + 1 > sizeof(addr.sun_path))
errx(1, "rpc filename '%s' too long", rpc_filename);
- strcpy(addr.sun_path, rpc_filename);
+ addr.sun_path[0] = '\0';
+ strcpy(addr.sun_path + 1, rpc_filename);
addr.sun_family = AF_UNIX;
/* Of course, this is racy! */
- if (connect(fd, (struct sockaddr *)&addr, sizeof(addr)) == 0)
+ if (connect(fd, (struct sockaddr *)&addr, sizeof(addr.sun_family) + strlen(rpc_filename) + 1) == 0)
errx(1, "rpc filename '%s' in use", rpc_filename);
unlink(rpc_filename);
/* Set the umask according to the desired file mode. */
new_umask = ld->rpc_filemode ^ 0777;
old_umask = umask(new_umask);
- if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)))
+ if (bind(fd, (struct sockaddr *)&addr, sizeof(addr.sun_family) + strlen(rpc_filename) + 1))
err(1, "Binding rpc socket to '%s'", rpc_filename);
umask(old_umask);
diff --git a/plugins/libplugin.c b/plugins/libplugin.c
index 20b0020f9..2079a0cbf 100644
--- a/plugins/libplugin.c
+++ b/plugins/libplugin.c
@@ -845,11 +845,14 @@ static struct command_result *handle_init(struct command *cmd,
if (strlen(p->rpc_location) + 1 > sizeof(addr.sun_path))
plugin_err(p, "rpc filename '%s' too long",
p->rpc_location);
- strcpy(addr.sun_path, p->rpc_location);
+ addr.sun_path[0] = '\0';
+ strcpy(addr.sun_path + 1, p->rpc_location);
addr.sun_family = AF_UNIX;
+ const size_t len = sizeof(addr.sun_family) +
+ strlen(p->rpc_location) + 1;
if (connect(p->rpc_conn->fd, (struct sockaddr *)&addr,
- sizeof(addr)) != 0) {
+ len) != 0) {
with_rpc = false;
plugin_log(p, LOG_UNUSUAL,
"Could not connect to '%s': %s",