1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Use Lua integers in more places where floats are unexpected. Fixes #1647

This commit is contained in:
dmiller
2019-06-26 20:13:43 +00:00
parent fbcaa39fa2
commit 73ce19e7b6
4 changed files with 28 additions and 28 deletions

View File

@@ -663,7 +663,7 @@ static int l_get_version_intensity (lua_State *L)
lua_pop(L,1); lua_pop(L,1);
if (selected_by_name) { if (selected_by_name) {
lua_pushnumber(L, max_intensity); lua_pushinteger(L, max_intensity);
return 1; return 1;
} }
@@ -690,7 +690,7 @@ static int l_get_version_intensity (lua_State *L)
} }
} }
lua_pushnumber(L, intensity); lua_pushinteger(L, intensity);
return 1; return 1;
} }
@@ -704,13 +704,13 @@ static int l_get_verbosity (lua_State *L)
we lie to it and say the verbosity is one higher than it really is. */ we lie to it and say the verbosity is one higher than it really is. */
verbosity += (nse_selectedbyname(L), lua_toboolean(L, -1) ? 1 : 0); verbosity += (nse_selectedbyname(L), lua_toboolean(L, -1) ? 1 : 0);
lua_pushnumber(L, verbosity); lua_pushinteger(L, verbosity);
return 1; return 1;
} }
static int l_get_debugging (lua_State *L) static int l_get_debugging (lua_State *L)
{ {
lua_pushnumber(L, o.debugging); lua_pushinteger(L, o.debugging);
return 1; return 1;
} }
@@ -735,7 +735,7 @@ static int l_fetchfile (lua_State *L)
static int l_get_timing_level (lua_State *L) static int l_get_timing_level (lua_State *L)
{ {
lua_pushnumber(L, o.timing_level); lua_pushinteger(L, o.timing_level);
return 1; return 1;
} }
@@ -767,18 +767,18 @@ static int l_add_targets (lua_State *L)
} }
/* was able to add some targets */ /* was able to add some targets */
if (ntarget) { if (ntarget) {
lua_pushnumber(L, ntarget); lua_pushinteger(L, ntarget);
return 1; return 1;
/* errors */ /* errors */
} else { } else {
lua_pushnumber(L, ntarget); lua_pushinteger(L, ntarget);
lua_pushstring(L, "failed to add new targets."); lua_pushstring(L, "failed to add new targets.");
return 2; return 2;
} }
} else { } else {
/* function called without arguments */ /* function called without arguments */
/* push the number of pending targets that are in the queue */ /* push the number of pending targets that are in the queue */
lua_pushnumber(L, NewTargets::insert("")); lua_pushinteger(L, NewTargets::insert(""));
return 1; return 1;
} }
} }
@@ -786,7 +786,7 @@ static int l_add_targets (lua_State *L)
/* Return the number of added targets */ /* Return the number of added targets */
static int l_get_new_targets_num (lua_State *L) static int l_get_new_targets_num (lua_State *L)
{ {
lua_pushnumber(L, NewTargets::get_number()); lua_pushinteger(L, NewTargets::get_number());
return 1; return 1;
} }
@@ -943,9 +943,9 @@ static int l_list_interfaces (lua_State *L)
static int l_get_ttl (lua_State *L) static int l_get_ttl (lua_State *L)
{ {
if (o.ttl < 0 || o.ttl > 255) if (o.ttl < 0 || o.ttl > 255)
lua_pushnumber(L, 64); //default TTL lua_pushinteger(L, 64); //default TTL
else else
lua_pushnumber(L, o.ttl); lua_pushinteger(L, o.ttl);
return 1; return 1;
} }
@@ -956,9 +956,9 @@ static int l_get_ttl (lua_State *L)
static int l_get_payload_length(lua_State *L) static int l_get_payload_length(lua_State *L)
{ {
if (o.extra_payload_length < 0) if (o.extra_payload_length < 0)
lua_pushnumber(L, 0); //default payload length lua_pushinteger(L, 0); //default payload length
else else
lua_pushnumber(L, o.extra_payload_length); lua_pushinteger(L, o.extra_payload_length);
return 1; return 1;
} }

View File

@@ -139,14 +139,14 @@ static int l_bignum_add( lua_State *L ) /** bignum_add( BIGNUM a, BIGNUM b ) */
static int l_bignum_num_bits( lua_State *L ) /** bignum_num_bits( BIGNUM bn ) */ static int l_bignum_num_bits( lua_State *L ) /** bignum_num_bits( BIGNUM bn ) */
{ {
bignum_data_t * userdata = (bignum_data_t *) luaL_checkudata(L, 1, "BIGNUM"); bignum_data_t * userdata = (bignum_data_t *) luaL_checkudata(L, 1, "BIGNUM");
lua_pushnumber( L, BN_num_bits( userdata->bn) ); lua_pushinteger( L, BN_num_bits( userdata->bn) );
return 1; return 1;
} }
static int l_bignum_num_bytes( lua_State *L ) /** bignum_num_bytes( BIGNUM bn ) */ static int l_bignum_num_bytes( lua_State *L ) /** bignum_num_bytes( BIGNUM bn ) */
{ {
bignum_data_t * userdata = (bignum_data_t *) luaL_checkudata(L, 1, "BIGNUM"); bignum_data_t * userdata = (bignum_data_t *) luaL_checkudata(L, 1, "BIGNUM");
lua_pushnumber( L, BN_num_bytes( userdata->bn) ); lua_pushinteger( L, BN_num_bytes( userdata->bn) );
return 1; return 1;
} }

View File

@@ -53,7 +53,7 @@ static int udata_tostring (lua_State *L, const char* type_handle,
return 1; return 1;
} }
typedef struct { const char* key; lua_Number val; } flags_pair; typedef struct { const char* key; lua_Integer val; } flags_pair;
static int get_flags (lua_State *L, const flags_pair *arr) static int get_flags (lua_State *L, const flags_pair *arr)
{ {
@@ -61,7 +61,7 @@ static int get_flags (lua_State *L, const flags_pair *arr)
lua_newtable(L); lua_newtable(L);
for(p=arr; p->key != NULL; p++) { for(p=arr; p->key != NULL; p++) {
lua_pushstring(L, p->key); lua_pushstring(L, p->key);
lua_pushnumber(L, p->val); lua_pushinteger(L, p->val);
lua_rawset(L, -3); lua_rawset(L, -3);
} }
return 1; return 1;
@@ -200,9 +200,9 @@ static void Lpcre_push_offsets (lua_State *L, const char *text, pcre2 * ud)
for (i=1, j=1; i <= (unsigned) ud->ncapt; i++) { for (i=1, j=1; i <= (unsigned) ud->ncapt; i++) {
k = i * 2; k = i * 2;
if (ud->match[k] >= 0) { if (ud->match[k] >= 0) {
lua_pushnumber(L, ud->match[k] + 1); lua_pushinteger(L, ud->match[k] + 1);
lua_rawseti(L, -2, j++); lua_rawseti(L, -2, j++);
lua_pushnumber(L, ud->match[k+1]); lua_pushinteger(L, ud->match[k+1]);
lua_rawseti(L, -2, j++); lua_rawseti(L, -2, j++);
} }
else { else {
@@ -229,8 +229,8 @@ static int Lpcre_match_generic(lua_State *L, Lpcre_push_matches push_matches)
res = pcre_exec(ud->pr, ud->extra, text, (int)elen, startoffset, eflags, res = pcre_exec(ud->pr, ud->extra, text, (int)elen, startoffset, eflags,
ud->match, (ud->ncapt + 1) * 3); ud->match, (ud->ncapt + 1) * 3);
if (res >= 0) { if (res >= 0) {
lua_pushnumber(L, (lua_Number) ud->match[0] + 1); lua_pushinteger(L, (lua_Number) ud->match[0] + 1);
lua_pushnumber(L, (lua_Number) ud->match[1]); lua_pushinteger(L, (lua_Number) ud->match[1]);
(*push_matches)(L, text, ud); (*push_matches)(L, text, ud);
return 3; return 3;
} }
@@ -279,7 +279,7 @@ static int Lpcre_gmatch(lua_State *L)
} else } else
break; break;
} }
lua_pushnumber(L, nmatch); lua_pushinteger(L, nmatch);
return 1; return 1;
} }

View File

@@ -419,18 +419,18 @@ static void tm_to_table(lua_State *L, const struct tm *tm)
#define NSE_NUM_TM_FIELDS 6 #define NSE_NUM_TM_FIELDS 6
lua_createtable(L, 0, NSE_NUM_TM_FIELDS); lua_createtable(L, 0, NSE_NUM_TM_FIELDS);
lua_pushnumber(L, tm->tm_year); lua_pushinteger(L, tm->tm_year);
lua_setfield(L, -2, "year"); lua_setfield(L, -2, "year");
/* Lua uses one-indexed months. */ /* Lua uses one-indexed months. */
lua_pushnumber(L, tm->tm_mon + 1); lua_pushinteger(L, tm->tm_mon + 1);
lua_setfield(L, -2, "month"); lua_setfield(L, -2, "month");
lua_pushnumber(L, tm->tm_mday); lua_pushinteger(L, tm->tm_mday);
lua_setfield(L, -2, "day"); lua_setfield(L, -2, "day");
lua_pushnumber(L, tm->tm_hour); lua_pushinteger(L, tm->tm_hour);
lua_setfield(L, -2, "hour"); lua_setfield(L, -2, "hour");
lua_pushnumber(L, tm->tm_min); lua_pushinteger(L, tm->tm_min);
lua_setfield(L, -2, "min"); lua_setfield(L, -2, "min");
lua_pushnumber(L, tm->tm_sec); lua_pushinteger(L, tm->tm_sec);
lua_setfield(L, -2, "sec"); lua_setfield(L, -2, "sec");
/* Omit tm_wday and tm_yday. */ /* Omit tm_wday and tm_yday. */
} }