diff --git a/nse_libssh2.cc b/nse_libssh2.cc index b75587187..ee146edd2 100644 --- a/nse_libssh2.cc +++ b/nse_libssh2.cc @@ -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) {