mirror of
https://github.com/bol-van/zapret.git
synced 2025-04-19 05:22:58 +03:00
tpws : fix possible null pointer dereference
This commit is contained in:
parent
21bc7a8727
commit
5124817a41
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
162
tpws/chartree.c
162
tpws/chartree.c
@ -1,81 +1,81 @@
|
|||||||
#include "chartree.h"
|
#include "chartree.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
static char *DupLower(const char *s)
|
static char *DupLower(const char *s)
|
||||||
{
|
{
|
||||||
char *sp,*sl = strdup(s);
|
char *sp,*sl = strdup(s);
|
||||||
if (!sl) return false;
|
if (!sl) return false;
|
||||||
for(sp=sl;*sp;sp++) *sp=tolower(*sp);
|
for(sp=sl;*sp;sp++) *sp=tolower(*sp);
|
||||||
return sl;
|
return sl;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cptr *CharTreeInit(char c)
|
static cptr *CharTreeInit(char c)
|
||||||
{
|
{
|
||||||
cptr *p;
|
cptr *p;
|
||||||
p=(cptr *)calloc(1,sizeof(cptr));
|
p=(cptr *)calloc(1,sizeof(cptr));
|
||||||
if (p) p->chr = c;
|
if (p) p->chr = c;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
void CharTreeDestroy(cptr *p)
|
void CharTreeDestroy(cptr *p)
|
||||||
{
|
{
|
||||||
if (p)
|
if (p)
|
||||||
{
|
{
|
||||||
CharTreeDestroy(p->leaf);
|
CharTreeDestroy(p->leaf);
|
||||||
CharTreeDestroy(p->next);
|
CharTreeDestroy(p->next);
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static cptr *CharTreeFindChar(cptr *p,char c)
|
static cptr *CharTreeFindChar(cptr *p,char c)
|
||||||
{
|
{
|
||||||
while (p)
|
while (p)
|
||||||
{
|
{
|
||||||
if (p->chr==c) return p;
|
if (p->chr==c) return p;
|
||||||
p = p->next;
|
p = p->next;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
bool CharTreeAddStr(cptr **pp,const char *s)
|
bool CharTreeAddStr(cptr **pp,const char *s)
|
||||||
{
|
{
|
||||||
cptr *p;
|
cptr *p;
|
||||||
if (*pp)
|
if (*pp)
|
||||||
{
|
{
|
||||||
if (!(p=CharTreeFindChar(*pp,*s)))
|
if (!(p=CharTreeFindChar(*pp,*s)))
|
||||||
{
|
{
|
||||||
// already present. append to list head
|
// already present. append to list head
|
||||||
if (!(p = CharTreeInit(*s)))
|
if (!(p = CharTreeInit(*s)))
|
||||||
return false;
|
return false;
|
||||||
p->next = *pp;
|
p->next = *pp;
|
||||||
*pp = p;
|
*pp = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (!(p = *pp = CharTreeInit(*s))) return false;
|
if (!(p = *pp = CharTreeInit(*s))) return false;
|
||||||
if (!*s) return true;
|
if (!*s) return true;
|
||||||
return CharTreeAddStr(&p->leaf,s+1);
|
return CharTreeAddStr(&p->leaf,s+1);
|
||||||
}
|
}
|
||||||
bool CharTreeCheckStr(cptr *p,const char *s)
|
bool CharTreeCheckStr(cptr *p,const char *s)
|
||||||
{
|
{
|
||||||
p = CharTreeFindChar(p,*s);
|
p = CharTreeFindChar(p,*s);
|
||||||
if (!p) return false;
|
if (!p) return false;
|
||||||
if (!*s) return true;
|
if (!*s) return true;
|
||||||
return CharTreeCheckStr(p->leaf,s+1);
|
return CharTreeCheckStr(p->leaf,s+1);
|
||||||
}
|
}
|
||||||
bool CharTreeAddStrLower(cptr **pp,const char *s)
|
bool CharTreeAddStrLower(cptr **pp,const char *s)
|
||||||
{
|
{
|
||||||
bool b;
|
bool b;
|
||||||
char *sl = DupLower(s);
|
char *sl = DupLower(s);
|
||||||
if (!sl) return false;
|
if (!sl) return false;
|
||||||
b=CharTreeAddStr(pp,sl);
|
b=CharTreeAddStr(pp,sl);
|
||||||
free(sl);
|
free(sl);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
bool CharTreeCheckStrLower(cptr *pp,const char *s)
|
bool CharTreeCheckStrLower(cptr *pp,const char *s)
|
||||||
{
|
{
|
||||||
bool b;
|
bool b;
|
||||||
char *sl = DupLower(s);
|
char *sl = DupLower(s);
|
||||||
if (!sl) return false;
|
if (!sl) return false;
|
||||||
b=CharTreeCheckStr(pp,sl);
|
b=CharTreeCheckStr(pp,sl);
|
||||||
free(sl);
|
free(sl);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
typedef struct cptr
|
typedef struct cptr
|
||||||
{
|
{
|
||||||
char chr;
|
char chr;
|
||||||
struct cptr *leaf,*next;
|
struct cptr *leaf,*next;
|
||||||
} cptr;
|
} cptr;
|
||||||
|
|
||||||
void CharTreeDestroy(cptr *p);
|
void CharTreeDestroy(cptr *p);
|
||||||
bool CharTreeAddStr(cptr **pp,const char *s);
|
bool CharTreeAddStr(cptr **pp,const char *s);
|
||||||
bool CharTreeAddStrLower(cptr **pp,const char *s);
|
bool CharTreeAddStrLower(cptr **pp,const char *s);
|
||||||
bool CharTreeCheckStr(cptr *p,const char *s);
|
bool CharTreeCheckStr(cptr *p,const char *s);
|
||||||
bool CharTreeCheckStrLower(cptr *pp,const char *s);
|
bool CharTreeCheckStrLower(cptr *pp,const char *s);
|
||||||
|
@ -275,7 +275,7 @@ bool handle_epollin(tproxy_conn_t *conn, int *data_transferred) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.hostnospace && pHost[5] == ' ' && find_host(&pHost,buf,bs))
|
if (params.hostnospace && find_host(&pHost,buf,bs) && pHost[5] == ' ')
|
||||||
{
|
{
|
||||||
p = pHost + 6;
|
p = pHost + 6;
|
||||||
pos = p - buf;
|
pos = p - buf;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user