mirror of
https://github.com/nzp-team/fteqw.git
synced 2024-11-14 00:10:46 +00:00
Handle recursive redirects better, don't silently truncate redirects.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6327 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
268b28a25d
commit
3369344387
2 changed files with 19 additions and 3 deletions
|
@ -520,7 +520,7 @@ static qboolean HTTP_DL_Work(struct dl_download *dl)
|
||||||
{
|
{
|
||||||
struct http_dl_ctx_s *con = dl->ctx;
|
struct http_dl_ctx_s *con = dl->ctx;
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
char Location[256];
|
char Location[4096];
|
||||||
char mimetype[256];
|
char mimetype[256];
|
||||||
char *nl;
|
char *nl;
|
||||||
char *msg;
|
char *msg;
|
||||||
|
@ -697,13 +697,19 @@ static qboolean HTTP_DL_Work(struct dl_download *dl)
|
||||||
else if (!strnicmp(msg, "Content-Type:", 13))
|
else if (!strnicmp(msg, "Content-Type:", 13))
|
||||||
{
|
{
|
||||||
*nl = '\0';
|
*nl = '\0';
|
||||||
|
//don't worry too much about truncation. its not like we can really do much with fancy mime types anyway.
|
||||||
COM_TrimString(msg+13, mimetype, sizeof(mimetype));
|
COM_TrimString(msg+13, mimetype, sizeof(mimetype));
|
||||||
*nl = '\n';
|
*nl = '\n';
|
||||||
}
|
}
|
||||||
else if (!strnicmp(msg, "Location: ", 10))
|
else if (!strnicmp(msg, "Location: ", 10))
|
||||||
{
|
{
|
||||||
*nl = '\0';
|
*nl = '\0';
|
||||||
COM_TrimString(msg+10, Location, sizeof(Location));
|
if (!COM_TrimString(msg+10, Location, sizeof(Location)))
|
||||||
|
{
|
||||||
|
Con_Printf("HTTP Redirect: location too long\n");
|
||||||
|
dl->status = DL_FAILED;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
*nl = '\n';
|
*nl = '\n';
|
||||||
}
|
}
|
||||||
else if (!strnicmp(msg, "Content-Encoding: ", 18))
|
else if (!strnicmp(msg, "Content-Encoding: ", 18))
|
||||||
|
@ -749,11 +755,20 @@ static qboolean HTTP_DL_Work(struct dl_download *dl)
|
||||||
nl = strchr(msg, '\n');
|
nl = strchr(msg, '\n');
|
||||||
if (nl)
|
if (nl)
|
||||||
*nl = '\0';
|
*nl = '\0';
|
||||||
Con_Printf("%s: %s %s (%s)\n", dl->url, buffer, COM_TrimString(msg, trimmed, sizeof(trimmed)), Location);
|
COM_TrimString(msg, trimmed, sizeof(trimmed));
|
||||||
|
Con_Printf("%s: %s %s (%s)\n", dl->url, buffer, trimmed, Location);
|
||||||
if (!*Location)
|
if (!*Location)
|
||||||
|
{
|
||||||
Con_Printf("Server redirected to null location\n");
|
Con_Printf("Server redirected to null location\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
if (dl->redircount++ > 10)
|
||||||
|
{
|
||||||
|
Con_Printf("HTTP: Recursive redirects\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
HTTP_Cleanup(dl);
|
HTTP_Cleanup(dl);
|
||||||
if (*Location == '/')
|
if (*Location == '/')
|
||||||
{
|
{
|
||||||
|
|
|
@ -99,6 +99,7 @@ struct dl_download
|
||||||
/*stream config*/
|
/*stream config*/
|
||||||
char *url; /*original url*/
|
char *url; /*original url*/
|
||||||
char redir[MAX_OSPATH]; /*current redirected url*/
|
char redir[MAX_OSPATH]; /*current redirected url*/
|
||||||
|
unsigned int redircount; /* so no infinite redirects with naughty servers.*/
|
||||||
char localname[MAX_OSPATH]; /*leave empty for a temp file*/
|
char localname[MAX_OSPATH]; /*leave empty for a temp file*/
|
||||||
enum fs_relative fsroot;
|
enum fs_relative fsroot;
|
||||||
struct vfsfile_s *file; /*downloaded to, if not already set when starting will open localname or a temp file*/
|
struct vfsfile_s *file; /*downloaded to, if not already set when starting will open localname or a temp file*/
|
||||||
|
|
Loading…
Reference in a new issue