Skip to content

Commit 73ce19e

Browse files
committed
Use Lua integers in more places where floats are unexpected. Fixes nmap#1647
1 parent fbcaa39 commit 73ce19e

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

nse_nmaplib.cc

+13-13
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ static int l_get_version_intensity (lua_State *L)
663663
lua_pop(L,1);
664664

665665
if (selected_by_name) {
666-
lua_pushnumber(L, max_intensity);
666+
lua_pushinteger(L, max_intensity);
667667
return 1;
668668
}
669669

@@ -690,7 +690,7 @@ static int l_get_version_intensity (lua_State *L)
690690
}
691691
}
692692

693-
lua_pushnumber(L, intensity);
693+
lua_pushinteger(L, intensity);
694694

695695
return 1;
696696
}
@@ -704,13 +704,13 @@ static int l_get_verbosity (lua_State *L)
704704
we lie to it and say the verbosity is one higher than it really is. */
705705
verbosity += (nse_selectedbyname(L), lua_toboolean(L, -1) ? 1 : 0);
706706

707-
lua_pushnumber(L, verbosity);
707+
lua_pushinteger(L, verbosity);
708708
return 1;
709709
}
710710

711711
static int l_get_debugging (lua_State *L)
712712
{
713-
lua_pushnumber(L, o.debugging);
713+
lua_pushinteger(L, o.debugging);
714714
return 1;
715715
}
716716

@@ -735,7 +735,7 @@ static int l_fetchfile (lua_State *L)
735735

736736
static int l_get_timing_level (lua_State *L)
737737
{
738-
lua_pushnumber(L, o.timing_level);
738+
lua_pushinteger(L, o.timing_level);
739739
return 1;
740740
}
741741

@@ -767,26 +767,26 @@ static int l_add_targets (lua_State *L)
767767
}
768768
/* was able to add some targets */
769769
if (ntarget) {
770-
lua_pushnumber(L, ntarget);
770+
lua_pushinteger(L, ntarget);
771771
return 1;
772772
/* errors */
773773
} else {
774-
lua_pushnumber(L, ntarget);
774+
lua_pushinteger(L, ntarget);
775775
lua_pushstring(L, "failed to add new targets.");
776776
return 2;
777777
}
778778
} else {
779779
/* function called without arguments */
780780
/* push the number of pending targets that are in the queue */
781-
lua_pushnumber(L, NewTargets::insert(""));
781+
lua_pushinteger(L, NewTargets::insert(""));
782782
return 1;
783783
}
784784
}
785785

786786
/* Return the number of added targets */
787787
static int l_get_new_targets_num (lua_State *L)
788788
{
789-
lua_pushnumber(L, NewTargets::get_number());
789+
lua_pushinteger(L, NewTargets::get_number());
790790
return 1;
791791
}
792792

@@ -943,9 +943,9 @@ static int l_list_interfaces (lua_State *L)
943943
static int l_get_ttl (lua_State *L)
944944
{
945945
if (o.ttl < 0 || o.ttl > 255)
946-
lua_pushnumber(L, 64); //default TTL
946+
lua_pushinteger(L, 64); //default TTL
947947
else
948-
lua_pushnumber(L, o.ttl);
948+
lua_pushinteger(L, o.ttl);
949949
return 1;
950950
}
951951

@@ -956,9 +956,9 @@ static int l_get_ttl (lua_State *L)
956956
static int l_get_payload_length(lua_State *L)
957957
{
958958
if (o.extra_payload_length < 0)
959-
lua_pushnumber(L, 0); //default payload length
959+
lua_pushinteger(L, 0); //default payload length
960960
else
961-
lua_pushnumber(L, o.extra_payload_length);
961+
lua_pushinteger(L, o.extra_payload_length);
962962
return 1;
963963
}
964964

nse_openssl.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@ static int l_bignum_add( lua_State *L ) /** bignum_add( BIGNUM a, BIGNUM b ) */
139139
static int l_bignum_num_bits( lua_State *L ) /** bignum_num_bits( BIGNUM bn ) */
140140
{
141141
bignum_data_t * userdata = (bignum_data_t *) luaL_checkudata(L, 1, "BIGNUM");
142-
lua_pushnumber( L, BN_num_bits( userdata->bn) );
142+
lua_pushinteger( L, BN_num_bits( userdata->bn) );
143143
return 1;
144144
}
145145

146146
static int l_bignum_num_bytes( lua_State *L ) /** bignum_num_bytes( BIGNUM bn ) */
147147
{
148148
bignum_data_t * userdata = (bignum_data_t *) luaL_checkudata(L, 1, "BIGNUM");
149-
lua_pushnumber( L, BN_num_bytes( userdata->bn) );
149+
lua_pushinteger( L, BN_num_bytes( userdata->bn) );
150150
return 1;
151151
}
152152

nse_pcrelib.cc

+7-7
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ static int udata_tostring (lua_State *L, const char* type_handle,
5353
return 1;
5454
}
5555

56-
typedef struct { const char* key; lua_Number val; } flags_pair;
56+
typedef struct { const char* key; lua_Integer val; } flags_pair;
5757

5858
static int get_flags (lua_State *L, const flags_pair *arr)
5959
{
6060
const flags_pair *p;
6161
lua_newtable(L);
6262
for(p=arr; p->key != NULL; p++) {
6363
lua_pushstring(L, p->key);
64-
lua_pushnumber(L, p->val);
64+
lua_pushinteger(L, p->val);
6565
lua_rawset(L, -3);
6666
}
6767
return 1;
@@ -200,9 +200,9 @@ static void Lpcre_push_offsets (lua_State *L, const char *text, pcre2 * ud)
200200
for (i=1, j=1; i <= (unsigned) ud->ncapt; i++) {
201201
k = i * 2;
202202
if (ud->match[k] >= 0) {
203-
lua_pushnumber(L, ud->match[k] + 1);
203+
lua_pushinteger(L, ud->match[k] + 1);
204204
lua_rawseti(L, -2, j++);
205-
lua_pushnumber(L, ud->match[k+1]);
205+
lua_pushinteger(L, ud->match[k+1]);
206206
lua_rawseti(L, -2, j++);
207207
}
208208
else {
@@ -229,8 +229,8 @@ static int Lpcre_match_generic(lua_State *L, Lpcre_push_matches push_matches)
229229
res = pcre_exec(ud->pr, ud->extra, text, (int)elen, startoffset, eflags,
230230
ud->match, (ud->ncapt + 1) * 3);
231231
if (res >= 0) {
232-
lua_pushnumber(L, (lua_Number) ud->match[0] + 1);
233-
lua_pushnumber(L, (lua_Number) ud->match[1]);
232+
lua_pushinteger(L, (lua_Number) ud->match[0] + 1);
233+
lua_pushinteger(L, (lua_Number) ud->match[1]);
234234
(*push_matches)(L, text, ud);
235235
return 3;
236236
}
@@ -279,7 +279,7 @@ static int Lpcre_gmatch(lua_State *L)
279279
} else
280280
break;
281281
}
282-
lua_pushnumber(L, nmatch);
282+
lua_pushinteger(L, nmatch);
283283
return 1;
284284
}
285285

nse_ssl_cert.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -419,18 +419,18 @@ static void tm_to_table(lua_State *L, const struct tm *tm)
419419
#define NSE_NUM_TM_FIELDS 6
420420
lua_createtable(L, 0, NSE_NUM_TM_FIELDS);
421421

422-
lua_pushnumber(L, tm->tm_year);
422+
lua_pushinteger(L, tm->tm_year);
423423
lua_setfield(L, -2, "year");
424424
/* Lua uses one-indexed months. */
425-
lua_pushnumber(L, tm->tm_mon + 1);
425+
lua_pushinteger(L, tm->tm_mon + 1);
426426
lua_setfield(L, -2, "month");
427-
lua_pushnumber(L, tm->tm_mday);
427+
lua_pushinteger(L, tm->tm_mday);
428428
lua_setfield(L, -2, "day");
429-
lua_pushnumber(L, tm->tm_hour);
429+
lua_pushinteger(L, tm->tm_hour);
430430
lua_setfield(L, -2, "hour");
431-
lua_pushnumber(L, tm->tm_min);
431+
lua_pushinteger(L, tm->tm_min);
432432
lua_setfield(L, -2, "min");
433-
lua_pushnumber(L, tm->tm_sec);
433+
lua_pushinteger(L, tm->tm_sec);
434434
lua_setfield(L, -2, "sec");
435435
/* Omit tm_wday and tm_yday. */
436436
}

0 commit comments

Comments
 (0)