mirror of
https://github.com/bol-van/zapret2.git
synced 2026-03-14 06:13:09 +00:00
AI inspired fixes
This commit is contained in:
@@ -373,28 +373,28 @@ void print_icmphdr(const struct icmp46 *icmp, bool v6)
|
|||||||
|
|
||||||
bool proto_check_ipv4(const uint8_t *data, size_t len)
|
bool proto_check_ipv4(const uint8_t *data, size_t len)
|
||||||
{
|
{
|
||||||
return len >= sizeof(struct ip) && (data[0] & 0xF0) == 0x40 && (data[0] & 0x0F)>=5 &&
|
if (len < sizeof(struct ip)) return false;
|
||||||
len >= ((data[0] & 0x0F) << 2);
|
uint8_t off = ((struct ip*)data)->ip_hl << 2;
|
||||||
|
return off>=sizeof(struct ip) && len>=off;
|
||||||
}
|
}
|
||||||
// move to transport protocol
|
// move to transport protocol
|
||||||
void proto_skip_ipv4(const uint8_t **data, size_t *len)
|
void proto_skip_ipv4(const uint8_t **data, size_t *len)
|
||||||
{
|
{
|
||||||
size_t l;
|
uint8_t off = ((struct ip*)*data)->ip_hl << 2;
|
||||||
|
*data += off;
|
||||||
l = (**data & 0x0F) << 2;
|
*len -= off;
|
||||||
*data += l;
|
|
||||||
*len -= l;
|
|
||||||
}
|
}
|
||||||
bool proto_check_tcp(const uint8_t *data, size_t len)
|
bool proto_check_tcp(const uint8_t *data, size_t len)
|
||||||
{
|
{
|
||||||
return len >= sizeof(struct tcphdr) && len >= ((data[12] & 0xF0) >> 2);
|
if (len < sizeof(struct tcphdr)) return false;
|
||||||
|
uint8_t off = ((struct tcphdr*)data)->th_off << 2;
|
||||||
|
return off>=sizeof(struct tcphdr) && len>=off;
|
||||||
}
|
}
|
||||||
void proto_skip_tcp(const uint8_t **data, size_t *len)
|
void proto_skip_tcp(const uint8_t **data, size_t *len)
|
||||||
{
|
{
|
||||||
size_t l;
|
uint8_t off = ((struct tcphdr*)*data)->th_off << 2;
|
||||||
l = ((*data)[12] & 0xF0) >> 2;
|
*data += off;
|
||||||
*data += l;
|
*len -= off;
|
||||||
*len -= l;
|
|
||||||
}
|
}
|
||||||
bool proto_check_udp(const uint8_t *data, size_t len)
|
bool proto_check_udp(const uint8_t *data, size_t len)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -61,25 +61,27 @@ void replace_char(char *s, char from, char to)
|
|||||||
for(;*s;s++) if (*s==from) *s=to;
|
for(;*s;s++) if (*s==from) *s=to;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strncasestr(const char *s, const char *find, size_t slen)
|
const char *strncasestr(const char *s, const char *find, size_t slen)
|
||||||
{
|
{
|
||||||
char c, sc;
|
char c, sc;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if ((c = *find++) != '\0')
|
if ((c = *find++))
|
||||||
{
|
{
|
||||||
len = strlen(find);
|
len = strlen(find);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (slen-- < 1 || (sc = *s++) == '\0') return NULL;
|
if (!slen) return NULL;
|
||||||
} while (toupper(c) != toupper(sc));
|
slen--;
|
||||||
|
sc = *s++;
|
||||||
|
} while (toupper((unsigned char)c) != toupper((unsigned char)sc));
|
||||||
if (len > slen) return NULL;
|
if (len > slen) return NULL;
|
||||||
} while (strncasecmp(s, find, len) != 0);
|
} while (strncasecmp(s, find, len));
|
||||||
s--;
|
s--;
|
||||||
}
|
}
|
||||||
return (char *)s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool is_letter(char c)
|
static inline bool is_letter(char c)
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ void qsort_ssize_t(ssize_t *array, int ct);
|
|||||||
int str_index(const char **strs, int count, const char *str);
|
int str_index(const char **strs, int count, const char *str);
|
||||||
void rtrim(char *s);
|
void rtrim(char *s);
|
||||||
void replace_char(char *s, char from, char to);
|
void replace_char(char *s, char from, char to);
|
||||||
char *strncasestr(const char *s,const char *find, size_t slen);
|
const char *strncasestr(const char *s,const char *find, size_t slen);
|
||||||
// [a-zA-z][a-zA-Z0-9]*
|
// [a-zA-z][a-zA-Z0-9]*
|
||||||
bool is_identifier(const char *p);
|
bool is_identifier(const char *p);
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ static bool addpool(hostlist_pool **hostlist, char **s, const char *end, int *ct
|
|||||||
p = ++(*s);
|
p = ++(*s);
|
||||||
flags |= HOSTLIST_POOL_FLAG_STRICT_MATCH;
|
flags |= HOSTLIST_POOL_FLAG_STRICT_MATCH;
|
||||||
}
|
}
|
||||||
for (; p<end && *p && *p!=' ' && *p!='\t' && *p!='\r' && *p != '\n'; p++) *p=tolower(*p);
|
for (; p<end && *p && *p!=' ' && *p!='\t' && *p!='\r' && *p != '\n'; p++) *p=tolower((unsigned char)*p);
|
||||||
if (!HostlistPoolAddStrLen(hostlist, *s, p-*s, flags))
|
if (!HostlistPoolAddStrLen(hostlist, *s, p-*s, flags))
|
||||||
{
|
{
|
||||||
HostlistPoolDestroy(hostlist);
|
HostlistPoolDestroy(hostlist);
|
||||||
|
|||||||
@@ -1003,13 +1003,13 @@ static struct blob_item *load_const_blob_to_collection(const char *name, const v
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static bool parse_uid(const char *opt, uid_t *uid, gid_t *gid, int *gid_count, int max_gids)
|
static bool parse_uid(char *opt, uid_t *uid, gid_t *gid, int *gid_count, int max_gids)
|
||||||
{
|
{
|
||||||
unsigned int u;
|
unsigned int u;
|
||||||
char c, *p, *e;
|
char c, *p, *e;
|
||||||
|
|
||||||
*gid_count = 0;
|
*gid_count = 0;
|
||||||
if ((e = strchr(optarg, ':'))) *e++ = 0;
|
if ((e = strchr(opt, ':'))) *e++ = 0;
|
||||||
if (sscanf(opt, "%u", &u) != 1) return false;
|
if (sscanf(opt, "%u", &u) != 1) return false;
|
||||||
*uid = (uid_t)u;
|
*uid = (uid_t)u;
|
||||||
for (p = e; p; )
|
for (p = e; p; )
|
||||||
|
|||||||
Reference in New Issue
Block a user