Skip to content

Commit

Permalink
Handling misused rte in evbuffer
Browse files Browse the repository at this point in the history
If we see an "rte", write a response and wait for the next "newsql".

Signed-off-by: Rivers Zhang <[email protected]>
  • Loading branch information
riverszhang89 committed Feb 5, 2025
1 parent 8c00a20 commit 7fa72c2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
16 changes: 16 additions & 0 deletions cdb2jdbc/src/test/java/com/bloomberg/comdb2/jdbc/BadRte.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.bloomberg.comdb2.jdbc;

import org.junit.*;
import org.junit.Assert.*;

public class BadRte {
@Test public void testBadRteClient() throws SQLException {
String db = System.getProperty("cdb2jdbc.test.database");
String cluster = System.getProperty("cdb2jdbc.test.cluster");
Connection conn = DriverManager.getConnection(String.format("jdbc:comdb2://%s/%s?allow_pmux_route=1&portmuxport=19000", cluster, db));
Statement stmt = conn.createStatement();
stmt.executeQuery("SELECT 1");
stmt.close();
conn.close();
}
}
24 changes: 20 additions & 4 deletions net/net_evbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2844,7 +2844,8 @@ static void rd_connect_msg_len(int fd, short what, void *data)
}
}

static int do_appsock_evbuffer(struct evbuffer *buf, struct sockaddr_in *ss, int fd, int is_readonly, int secure)
static int do_appsock_evbuffer(struct evbuffer *buf, struct sockaddr_in *ss, int fd, int is_readonly, int secure,
int *pagain)
{
struct appsock_info *info = NULL;
struct evbuffer_ptr b = evbuffer_search(buf, "\n", 1, NULL);
Expand All @@ -2861,6 +2862,16 @@ static int do_appsock_evbuffer(struct evbuffer *buf, struct sockaddr_in *ss, int
return 1;
}

if (strcmp(key, "rte ") == 0) {
evbuffer_read(buf, fd, -1);
evbuffer_free(buf);
logmsg(LOGMSG_ERROR, "misused rte!\n");
ssize_t rc = write(fd, "0\n", 2);
if (rc == 2 && pagain)
*pagain = 1;
return 1;
}

info = get_appsock_info(key);
}

Expand Down Expand Up @@ -2903,6 +2914,7 @@ static void do_read(int fd, short what, void *data)
netinfo_type *netinfo_ptr = a->netinfo_ptr;
struct sockaddr_in ss = a->ss;
int secure = a->secure;
int again = 0;
a->fd = -1;
accept_info_free(a);
a = NULL;
Expand All @@ -2911,8 +2923,12 @@ static void do_read(int fd, short what, void *data)
shutdown_close(fd);
return;
}
if ((do_appsock_evbuffer(buf, &ss, fd, 0, secure)) == 0) return;
handle_appsock(netinfo_ptr, &ss, first_byte, buf, fd);
if ((do_appsock_evbuffer(buf, &ss, fd, 0, secure, &again)) == 0)
return;
if (again)
accept_info_new(netinfo_ptr, &ss, fd, secure);
else
handle_appsock(netinfo_ptr, &ss, first_byte, buf, fd);
}

static void accept_cb(struct evconnlistener *listener, evutil_socket_t fd,
Expand Down Expand Up @@ -3881,5 +3897,5 @@ void do_revconn_evbuffer(int fd, short what, void *data)
struct sockaddr_in addr;
socklen_t laddr = sizeof(addr);
getsockname(fd, (struct sockaddr *)&addr, &laddr);
do_appsock_evbuffer(buf, &addr, fd, 1, 0);
do_appsock_evbuffer(buf, &addr, fd, 1, 0, NULL);
}

0 comments on commit 7fa72c2

Please sign in to comment.