Browse Source

tpws : fix possible null pointer dereference

pull/21/head
bolvan 7 years ago
parent
commit
5124817a41
  1. BIN
      binaries/armhf/tpws
  2. BIN
      binaries/mips32r1-lsb/tpws
  3. BIN
      binaries/mips32r1-msb/tpws
  4. BIN
      binaries/x86_64/tpws
  5. 162
      tpws/chartree.c
  6. 32
      tpws/chartree.h
  7. 2
      tpws/tpws.c

BIN
binaries/armhf/tpws

Binary file not shown.

BIN
binaries/mips32r1-lsb/tpws

Binary file not shown.

BIN
binaries/mips32r1-msb/tpws

Binary file not shown.

BIN
binaries/x86_64/tpws

Binary file not shown.

162
tpws/chartree.c

@ -1,81 +1,81 @@
#include "chartree.h"
#include <string.h>
#include <stdlib.h>
static char *DupLower(const char *s)
{
char *sp,*sl = strdup(s);
if (!sl) return false;
for(sp=sl;*sp;sp++) *sp=tolower(*sp);
return sl;
}
static cptr *CharTreeInit(char c)
{
cptr *p;
p=(cptr *)calloc(1,sizeof(cptr));
if (p) p->chr = c;
return p;
}
void CharTreeDestroy(cptr *p)
{
if (p)
{
CharTreeDestroy(p->leaf);
CharTreeDestroy(p->next);
free(p);
}
}
static cptr *CharTreeFindChar(cptr *p,char c)
{
while (p)
{
if (p->chr==c) return p;
p = p->next;
}
return NULL;
}
bool CharTreeAddStr(cptr **pp,const char *s)
{
cptr *p;
if (*pp)
{
if (!(p=CharTreeFindChar(*pp,*s)))
{
// already present. append to list head
if (!(p = CharTreeInit(*s)))
return false;
p->next = *pp;
*pp = p;
}
}
else
if (!(p = *pp = CharTreeInit(*s))) return false;
if (!*s) return true;
return CharTreeAddStr(&p->leaf,s+1);
}
bool CharTreeCheckStr(cptr *p,const char *s)
{
p = CharTreeFindChar(p,*s);
if (!p) return false;
if (!*s) return true;
return CharTreeCheckStr(p->leaf,s+1);
}
bool CharTreeAddStrLower(cptr **pp,const char *s)
{
bool b;
char *sl = DupLower(s);
if (!sl) return false;
b=CharTreeAddStr(pp,sl);
free(sl);
return b;
}
bool CharTreeCheckStrLower(cptr *pp,const char *s)
{
bool b;
char *sl = DupLower(s);
if (!sl) return false;
b=CharTreeCheckStr(pp,sl);
free(sl);
return b;
}
#include "chartree.h"
#include <string.h>
#include <stdlib.h>
static char *DupLower(const char *s)
{
char *sp,*sl = strdup(s);
if (!sl) return false;
for(sp=sl;*sp;sp++) *sp=tolower(*sp);
return sl;
}
static cptr *CharTreeInit(char c)
{
cptr *p;
p=(cptr *)calloc(1,sizeof(cptr));
if (p) p->chr = c;
return p;
}
void CharTreeDestroy(cptr *p)
{
if (p)
{
CharTreeDestroy(p->leaf);
CharTreeDestroy(p->next);
free(p);
}
}
static cptr *CharTreeFindChar(cptr *p,char c)
{
while (p)
{
if (p->chr==c) return p;
p = p->next;
}
return NULL;
}
bool CharTreeAddStr(cptr **pp,const char *s)
{
cptr *p;
if (*pp)
{
if (!(p=CharTreeFindChar(*pp,*s)))
{
// already present. append to list head
if (!(p = CharTreeInit(*s)))
return false;
p->next = *pp;
*pp = p;
}
}
else
if (!(p = *pp = CharTreeInit(*s))) return false;
if (!*s) return true;
return CharTreeAddStr(&p->leaf,s+1);
}
bool CharTreeCheckStr(cptr *p,const char *s)
{
p = CharTreeFindChar(p,*s);
if (!p) return false;
if (!*s) return true;
return CharTreeCheckStr(p->leaf,s+1);
}
bool CharTreeAddStrLower(cptr **pp,const char *s)
{
bool b;
char *sl = DupLower(s);
if (!sl) return false;
b=CharTreeAddStr(pp,sl);
free(sl);
return b;
}
bool CharTreeCheckStrLower(cptr *pp,const char *s)
{
bool b;
char *sl = DupLower(s);
if (!sl) return false;
b=CharTreeCheckStr(pp,sl);
free(sl);
return b;
}

32
tpws/chartree.h

@ -1,16 +1,16 @@
#pragma once
#include <stdbool.h>
#include <ctype.h>
typedef struct cptr
{
char chr;
struct cptr *leaf,*next;
} cptr;
void CharTreeDestroy(cptr *p);
bool CharTreeAddStr(cptr **pp,const char *s);
bool CharTreeAddStrLower(cptr **pp,const char *s);
bool CharTreeCheckStr(cptr *p,const char *s);
bool CharTreeCheckStrLower(cptr *pp,const char *s);
#pragma once
#include <stdbool.h>
#include <ctype.h>
typedef struct cptr
{
char chr;
struct cptr *leaf,*next;
} cptr;
void CharTreeDestroy(cptr *p);
bool CharTreeAddStr(cptr **pp,const char *s);
bool CharTreeAddStrLower(cptr **pp,const char *s);
bool CharTreeCheckStr(cptr *p,const char *s);
bool CharTreeCheckStrLower(cptr *pp,const char *s);

2
tpws/tpws.c

@ -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;
pos = p - buf;

Loading…
Cancel
Save