From b8f7d94ef15b93c98cda472a32227d84a3ac5f72 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Tue, 28 Nov 2000 09:05:47 +0000 Subject: [PATCH] James Griffiths' max-redirs fix --- lib/highlevel.c | 10 ++++++++-- lib/url.c | 3 +++ lib/urldata.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/highlevel.c b/lib/highlevel.c index dc7acc130..b3bb9e157 100644 --- a/lib/highlevel.c +++ b/lib/highlevel.c @@ -624,11 +624,17 @@ CURLcode curl_transfer(CURL *curl) if((res == CURLE_OK) && data->newurl) { /* Location: redirect - + This is assumed to happen for HTTP(S) only! - */ + */ char prot[16]; char path[URL_MAX_LENGTH]; + if (data->maxredirs && (data->followlocation >= data->maxredirs)) { + failf(data,"Maximum (%d) redirects followed", data->maxredirs); + curl_disconnect(c_connect); + res=CURLE_TOO_MANY_REDIRECTS; + break; + } /* mark the next request as a followed location: */ data->bits.this_is_a_follow = TRUE; diff --git a/lib/url.c b/lib/url.c index 9522034f0..2d88aa495 100644 --- a/lib/url.c +++ b/lib/url.c @@ -478,6 +478,9 @@ CURLcode curl_setopt(CURL *curl, CURLoption option, ...) case CURLOPT_TIMEOUT: data->timeout = va_arg(param, long); break; + case CURLOPT_MAXREDIRS: + data->maxredirs = va_arg(param, long); + break; case CURLOPT_USERAGENT: data->useragent = va_arg(param, char *); break; diff --git a/lib/urldata.h b/lib/urldata.h index a0df9b4ff..45b632bbf 100644 --- a/lib/urldata.h +++ b/lib/urldata.h @@ -417,6 +417,7 @@ struct UrlData { /* stuff related to HTTP */ long followlocation; + long maxredirs; /* maximum no. of http(s) redirects to follow */ char *referer; bool free_referer; /* set TRUE if 'referer' points to a string we allocated */