mirror of
https://github.com/nmap/nmap.git
synced 2025-12-06 04:31:29 +00:00
Lua 5.4 change: userdata created with 1 uservalue by default. Set to 0 when possible
This commit is contained in:
6
lpeg.c
6
lpeg.c
@@ -2285,7 +2285,7 @@ static TTree *gettree (lua_State *L, int idx, int *len) {
|
|||||||
*/
|
*/
|
||||||
static TTree *newtree (lua_State *L, int len) {
|
static TTree *newtree (lua_State *L, int len) {
|
||||||
size_t size = (len - 1) * sizeof(TTree) + sizeof(Pattern);
|
size_t size = (len - 1) * sizeof(TTree) + sizeof(Pattern);
|
||||||
Pattern *p = (Pattern *)lua_newuserdata(L, size);
|
Pattern *p = (Pattern *)lua_newuserdatauv(L, size, 1);
|
||||||
luaL_getmetatable(L, PATTERN_T);
|
luaL_getmetatable(L, PATTERN_T);
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
p->code = NULL; p->codesize = 0;
|
p->code = NULL; p->codesize = 0;
|
||||||
@@ -3390,7 +3390,7 @@ static Capture *doublecap (lua_State *L, Capture *cap, int captop, int ptop) {
|
|||||||
Capture *newc;
|
Capture *newc;
|
||||||
if (captop >= INT_MAX/((int)sizeof(Capture) * 2))
|
if (captop >= INT_MAX/((int)sizeof(Capture) * 2))
|
||||||
luaL_error(L, "too many captures");
|
luaL_error(L, "too many captures");
|
||||||
newc = (Capture *)lua_newuserdata(L, captop * 2 * sizeof(Capture));
|
newc = (Capture *)lua_newuserdatauv(L, captop * 2 * sizeof(Capture), 0);
|
||||||
memcpy(newc, cap, captop * sizeof(Capture));
|
memcpy(newc, cap, captop * sizeof(Capture));
|
||||||
lua_replace(L, caplistidx(ptop));
|
lua_replace(L, caplistidx(ptop));
|
||||||
return newc;
|
return newc;
|
||||||
@@ -3412,7 +3412,7 @@ static Stack *doublestack (lua_State *L, Stack **stacklimit, int ptop) {
|
|||||||
luaL_error(L, "too many pending calls/choices");
|
luaL_error(L, "too many pending calls/choices");
|
||||||
newn = 2 * n; /* new size */
|
newn = 2 * n; /* new size */
|
||||||
if (newn > max) newn = max;
|
if (newn > max) newn = max;
|
||||||
newstack = (Stack *)lua_newuserdata(L, newn * sizeof(Stack));
|
newstack = (Stack *)lua_newuserdatauv(L, newn * sizeof(Stack), 0);
|
||||||
memcpy(newstack, stack, n * sizeof(Stack));
|
memcpy(newstack, stack, n * sizeof(Stack));
|
||||||
lua_replace(L, stackidx(ptop));
|
lua_replace(L, stackidx(ptop));
|
||||||
*stacklimit = newstack + newn;
|
*stacklimit = newstack + newn;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ static int l_dnet_new (lua_State *L)
|
|||||||
{
|
{
|
||||||
nse_dnet_udata *udata;
|
nse_dnet_udata *udata;
|
||||||
|
|
||||||
udata = (nse_dnet_udata *) lua_newuserdata(L, sizeof(nse_dnet_udata));
|
udata = (nse_dnet_udata *) lua_newuserdatauv(L, sizeof(nse_dnet_udata), 0);
|
||||||
lua_pushvalue(L, DNET_METATABLE);
|
lua_pushvalue(L, DNET_METATABLE);
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
udata->eth = NULL;
|
udata->eth = NULL;
|
||||||
@@ -142,7 +142,7 @@ static eth_t *open_eth_cached (lua_State *L, int dnet_index, const char *device)
|
|||||||
if (!lua_isuserdata(L, -1))
|
if (!lua_isuserdata(L, -1))
|
||||||
{
|
{
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
eth = (eth_t **) lua_newuserdata(L, sizeof(eth_t *));
|
eth = (eth_t **) lua_newuserdatauv(L, sizeof(eth_t *), 0);
|
||||||
*eth = eth_open(device);
|
*eth = eth_open(device);
|
||||||
if (*eth == NULL)
|
if (*eth == NULL)
|
||||||
luaL_error(L, "unable to open dnet on ethernet interface %s", device);
|
luaL_error(L, "unable to open dnet on ethernet interface %s", device);
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ static int dir_iter_factory (lua_State *L) {
|
|||||||
const char *path = luaL_checkstring (L, 1);
|
const char *path = luaL_checkstring (L, 1);
|
||||||
dir_data *d;
|
dir_data *d;
|
||||||
lua_pushcfunction (L, dir_iter);
|
lua_pushcfunction (L, dir_iter);
|
||||||
d = (dir_data *) lua_newuserdata (L, sizeof(dir_data));
|
d = (dir_data *) lua_newuserdatauv (L, sizeof(dir_data), 0);
|
||||||
luaL_getmetatable (L, DIR_METATABLE);
|
luaL_getmetatable (L, DIR_METATABLE);
|
||||||
lua_setmetatable (L, -2);
|
lua_setmetatable (L, -2);
|
||||||
d->closed = 0;
|
d->closed = 0;
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ static int l_session_open (lua_State *L) {
|
|||||||
luaL_checkinteger(L, 2);
|
luaL_checkinteger(L, 2);
|
||||||
lua_settop(L, 2);
|
lua_settop(L, 2);
|
||||||
|
|
||||||
state = (ssh_userdata *)lua_newuserdata(L, sizeof(ssh_userdata)); /* index 3 */
|
state = (ssh_userdata *)lua_newuserdatauv(L, sizeof(ssh_userdata), 1); /* index 3 */
|
||||||
|
|
||||||
assert(lua_gettop(L) == 3);
|
assert(lua_gettop(L) == 3);
|
||||||
state->session = NULL;
|
state->session = NULL;
|
||||||
@@ -864,7 +864,7 @@ static int finish_open_channel (lua_State *L, int status, lua_KContext ctx) {
|
|||||||
|
|
||||||
static int l_open_channel (lua_State *L) {
|
static int l_open_channel (lua_State *L) {
|
||||||
ssh_userdata *state = (ssh_userdata *)lua_touserdata(L, 1);
|
ssh_userdata *state = (ssh_userdata *)lua_touserdata(L, 1);
|
||||||
LIBSSH2_CHANNEL **channel = (LIBSSH2_CHANNEL **)lua_newuserdata(L, sizeof(LIBSSH2_CHANNEL *));
|
LIBSSH2_CHANNEL **channel = (LIBSSH2_CHANNEL **)lua_newuserdatauv(L, sizeof(LIBSSH2_CHANNEL *), 0);
|
||||||
|
|
||||||
while ((*channel = libssh2_channel_open_session(state->session)) == NULL
|
while ((*channel = libssh2_channel_open_session(state->session)) == NULL
|
||||||
&& libssh2_session_last_errno(state->session) == LIBSSH2_ERROR_EAGAIN) {
|
&& libssh2_session_last_errno(state->session) == LIBSSH2_ERROR_EAGAIN) {
|
||||||
|
|||||||
10
nse_nsock.cc
10
nse_nsock.cc
@@ -91,7 +91,7 @@ static nsock_pool new_pool (lua_State *L)
|
|||||||
|
|
||||||
nsock_pool_set_broadcast(nsp, true);
|
nsock_pool_set_broadcast(nsp, true);
|
||||||
|
|
||||||
nspp = (nsock_pool *) lua_newuserdata(L, sizeof(nsock_pool));
|
nspp = (nsock_pool *) lua_newuserdatauv(L, sizeof(nsock_pool), 0);
|
||||||
*nspp = nsp;
|
*nspp = nsp;
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
lua_pushcfunction(L, gc_pool);
|
lua_pushcfunction(L, gc_pool);
|
||||||
@@ -751,8 +751,8 @@ static int l_get_info (lua_State *L)
|
|||||||
int af; // address family
|
int af; // address family
|
||||||
struct sockaddr_storage local;
|
struct sockaddr_storage local;
|
||||||
struct sockaddr_storage remote;
|
struct sockaddr_storage remote;
|
||||||
char *ipstring_local = (char *) lua_newuserdata(L, sizeof(char) * INET6_ADDRSTRLEN);
|
char *ipstring_local = (char *) lua_newuserdatauv(L, sizeof(char) * INET6_ADDRSTRLEN, 0);
|
||||||
char *ipstring_remote = (char *) lua_newuserdata(L, sizeof(char) * INET6_ADDRSTRLEN);
|
char *ipstring_remote = (char *) lua_newuserdatauv(L, sizeof(char) * INET6_ADDRSTRLEN, 0);
|
||||||
|
|
||||||
nsock_iod_get_communication_info(nu->nsiod, &protocol, &af,
|
nsock_iod_get_communication_info(nu->nsiod, &protocol, &af,
|
||||||
(struct sockaddr*)&local, (struct sockaddr*)&remote,
|
(struct sockaddr*)&local, (struct sockaddr*)&remote,
|
||||||
@@ -812,7 +812,7 @@ static int l_sleep (lua_State *L)
|
|||||||
/* Convert to milliseconds for nsock_timer_create. */
|
/* Convert to milliseconds for nsock_timer_create. */
|
||||||
msecs = (int) (secs * 1000 + 0.5);
|
msecs = (int) (secs * 1000 + 0.5);
|
||||||
|
|
||||||
nsock_event_id *neidp = (nsock_event_id *) lua_newuserdata(L, sizeof(nsock_event_id *));
|
nsock_event_id *neidp = (nsock_event_id *) lua_newuserdatauv(L, sizeof(nsock_event_id *), 0);
|
||||||
*neidp = nsock_timer_create(nsp, sleep_callback, msecs, L);
|
*neidp = nsock_timer_create(nsp, sleep_callback, msecs, L);
|
||||||
lua_pushvalue(L, NSOCK_POOL);
|
lua_pushvalue(L, NSOCK_POOL);
|
||||||
lua_pushcclosure(L, sleep_destructor, 1);
|
lua_pushcclosure(L, sleep_destructor, 1);
|
||||||
@@ -930,7 +930,7 @@ static int l_new (lua_State *L)
|
|||||||
|
|
||||||
lua_settop(L, 0);
|
lua_settop(L, 0);
|
||||||
|
|
||||||
nu = (nse_nsock_udata *) lua_newuserdata(L, sizeof(nse_nsock_udata));
|
nu = (nse_nsock_udata *) lua_newuserdatauv(L, sizeof(nse_nsock_udata), 1);
|
||||||
lua_pushvalue(L, NSOCK_SOCKET);
|
lua_pushvalue(L, NSOCK_SOCKET);
|
||||||
lua_setmetatable(L, -2);
|
lua_setmetatable(L, -2);
|
||||||
initialize(L, 1, nu, proto, af);
|
initialize(L, 1, nu, proto, af);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ typedef struct bignum_data {
|
|||||||
|
|
||||||
int nse_pushbn( lua_State *L, BIGNUM *num, bool should_free)
|
int nse_pushbn( lua_State *L, BIGNUM *num, bool should_free)
|
||||||
{
|
{
|
||||||
bignum_data_t * data = (bignum_data_t *) lua_newuserdata( L, sizeof(bignum_data_t));
|
bignum_data_t * data = (bignum_data_t *) lua_newuserdatauv( L, sizeof(bignum_data_t), 0);
|
||||||
luaL_getmetatable( L, "BIGNUM" );
|
luaL_getmetatable( L, "BIGNUM" );
|
||||||
lua_setmetatable( L, -2 );
|
lua_setmetatable( L, -2 );
|
||||||
data->bn = num;
|
data->bn = num;
|
||||||
|
|||||||
@@ -160,13 +160,13 @@ static void obj_to_key(lua_State *L, const ASN1_OBJECT *obj)
|
|||||||
nid = OBJ_obj2nid(obj);
|
nid = OBJ_obj2nid(obj);
|
||||||
if (nid == NID_undef) {
|
if (nid == NID_undef) {
|
||||||
size_t size = 1;
|
size_t size = 1;
|
||||||
char *buf = (char *) lua_newuserdata(L, size);
|
char *buf = (char *) lua_newuserdatauv(L, size, 0);
|
||||||
const char *p, *q;
|
const char *p, *q;
|
||||||
int i, n;
|
int i, n;
|
||||||
|
|
||||||
while ((n = OBJ_obj2txt(buf, size, obj, 1)) < 0 || (unsigned) n >= size) {
|
while ((n = OBJ_obj2txt(buf, size, obj, 1)) < 0 || (unsigned) n >= size) {
|
||||||
size = size * 2;
|
size = size * 2;
|
||||||
buf = (char *) lua_newuserdata(L, size);
|
buf = (char *) lua_newuserdatauv(L, size, 0);
|
||||||
memcpy(lua_touserdata(L, -1), lua_touserdata(L, -2), lua_rawlen(L, -2));
|
memcpy(lua_touserdata(L, -1), lua_touserdata(L, -2), lua_rawlen(L, -2));
|
||||||
lua_replace(L, -2);
|
lua_replace(L, -2);
|
||||||
}
|
}
|
||||||
@@ -555,7 +555,7 @@ static int parse_ssl_cert(lua_State *L, X509 *cert)
|
|||||||
EVP_PKEY *pubkey;
|
EVP_PKEY *pubkey;
|
||||||
int pkey_type;
|
int pkey_type;
|
||||||
|
|
||||||
udata = (struct cert_userdata *) lua_newuserdata(L, sizeof(*udata));
|
udata = (struct cert_userdata *) lua_newuserdatauv(L, sizeof(*udata), 0);
|
||||||
udata->cert = cert;
|
udata->cert = cert;
|
||||||
|
|
||||||
#define NSE_NUM_CERT_FIELDS 7
|
#define NSE_NUM_CERT_FIELDS 7
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ static int lzstream_docompress(lua_State *L, lz_stream *s, int from, int to, int
|
|||||||
|
|
||||||
|
|
||||||
static lz_stream *lzstream_new(lua_State *L, int src) {
|
static lz_stream *lzstream_new(lua_State *L, int src) {
|
||||||
lz_stream *s = (lz_stream*)lua_newuserdata(L, sizeof(lz_stream));
|
lz_stream *s = (lz_stream*)lua_newuserdatauv(L, sizeof(lz_stream), 0);
|
||||||
|
|
||||||
luaL_getmetatable(L, ZSTREAMMETA);
|
luaL_getmetatable(L, ZSTREAMMETA);
|
||||||
lua_setmetatable(L, -2); /* set metatable */
|
lua_setmetatable(L, -2); /* set metatable */
|
||||||
|
|||||||
Reference in New Issue
Block a user