if HOME isn't set or too long, we attempt to lost the curlrc file from

current directory instead!
This commit is contained in:
Daniel Stenberg 2002-04-05 15:04:04 +00:00
parent 4db8c8b1a3
commit edbe0d166c

View File

@ -1604,27 +1604,28 @@ static int parseconfig(char *filename,
{ {
int res; int res;
FILE *file; FILE *file;
char filebuffer[256]; char filebuffer[512];
bool usedarg; bool usedarg;
char *home=NULL; char *home;
if(!filename || !*filename) { if(!filename || !*filename) {
/* NULL or no file name attempts to load .curlrc from the homedir! */ /* NULL or no file name attempts to load .curlrc from the homedir! */
#define CURLRC DOT_CHAR "curlrc" #define CURLRC DOT_CHAR "curlrc"
filename = CURLRC; /* sensible default */
home = curl_getenv("HOME"); /* portable environment reader */ home = curl_getenv("HOME"); /* portable environment reader */
if(!home) if(home) {
return 0; if(strlen(home)<(sizeof(filebuffer)-strlen(CURLRC))) {
if(strlen(home)>(sizeof(filebuffer)-strlen(CURLRC))) {
free(home);
return 0;
}
sprintf(filebuffer, "%s%s%s", home, DIR_CHAR, CURLRC); snprintf(filebuffer, sizeof(filebuffer),
"%s%s%s", home, DIR_CHAR, CURLRC);
filename = filebuffer; filename = filebuffer;
} }
free(home); /* we've used it, now free it */
}
}
if(strcmp(filename,"-")) if(strcmp(filename,"-"))
file = fopen(filename, "r"); file = fopen(filename, "r");
@ -1770,8 +1771,6 @@ static int parseconfig(char *filename,
if(file != stdin) if(file != stdin)
fclose(file); fclose(file);
} }
if(home)
free(home);
return 0; return 0;
} }