1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-06 06:29:03 +00:00

Fix libssh2.channel_read_stderr, was reading stream 0

This commit is contained in:
dmiller
2024-10-03 19:18:13 +00:00
parent 325a4f680c
commit f8b7e5c860

View File

@@ -702,8 +702,9 @@ static int channel_read (lua_State *L, int status, lua_KContext ctx) {
char buf[2048];
size_t buflen = 2048;
LIBSSH2_CHANNEL **channel = (LIBSSH2_CHANNEL **) lua_touserdata(L, 2);
int stream_id = luaL_checkinteger(L, 3);
while ((rc = libssh2_channel_read(*channel, buf, buflen)) == LIBSSH2_ERROR_EAGAIN) {
while ((rc = libssh2_channel_read_ex(*channel, stream_id, buf, buflen)) == LIBSSH2_ERROR_EAGAIN) {
luaL_getmetafield(L, 1, "filter");
lua_pushvalue(L, 1);
lua_callk(L, 1, 0, 0, channel_read);
@@ -722,30 +723,13 @@ static int channel_read (lua_State *L, int status, lua_KContext ctx) {
}
static int l_channel_read (lua_State *L) {
lua_pushinteger(L, 0);
return channel_read(L, 0, 0);
}
static int l_channel_read_stderr(lua_State *L) {
int rc;
char buf[2048];
size_t buflen = 2048;
LIBSSH2_CHANNEL **channel = (LIBSSH2_CHANNEL **) lua_touserdata(L, 2);
while ((rc = libssh2_channel_read_stderr(*channel, buf, buflen)) == LIBSSH2_ERROR_EAGAIN) {
luaL_getmetafield(L, 1, "filter");
lua_pushvalue(L, 1);
lua_callk(L, 1, 0, 0, channel_read);
}
if (rc > 0) {
lua_pushlstring(L, buf, rc);
return 1;
}
else if (rc < 0)
return luaL_error(L, "Reading from channel");
lua_pushnil(L);
return 1;
lua_pushinteger(L, SSH_EXTENDED_DATA_STDERR);
return channel_read(L, 0, 0);
}
static int channel_write (lua_State *L, int status, lua_KContext ctx) {