From d74b2c505619306ab1ce3d4af3f66084b4faeed9 Mon Sep 17 00:00:00 2001 From: Corentin Chary Date: Mon, 18 Apr 2011 21:20:45 +0200 Subject: [PATCH] euscan: verify urls when redirected Reported-By: Daniel Pielmeier Signed-off-by: Corentin Chary --- euscan | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/euscan b/euscan index bea3399..c56b98a 100755 --- a/euscan +++ b/euscan @@ -175,23 +175,31 @@ def gen_versions(components, level): return versions -def tryurl(fileurl, output): +def tryurl(fileurl, output, regex): result = False output.ebegin("Trying: " + fileurl) try: + basename = os.path.basename(fileurl) + fp = urllib2.urlopen(fileurl, None, 5) headers = fp.info() - basename = os.path.basename(fileurl) - if 'Content-disposition' in headers and basename not in headers['Content-disposition']: result = False elif 'Content-Length' in headers and headers['Content-Length'] == '0': result = False elif 'text/html' in headers['Content-Type']: result = False + elif fp.geturl() != fileurl: + basename2 = os.path.basename(fp.geturl()) + + # Redirect to another (earlier?) version + if basename != basename2 and re.match(regex, fp.geturl()): + result = False + else: + result = True else: result = True except urllib2.URLError: @@ -388,8 +396,9 @@ def brute_force(cpv, fileurl, options, output, limit=None): continue url = url_from_template(template, vstring) + regex = regex_from_template(template) - if not tryurl(url, output): + if not tryurl(url, output, regex): continue result.append([url, vstring])