From 565a8abffc78f9308e434c91bd77358ee780a9d3 Mon Sep 17 00:00:00 2001 From: bol-van Date: Mon, 9 Feb 2026 10:04:13 +0300 Subject: [PATCH] AI fixes --- nfq2/checksum.h | 8 ++++---- nfq2/darkmagic.c | 4 ++-- nfq2/helpers.c | 14 +++++++++++--- nfq2/helpers.h | 2 ++ nfq2/lua.c | 6 +++--- 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/nfq2/checksum.h b/nfq2/checksum.h index d23ab31..6689e0a 100644 --- a/nfq2/checksum.h +++ b/nfq2/checksum.h @@ -19,10 +19,10 @@ struct icmp46 uint16_t icmp_cksum; union { - uint32_t icmp_data32; - uint16_t icmp_data16[2]; - uint8_t icmp_data8[4]; - }; + uint32_t data32; + uint16_t data16[2]; + uint8_t data8[4]; + } data; }; uint16_t csum_tcpudp_magic(uint32_t saddr, uint32_t daddr, size_t len, uint8_t proto, uint16_t sum); diff --git a/nfq2/darkmagic.c b/nfq2/darkmagic.c index a7778a9..013b562 100644 --- a/nfq2/darkmagic.c +++ b/nfq2/darkmagic.c @@ -358,9 +358,9 @@ void str_icmphdr(char *s, size_t s_len, bool v6, const struct icmp46 *icmp) char stype[32]; str_icmp_type_name(stype,sizeof(stype),v6,icmp->icmp_type); if (icmp->icmp_type==ICMP_ECHO || icmp->icmp_type==ICMP_ECHOREPLY || icmp->icmp_type==ICMP6_ECHO_REQUEST || icmp->icmp_type==ICMP6_ECHO_REPLY) - snprintf(s,s_len,"icmp_type=%s icmp_code=%u id=0x%04X seq=%u",stype,icmp->icmp_code,ntohs(icmp->icmp_data16[0]),ntohs(icmp->icmp_data16[1])); + snprintf(s,s_len,"icmp_type=%s icmp_code=%u id=0x%04X seq=%u",stype,icmp->icmp_code,ntohs(icmp->data.data16[0]),ntohs(icmp->data.data16[1])); else - snprintf(s,s_len,"icmp_type=%s icmp_code=%u data=0x%08X",stype,icmp->icmp_code,ntohl(icmp->icmp_data32)); + snprintf(s,s_len,"icmp_type=%s icmp_code=%u data=0x%08X",stype,icmp->icmp_code,ntohl(icmp->data.data32)); } void print_icmphdr(const struct icmp46 *icmp, bool v6) { diff --git a/nfq2/helpers.c b/nfq2/helpers.c index a119030..3f89ac8 100644 --- a/nfq2/helpers.c +++ b/nfq2/helpers.c @@ -165,7 +165,7 @@ void expand_bits(void *target, const void *source, unsigned int source_bitlen, u unsigned int bitlen = target_bitlen>3; - if ((target_bytelen-bytelen)>=1) memset(target+bytelen,0,target_bytelen-bytelen); + if ((target_bytelen-bytelen)>=1) memset((uint8_t*)target+bytelen,0,target_bytelen-bytelen); memcpy(target,source,bytelen); if ((bitlen &= 7)) ((uint8_t*)target)[bytelen] = ((uint8_t*)source)[bytelen] & (~((1 << (8-bitlen)) - 1)); } @@ -504,6 +504,14 @@ int getentropy(void *buf, size_t len) } #endif + +ssize_t read_intr(int fd, void *buf, size_t count) +{ + ssize_t rd; + while ((rd=read(fd,buf,count))<0 && errno==EINTR); + return rd; +} + bool fill_crypto_random_bytes(uint8_t *p,size_t sz) { ssize_t rd; @@ -526,7 +534,7 @@ bool fill_crypto_random_bytes(uint8_t *p,size_t sz) { do { - if ((rd=read(fd,p,sz))>0) + if ((rd=read_intr(fd,p,sz))>0) { p+=rd; sz-=rd; } @@ -537,7 +545,7 @@ bool fill_crypto_random_bytes(uint8_t *p,size_t sz) { do { - if ((rd=read(fd,p,sz))>0) + if ((rd=read_intr(fd,p,sz))>0) { p+=rd; sz-=rd; } diff --git a/nfq2/helpers.h b/nfq2/helpers.h index ac49e65..f7f08b6 100644 --- a/nfq2/helpers.h +++ b/nfq2/helpers.h @@ -33,6 +33,8 @@ const char *strncasestr(const char *s,const char *find, size_t slen); // [a-zA-z][a-zA-Z0-9]* bool is_identifier(const char *p); +ssize_t read_intr(int fd, void *buf, size_t count); + bool load_file(const char *filename, off_t offset, void *buffer, size_t *buffer_size); bool save_file(const char *filename, const void *buffer, size_t buffer_size); bool append_to_list_file(const char *filename, const char *s); diff --git a/nfq2/lua.c b/nfq2/lua.c index 9849369..d7375e0 100644 --- a/nfq2/lua.c +++ b/nfq2/lua.c @@ -1422,7 +1422,7 @@ void lua_push_icmphdr(lua_State *L, const struct icmp46 *icmp, size_t len) lua_pushf_int(L,"icmp_type",icmp->icmp_type); lua_pushf_int(L,"icmp_code",icmp->icmp_code); lua_pushf_int(L,"icmp_cksum",ntohs(icmp->icmp_cksum)); - lua_pushf_lint(L,"icmp_data",ntohl(icmp->icmp_data32)); + lua_pushf_lint(L,"icmp_data",ntohl(icmp->data.data32)); } else lua_pushnil(L); @@ -2318,7 +2318,7 @@ bool lua_reconstruct_icmphdr(lua_State *L, int idx, struct icmp46 *icmp) lua_getfield(L,idx,"icmp_data"); if (lua_type(L,-1)!=LUA_TNUMBER) goto err; - icmp->icmp_data32 = htonl((uint32_t)lua_tolint(L,-1)); + icmp->data.data32 = htonl((uint32_t)lua_tolint(L,-1)); lua_pop(L, 1); lua_getfield(L,idx,"icmp_cksum"); @@ -3511,7 +3511,7 @@ static void *z_alloc(voidpf opaque, uInt items, uInt size) } static void z_free(voidpf opaque, voidpf address) { - return free(address); + free(address); } static int luacall_gzip_init(lua_State *L) {