1
0
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:
dmiller
2024-06-20 20:47:10 +00:00
parent 13be028eb1
commit 136e1c6ed7
8 changed files with 18 additions and 18 deletions

6
lpeg.c
View File

@@ -2285,7 +2285,7 @@ static TTree *gettree (lua_State *L, int idx, int *len) {
*/
static TTree *newtree (lua_State *L, int len) {
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);
lua_setmetatable(L, -2);
p->code = NULL; p->codesize = 0;
@@ -3390,7 +3390,7 @@ static Capture *doublecap (lua_State *L, Capture *cap, int captop, int ptop) {
Capture *newc;
if (captop >= INT_MAX/((int)sizeof(Capture) * 2))
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));
lua_replace(L, caplistidx(ptop));
return newc;
@@ -3412,7 +3412,7 @@ static Stack *doublestack (lua_State *L, Stack **stacklimit, int ptop) {
luaL_error(L, "too many pending calls/choices");
newn = 2 * n; /* new size */
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));
lua_replace(L, stackidx(ptop));
*stacklimit = newstack + newn;

View File

@@ -37,7 +37,7 @@ static int l_dnet_new (lua_State *L)
{
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_setmetatable(L, -2);
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))
{
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);
if (*eth == NULL)
luaL_error(L, "unable to open dnet on ethernet interface %s", device);

View File

@@ -220,7 +220,7 @@ static int dir_iter_factory (lua_State *L) {
const char *path = luaL_checkstring (L, 1);
dir_data *d;
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);
lua_setmetatable (L, -2);
d->closed = 0;

View File

@@ -335,7 +335,7 @@ static int l_session_open (lua_State *L) {
luaL_checkinteger(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);
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) {
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
&& libssh2_session_last_errno(state->session) == LIBSSH2_ERROR_EAGAIN) {

View File

@@ -91,7 +91,7 @@ static nsock_pool new_pool (lua_State *L)
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;
lua_newtable(L);
lua_pushcfunction(L, gc_pool);
@@ -751,8 +751,8 @@ static int l_get_info (lua_State *L)
int af; // address family
struct sockaddr_storage local;
struct sockaddr_storage remote;
char *ipstring_local = (char *) lua_newuserdata(L, sizeof(char) * INET6_ADDRSTRLEN);
char *ipstring_remote = (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_newuserdatauv(L, sizeof(char) * INET6_ADDRSTRLEN, 0);
nsock_iod_get_communication_info(nu->nsiod, &protocol, &af,
(struct sockaddr*)&local, (struct sockaddr*)&remote,
@@ -812,7 +812,7 @@ static int l_sleep (lua_State *L)
/* Convert to milliseconds for nsock_timer_create. */
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);
lua_pushvalue(L, NSOCK_POOL);
lua_pushcclosure(L, sleep_destructor, 1);
@@ -930,7 +930,7 @@ static int l_new (lua_State *L)
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_setmetatable(L, -2);
initialize(L, 1, nu, proto, af);

View File

@@ -43,7 +43,7 @@ typedef struct bignum_data {
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" );
lua_setmetatable( L, -2 );
data->bn = num;

View File

@@ -160,13 +160,13 @@ static void obj_to_key(lua_State *L, const ASN1_OBJECT *obj)
nid = OBJ_obj2nid(obj);
if (nid == NID_undef) {
size_t size = 1;
char *buf = (char *) lua_newuserdata(L, size);
char *buf = (char *) lua_newuserdatauv(L, size, 0);
const char *p, *q;
int i, n;
while ((n = OBJ_obj2txt(buf, size, obj, 1)) < 0 || (unsigned) n >= size) {
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));
lua_replace(L, -2);
}
@@ -555,7 +555,7 @@ static int parse_ssl_cert(lua_State *L, X509 *cert)
EVP_PKEY *pubkey;
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;
#define NSE_NUM_CERT_FIELDS 7

View File

@@ -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) {
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);
lua_setmetatable(L, -2); /* set metatable */