annotate files/patch-src_apps_common_hiredis__libevent2.c @ 13:c7cf16351c81

Apply patches for proper STUN message validation: 1. Validate the size of an attribute before returning it to the caller. Previously this was being done in stun_attr_get_next_str() to check that the previous attribute didn't exceed the size of the underlying buffer, however by that point any maliciously crafted attributes would have already had their chance to attack the caller. commit 9b8baa805582ae66d2a1ed68483609f90fcfb4d0 2. Validate the size of the buffer in stun_get_command_message_len_str(). Without this the caller could read off the end of the underlying buffer if it receives a maliciously crafted packet with an invalid header size. commit 14cb1c94e7be98869f45678ba195a26796a797c4 3. Changed type from int to size_t to avoid warning. warning: comparison between signed and unsigned integer expressions commit 4722697645cf033de8cf4f34e4214af750746365 See also: https://github.com/coturn/coturn/pull/472
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 28 Mar 2020 15:44:52 +0100
parents 9a1ee735f28f
children 4a6383e57d12
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
1 --- src/apps/common/hiredis_libevent2.c.orig 2019-03-02 21:06:19 UTC
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
2 +++ src/apps/common/hiredis_libevent2.c
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
3 @@ -55,6 +55,7 @@ struct redisLibeventEvents
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
4 char *ip;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
5 int port;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
6 char *pwd;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
7 + char *usocket;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
8 int db;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
9 };
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
10
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
11 @@ -223,12 +224,13 @@ void send_message_to_redis(redis_context_handle rch, c
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
12
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
13 ///////////////////////// Attach /////////////////////////////////
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
14
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
15 -redis_context_handle redisLibeventAttach(struct event_base *base, char *ip0, int port0, char *pwd, int db)
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
16 +redis_context_handle redisLibeventAttach(struct event_base *base, char *ip0, int port0, char *pwd, char *usocket, int db)
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
17 {
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
18
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
19 struct redisLibeventEvents *e = NULL;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
20 redisAsyncContext *ac = NULL;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
21
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
22 + char sockpath[256] = "\0";
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
23 char ip[256];
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
24 if(ip0 && ip0[0])
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
25 STRCPY(ip,ip0);
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
26 @@ -239,7 +241,14 @@ redis_context_handle redisLibeventAttach(struct event_
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
27 if(port0>0)
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
28 port=port0;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
29
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
30 - ac = redisAsyncConnect(ip, port);
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
31 + if(usocket)
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
32 + STRCPY(sockpath, usocket);
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
33 +
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
34 + if(usocket) {
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
35 + ac = redisAsyncConnectUnix(sockpath);
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
36 + } else {
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
37 + ac = redisAsyncConnect(ip, port);
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
38 + }
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
39 if (!ac) {
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
40 fprintf(stderr,"Error: %s:%s\n", ac->errstr, ac->c.errstr);
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
41 return NULL;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
42 @@ -256,6 +265,11 @@ redis_context_handle redisLibeventAttach(struct event_
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
43 e->port = port;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
44 if(pwd)
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
45 e->pwd = turn_strdup(pwd);
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
46 + if (usocket) {
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
47 + e->usocket = turn_strdup(usocket);
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
48 + } else {
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
49 + e->usocket = NULL;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
50 + }
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
51 e->db = db;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
52
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
53 /* Register functions to start/stop listening for events */
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
54 @@ -277,6 +291,7 @@ redis_context_handle redisLibeventAttach(struct event_
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
55 e);
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
56
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
57 if (e->rev == NULL || e->wev == NULL) {
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
58 + /* XXX FIXME TBD: free e->ip, e->pwd, e->usocket */
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
59 turn_free(e, sizeof(struct redisLibeventEvents));
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
60 return NULL;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
61 }
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
62 @@ -327,7 +342,11 @@ static void redis_reconnect(struct redisLibeventEvents
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
63 e->context = NULL;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
64 }
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
65
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
66 - ac = redisAsyncConnect(e->ip, e->port);
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
67 + if(e->usocket) {
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
68 + ac = redisAsyncConnectUnix(e->usocket);
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
69 + } else {
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
70 + ac = redisAsyncConnect(e->ip, e->port);
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
71 + }
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
72 if(!ac) {
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
73 return;
9a1ee735f28f Patch to allow redis connections by a Unix socket.
Franz Glasner <fzglas.hg@dom66.de>
parents:
diff changeset
74 }