mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
* Made '-' as file name to read cookies from equal stdin.
* I hope I finally removed 'empty cookies' crash
This commit is contained in:
parent
1d75889360
commit
9280c208d3
14
lib/cookie.c
14
lib/cookie.c
@ -102,7 +102,7 @@ struct Cookie *cookie_add(struct CookieInfo *c,
|
|||||||
/* we have a <what>=<this> pair or a 'secure' word here */
|
/* we have a <what>=<this> pair or a 'secure' word here */
|
||||||
if(strchr(ptr, '=')) {
|
if(strchr(ptr, '=')) {
|
||||||
name[0]=what[0]=0; /* init the buffers */
|
name[0]=what[0]=0; /* init the buffers */
|
||||||
if(2 == sscanf(ptr, "%" MAX_NAME_TXT "[^=]=%"
|
if(1 <= sscanf(ptr, "%" MAX_NAME_TXT "[^=]=%"
|
||||||
MAX_COOKIE_LINE_TXT "[^\r\n]",
|
MAX_COOKIE_LINE_TXT "[^\r\n]",
|
||||||
name, what)) {
|
name, what)) {
|
||||||
/* this is a legal <what>=<this> pair */
|
/* this is a legal <what>=<this> pair */
|
||||||
@ -317,6 +317,7 @@ struct CookieInfo *cookie_init(char *file)
|
|||||||
char line[MAX_COOKIE_LINE];
|
char line[MAX_COOKIE_LINE];
|
||||||
struct CookieInfo *c;
|
struct CookieInfo *c;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
bool fromfile=TRUE;
|
||||||
|
|
||||||
c = (struct CookieInfo *)malloc(sizeof(struct CookieInfo));
|
c = (struct CookieInfo *)malloc(sizeof(struct CookieInfo));
|
||||||
if(!c)
|
if(!c)
|
||||||
@ -324,7 +325,13 @@ struct CookieInfo *cookie_init(char *file)
|
|||||||
memset(c, 0, sizeof(struct CookieInfo));
|
memset(c, 0, sizeof(struct CookieInfo));
|
||||||
c->filename = strdup(file?file:"none"); /* copy the name just in case */
|
c->filename = strdup(file?file:"none"); /* copy the name just in case */
|
||||||
|
|
||||||
fp = file?fopen(file, "r"):NULL;
|
if(strequal(file, "-")) {
|
||||||
|
fp = stdin;
|
||||||
|
fromfile=FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
fp = file?fopen(file, "r"):NULL;
|
||||||
|
|
||||||
if(fp) {
|
if(fp) {
|
||||||
while(fgets(line, MAX_COOKIE_LINE, fp)) {
|
while(fgets(line, MAX_COOKIE_LINE, fp)) {
|
||||||
if(strnequal("Set-Cookie:", line, 11)) {
|
if(strnequal("Set-Cookie:", line, 11)) {
|
||||||
@ -344,7 +351,8 @@ struct CookieInfo *cookie_init(char *file)
|
|||||||
cookie_add(c, FALSE, lineptr);
|
cookie_add(c, FALSE, lineptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(fp);
|
if(fromfile)
|
||||||
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
|
Loading…
Reference in New Issue
Block a user