Skip to content

Commit

Permalink
fix segfault and bigger cookie storage size
Browse files Browse the repository at this point in the history
  • Loading branch information
pracj3am committed Sep 23, 2014
1 parent 3faa13f commit 0b82487
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion crawler.c
Original file line number Diff line number Diff line change
Expand Up @@ -690,14 +690,15 @@ static void setcookie(struct surl *u,char *str) {
u->cookiecnt++;
}

if (u->cookiecnt < sizeof(u->cookies)/sizeof(*u->cookies)) {
if (t < sizeof(u->cookies)/sizeof(*u->cookies)) {
u->cookies[t].name = cookie.name;
u->cookies[t].value = cookie.value;
u->cookies[t].domain = cookie.domain;
u->cookies[t].secure = cookie.secure;
u->cookies[t].host_only = cookie.host_only;
debugf("[%d] Storing cookie #%d: name='%s', value='%s', domain='%s', host_only=%d, secure=%d\n",u->index,t,cookie.name,cookie.value,cookie.domain,cookie.host_only,cookie.secure);
} else {
u->cookiecnt--;
debugf("[%d] Not enough memory for storing cookies\n",u->index);
}

Expand Down
3 changes: 2 additions & 1 deletion h/struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
enum {
BUFSIZE = 700*1024,
MAXURLSIZE = 4096,
COOKIESTORAGESIZE = 25,
};

enum {
Expand Down Expand Up @@ -126,7 +127,7 @@ struct surl {
char redirectedto[MAXURLSIZE]; // co nakonec hlasime ve vystupu v hlavicce
int chunked; // 1 pokud transfer-encoding: chunked
int nextchunkedpos;
struct cookie cookies[20];
struct cookie cookies[COOKIESTORAGESIZE];
int cookiecnt;
char customparam[256]; // parametr do custom headeru
char charset[32];
Expand Down
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void initurls(int argc, char *argv[])
{
struct surl *curl, *purl;
char *p, *q;
struct cookie cookies[20];
struct cookie cookies[COOKIESTORAGESIZE];
int ccnt = 0, i = 0;

url = (struct surl *)malloc(sizeof(struct surl));
Expand All @@ -43,7 +43,7 @@ void initurls(int argc, char *argv[])
if(!strncmp(argv[t], "-A", 2)) {sprintf(settings.customagent,"%.*s", I_LENGTHOF(settings.customagent), argv[t+1]); t++; debugf("Custom agent: %s\n",settings.customagent); continue;}
if(!strncmp(argv[t], "-b", 2)) {
p = argv[t+1];
while (p[0] != '\0' && ccnt < 20) {
while (p[0] != '\0' && ccnt < COOKIESTORAGESIZE) {
q = strchrnul(p, '\n');
cookies[ccnt].name = malloc(q-p);
cookies[ccnt].value = malloc(q-p);
Expand Down

0 comments on commit 0b82487

Please sign in to comment.