mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Fix crashes when assigning timeouts as floats. New NSE utility function nseU_checkinteger
This commit is contained in:
@@ -44,7 +44,7 @@ extern NmapOps o;
|
||||
typedef struct nse_nsock_udata
|
||||
{
|
||||
nsock_iod nsiod;
|
||||
unsigned timeout;
|
||||
int timeout;
|
||||
|
||||
lua_State *thread;
|
||||
|
||||
@@ -739,9 +739,10 @@ static int l_get_info (lua_State *L)
|
||||
static int l_set_timeout (lua_State *L)
|
||||
{
|
||||
nse_nsock_udata *nu = check_nsock_udata(L, 1, false);
|
||||
nu->timeout = luaL_checkinteger(L, 2);
|
||||
if ((int) nu->timeout < -1) /* -1 is no timeout */
|
||||
return luaL_error(L, "Negative timeout: %d", nu->timeout);
|
||||
int timeout = nseU_checkinteger(L, 2);
|
||||
if (timeout < -1) /* -1 is no timeout */
|
||||
return luaL_error(L, "Negative timeout: %f", timeout);
|
||||
nu->timeout = timeout;
|
||||
return nseU_success(L);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "Target.h"
|
||||
#include "portlist.h"
|
||||
@@ -7,6 +8,16 @@
|
||||
#include "nse_main.h"
|
||||
#include "nse_utility.h"
|
||||
|
||||
int nseU_checkinteger (lua_State *L, int arg)
|
||||
{
|
||||
lua_Number n = luaL_checknumber(L, arg);
|
||||
int i;
|
||||
if (!lua_numbertointeger(floor(n), &i)) {
|
||||
return luaL_error(L, "Number cannot be converted to an integer");
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int nseU_traceback (lua_State *L)
|
||||
{
|
||||
if (lua_isstring(L, 1))
|
||||
|
||||
@@ -8,6 +8,12 @@ class Target;
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
/* int nseU_checkinteger (lua_State *L, int arg)
|
||||
*
|
||||
* Replacement for luaL_checkinteger that does a floor operation first
|
||||
*/
|
||||
int nseU_checkinteger (lua_State *L, int arg);
|
||||
|
||||
/* int nseU_traceback (lua_State *L)
|
||||
*
|
||||
* Traceback C Lua function.
|
||||
|
||||
Reference in New Issue
Block a user