Skip to content

Commit 14cbec7

Browse files
committed
Fix stack buffer corruption on destroy_sql_pool
Signed-off-by: mkhullar <mohit.khullar@gmail.com>
1 parent 8fccc99 commit 14cbec7

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

db/process_message.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,10 @@ int process_command(struct dbenv *dbenv, char *line, int lline, int st)
13811381
else if (tokcmp(tok, ltok, "destroy_sql_pool") == 0) {
13821382
char zPoolName[PATH_MAX];
13831383
tok = segtok(line, lline, &st, &ltok);
1384+
if (ltok >= PATH_MAX) {
1385+
logmsg(LOGMSG_USER, "pool name too long. Max: %d\n", PATH_MAX - 1);
1386+
return -1;
1387+
}
13841388
if (ltok != 0) {
13851389
tokcpy(tok, ltok, zPoolName);
13861390
rc = destroy_sql_pool(zPoolName, SQL_POOL_STOP_TIMEOUT_US);

lua/syssp.c.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,7 @@ static int db_send(Lua L)
489489

490490
if (!lua_isstring(L, 1))
491491
return luaL_error(L, "Expected string argument");
492-
cmd = (char*) lua_tostring(L, -1);
493-
lua_settop(L, 0);
492+
cmd = (char*) lua_tostring(L, 1);
494493

495494
return _db_process_command(L, cmd, "out");
496495
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ifeq ($(TESTSROOTDIR),)
2+
include ../testcase.mk
3+
else
4+
include $(TESTSROOTDIR)/testcase.mk
5+
endif
6+
7+
export TEST_TIMEOUT=1m
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
bash -n "$0" || exit 1
3+
4+
dbnm=$1
5+
6+
long_name=$(printf 'A%.0s' $(seq 1 5000))
7+
8+
# Should return error, not crash the server
9+
cdb2sql ${CDB2_OPTIONS} $dbnm default "EXEC PROCEDURE sys.cmd.send('destroy_sql_pool $long_name')" >/dev/null 2>&1
10+
11+
# Verify server is still alive
12+
cdb2sql ${CDB2_OPTIONS} $dbnm default "SELECT 'alive'" >output.actual 2>&1
13+
14+
grep -q "('alive'='alive')" output.actual
15+
if [ $? -ne 0 ]; then
16+
echo "FAILURE: server not responding after overflow attempt"
17+
cat output.actual
18+
exit 1
19+
fi
20+
21+
echo "SUCCESS"

0 commit comments

Comments
 (0)