diff --git a/crawler.c b/crawler.c index 7b22bc9..0b88622 100644 --- a/crawler.c +++ b/crawler.c @@ -690,7 +690,7 @@ 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; @@ -698,6 +698,7 @@ static void setcookie(struct surl *u,char *str) { 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); } diff --git a/h/struct.h b/h/struct.h index 215cd5c..325d978 100644 --- a/h/struct.h +++ b/h/struct.h @@ -3,6 +3,7 @@ enum { BUFSIZE = 700*1024, MAXURLSIZE = 4096, + COOKIESTORAGESIZE = 25, }; enum { @@ -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]; diff --git a/main.c b/main.c index e29ade2..cec9314 100644 --- a/main.c +++ b/main.c @@ -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)); @@ -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);