From 80303366aeb158f1780e4ff5acec8e9df7db83df Mon Sep 17 00:00:00 2001 From: Romain Bentz Date: Wed, 10 Jun 2015 10:46:12 +0200 Subject: [PATCH] Add NULL value check to fix #45289 * src/recur.c (retrieve_tree): Check return value of url_parse() --- src/recur.c | 93 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/src/recur.c b/src/recur.c index 03d61b83..7240841b 100644 --- a/src/recur.c +++ b/src/recur.c @@ -298,52 +298,63 @@ retrieve_tree (struct url *start_url_parsed, struct iri *pi) char *redirected = NULL; struct url *url_parsed = url_parse (url, &url_err, i, true); - status = retrieve_url (url_parsed, url, &file, &redirected, referer, - &dt, false, i, true); - - if (html_allowed && file && status == RETROK - && (dt & RETROKF) && (dt & TEXTHTML)) + if (!url_parsed) { - descend = true; - is_css = false; - } - - /* a little different, css_allowed can override content type - lots of web servers serve css with an incorrect content type - */ - if (file && status == RETROK - && (dt & RETROKF) && - ((dt & TEXTCSS) || css_allowed)) - { - descend = true; - is_css = true; - } - - if (redirected) - { - /* We have been redirected, possibly to another host, or - different path, or wherever. Check whether we really - want to follow it. */ - if (descend) - { - if (!descend_redirect_p (redirected, url_parsed, depth, - start_url_parsed, blacklist, i)) - descend = false; - else - /* Make sure that the old pre-redirect form gets - blacklisted. */ - blacklist_add (blacklist, url); - } - - xfree (url); - url = redirected; + char *error = url_error (url, url_err); + logprintf (LOG_NOTQUIET, "%s: %s.\n",url, error); + xfree (error); + inform_exit_status (URLERROR); } else { - xfree (url); - url = xstrdup (url_parsed->url); + + status = retrieve_url (url_parsed, url, &file, &redirected, referer, + &dt, false, i, true); + + if (html_allowed && file && status == RETROK + && (dt & RETROKF) && (dt & TEXTHTML)) + { + descend = true; + is_css = false; + } + + /* a little different, css_allowed can override content type + lots of web servers serve css with an incorrect content type + */ + if (file && status == RETROK + && (dt & RETROKF) && + ((dt & TEXTCSS) || css_allowed)) + { + descend = true; + is_css = true; + } + + if (redirected) + { + /* We have been redirected, possibly to another host, or + different path, or wherever. Check whether we really + want to follow it. */ + if (descend) + { + if (!descend_redirect_p (redirected, url_parsed, depth, + start_url_parsed, blacklist, i)) + descend = false; + else + /* Make sure that the old pre-redirect form gets + blacklisted. */ + blacklist_add (blacklist, url); + } + + xfree (url); + url = redirected; + } + else + { + xfree (url); + url = xstrdup (url_parsed->url); + } + url_free (url_parsed); } - url_free (url_parsed); } if (opt.spider)