Blame SOURCES/wget-1.19.5-covscan-important-issues.patch

aa6d84
From b24351183ec574f81c729cbb3286aceaee3f03c8 Mon Sep 17 00:00:00 2001
aa6d84
From: Tomas Hozza <thozza@redhat.com>
aa6d84
Date: Mon, 30 Jul 2018 12:20:27 +0200
aa6d84
Subject: [PATCH 1/6] * src/ftp.c (getftp): Fix RESOURCE LEAK found by Coverity
aa6d84
aa6d84
Error: RESOURCE_LEAK (CWE-772):
aa6d84
wget-1.19.5/src/ftp.c:1493: alloc_fn: Storage is returned from allocation function "fopen".
aa6d84
wget-1.19.5/src/ftp.c:1493: var_assign: Assigning: "fp" = storage returned from "fopen(con->target, "wb")".
aa6d84
wget-1.19.5/src/ftp.c:1811: leaked_storage: Variable "fp" going out of scope leaks the storage it points to.
aa6d84
\# 1809|     if (fp && !output_stream)
aa6d84
\# 1810|       fclose (fp);
aa6d84
\# 1811|->   return err;
aa6d84
\# 1812|   }
aa6d84
\# 1813|
aa6d84
aa6d84
It can happen, that "if (!output_stream || con->cmd & DO_LIST)" on line #1398 can be true, even though "output_stream != NULL". In this case a new file is opened to "fp". Later it may happen in the FTPS branch, that some error will occure and code will jump to label "exit_error". In "exit_error", the "fp" is closed only if "output_stream == NULL". However this may not be true as described earlier and "fp" leaks.
aa6d84
aa6d84
On line #1588, there is the following conditional free of "fp":
aa6d84
aa6d84
  /* Close the local file.  */
aa6d84
  if (!output_stream || con->cmd & DO_LIST)
aa6d84
    fclose (fp);
aa6d84
aa6d84
Therefore the conditional at the end of the function after "exit_error" label should be modified to:
aa6d84
aa6d84
  if (fp && (!output_stream || con->cmd & DO_LIST))
aa6d84
    fclose (fp);
aa6d84
aa6d84
This will ensure that "fp" does not leak in any case it sould be opened.
aa6d84
aa6d84
Signed-off-by: Tomas Hozza <thozza@redhat.com>
aa6d84
---
aa6d84
 src/ftp.c | 2 +-
aa6d84
 1 file changed, 1 insertion(+), 1 deletion(-)
aa6d84
aa6d84
diff --git a/src/ftp.c b/src/ftp.c
aa6d84
index 69148936..daaae939 100644
aa6d84
--- a/src/ftp.c
aa6d84
+++ b/src/ftp.c
aa6d84
@@ -1806,7 +1806,7 @@ Error in server response, closing control connection.\n"));
aa6d84
 exit_error:
aa6d84
 
aa6d84
   /* If fp is a regular file, close and try to remove it */
aa6d84
-  if (fp && !output_stream)
aa6d84
+  if (fp && (!output_stream || con->cmd & DO_LIST))
aa6d84
     fclose (fp);
aa6d84
   return err;
aa6d84
 }
aa6d84
-- 
aa6d84
2.17.1
aa6d84
aa6d84
aa6d84
From b8be904ac7c25387672b0aa39f7cba699bffc48e Mon Sep 17 00:00:00 2001
aa6d84
From: Tomas Hozza <thozza@redhat.com>
aa6d84
Date: Mon, 30 Jul 2018 15:38:45 +0200
aa6d84
Subject: [PATCH 2/6] * src/http.c (check_auth): Fix RESOURCE LEAK found by
aa6d84
 Coverity
aa6d84
aa6d84
Error: RESOURCE_LEAK (CWE-772):
aa6d84
wget-1.19.5/src/http.c:2434: alloc_fn: Storage is returned from allocation function "xmalloc".
aa6d84
wget-1.19.5/lib/xmalloc.c:41:11: alloc_fn: Storage is returned from allocation function "malloc".
aa6d84
wget-1.19.5/lib/xmalloc.c:41:11: var_assign: Assigning: "p" = "malloc(n)".
aa6d84
wget-1.19.5/lib/xmalloc.c:44:3: return_alloc: Returning allocated memory "p".
aa6d84
wget-1.19.5/src/http.c:2434: var_assign: Assigning: "auth_stat" = storage returned from "xmalloc(4UL)".
aa6d84
wget-1.19.5/src/http.c:2446: noescape: Resource "auth_stat" is not freed or pointed-to in "create_authorization_line".
aa6d84
wget-1.19.5/src/http.c:5203:70: noescape: "create_authorization_line(char const *, char const *, char const *, char const *, char const *, _Bool *, uerr_t *)" does not free or save its parameter "auth_err".
aa6d84
wget-1.19.5/src/http.c:2476: leaked_storage: Variable "auth_stat" going out of scope leaks the storage it points to.
aa6d84
\# 2474|                 /* Creating the Authorization header went wrong */
aa6d84
\# 2475|               }
aa6d84
\# 2476|->         }
aa6d84
\# 2477|         else
aa6d84
\# 2478|           {
aa6d84
aa6d84
Error: RESOURCE_LEAK (CWE-772):
aa6d84
wget-1.19.5/src/http.c:2431: alloc_fn: Storage is returned from allocation function "url_full_path".
aa6d84
wget-1.19.5/src/url.c:1105:19: alloc_fn: Storage is returned from allocation function "xmalloc".
aa6d84
wget-1.19.5/lib/xmalloc.c:41:11: alloc_fn: Storage is returned from allocation function "malloc".
aa6d84
wget-1.19.5/lib/xmalloc.c:41:11: var_assign: Assigning: "p" = "malloc(n)".
aa6d84
wget-1.19.5/lib/xmalloc.c:44:3: return_alloc: Returning allocated memory "p".
aa6d84
wget-1.19.5/src/url.c:1105:19: var_assign: Assigning: "full_path" = "xmalloc(length + 1)".
aa6d84
wget-1.19.5/src/url.c:1107:3: noescape: Resource "full_path" is not freed or pointed-to in function "full_path_write".
aa6d84
wget-1.19.5/src/url.c:1078:47: noescape: "full_path_write(struct url const *, char *)" does not free or save its parameter "where".
aa6d84
wget-1.19.5/src/url.c:1110:3: return_alloc: Returning allocated memory "full_path".
aa6d84
wget-1.19.5/src/http.c:2431: var_assign: Assigning: "pth" = storage returned from "url_full_path(u)".
aa6d84
wget-1.19.5/src/http.c:2446: noescape: Resource "pth" is not freed or pointed-to in "create_authorization_line".
aa6d84
wget-1.19.5/src/http.c:5203:40: noescape: "create_authorization_line(char const *, char const *, char const *, char const *, char const *, _Bool *, uerr_t *)" does not free or save its parameter "path".
aa6d84
wget-1.19.5/src/http.c:2476: leaked_storage: Variable "pth" going out of scope leaks the storage it points to.
aa6d84
\# 2474|                 /* Creating the Authorization header went wrong */
aa6d84
\# 2475|               }
aa6d84
\# 2476|->         }
aa6d84
\# 2477|         else
aa6d84
\# 2478|           {
aa6d84
aa6d84
Both "pth" and "auth_stat" are allocated in "check_auth()" function. These are used for creating the HTTP Authorization Request header via "create_authorization_line()" function. In case the creation went OK (auth_err == RETROK), then the memory previously allocated to "pth" and "auth_stat" is freed. However if the creation failed, then the memory is never freed and it leaks.
aa6d84
aa6d84
Signed-off-by: Tomas Hozza <thozza@redhat.com>
aa6d84
---
aa6d84
 src/http.c | 4 ++--
aa6d84
 1 file changed, 2 insertions(+), 2 deletions(-)
aa6d84
aa6d84
diff --git a/src/http.c b/src/http.c
aa6d84
index 093be167..4e0d467a 100644
aa6d84
--- a/src/http.c
aa6d84
+++ b/src/http.c
aa6d84
@@ -2451,6 +2451,8 @@ check_auth (const struct url *u, char *user, char *passwd, struct response *resp
aa6d84
                                               auth_stat);
aa6d84
 
aa6d84
           auth_err = *auth_stat;
aa6d84
+          xfree (auth_stat);
aa6d84
+          xfree (pth);
aa6d84
           if (auth_err == RETROK)
aa6d84
             {
aa6d84
               request_set_header (req, "Authorization", value, rel_value);
aa6d84
@@ -2464,8 +2466,6 @@ check_auth (const struct url *u, char *user, char *passwd, struct response *resp
aa6d84
                   register_basic_auth_host (u->host);
aa6d84
                 }
aa6d84
 
aa6d84
-              xfree (pth);
aa6d84
-              xfree (auth_stat);
aa6d84
               *retry = true;
aa6d84
               goto cleanup;
aa6d84
             }
aa6d84
-- 
aa6d84
2.17.1
aa6d84
aa6d84
aa6d84
From dfef92bac3997b9848e86d84a843d5d7dde4fd99 Mon Sep 17 00:00:00 2001
aa6d84
From: Tomas Hozza <thozza@redhat.com>
aa6d84
Date: Tue, 31 Jul 2018 16:58:12 +0200
aa6d84
Subject: [PATCH 3/6] * src/http.c (http_loop): Fix RESOURCE LEAK found by
aa6d84
 Coverity
aa6d84
aa6d84
Error: RESOURCE_LEAK (CWE-772):
aa6d84
wget-1.19.5/src/http.c:4486: alloc_fn: Storage is returned from allocation function "url_string".
aa6d84
wget-1.19.5/src/url.c:2248:3: alloc_fn: Storage is returned from allocation function "xmalloc".
aa6d84
wget-1.19.5/lib/xmalloc.c:41:11: alloc_fn: Storage is returned from allocation function "malloc".
aa6d84
wget-1.19.5/lib/xmalloc.c:41:11: var_assign: Assigning: "p" = "malloc(n)".
aa6d84
wget-1.19.5/lib/xmalloc.c:44:3: return_alloc: Returning allocated memory "p".
aa6d84
wget-1.19.5/src/url.c:2248:3: var_assign: Assigning: "result" = "xmalloc(size)".
aa6d84
wget-1.19.5/src/url.c:2248:3: var_assign: Assigning: "p" = "result".
aa6d84
wget-1.19.5/src/url.c:2250:3: noescape: Resource "p" is not freed or pointed-to in function "memcpy". [Note: The source code implementation of the function has been overridden by a builtin model.]
aa6d84
wget-1.19.5/src/url.c:2253:7: noescape: Resource "p" is not freed or pointed-to in function "memcpy". [Note: The source code implementation of the function has been overridden by a builtin model.]
aa6d84
wget-1.19.5/src/url.c:2257:11: noescape: Resource "p" is not freed or pointed-to in function "memcpy". [Note: The source code implementation of the function has been overridden by a builtin model.]
aa6d84
wget-1.19.5/src/url.c:2264:3: noescape: Resource "p" is not freed or pointed-to in function "memcpy". [Note: The source code implementation of the function has been overridden by a builtin model.]
aa6d84
wget-1.19.5/src/url.c:2270:7: identity_transfer: Passing "p" as argument 1 to function "number_to_string", which returns an offset off that argument.
aa6d84
wget-1.19.5/src/utils.c:1776:11: var_assign_parm: Assigning: "p" = "buffer".
aa6d84
wget-1.19.5/src/utils.c:1847:3: return_var: Returning "p", which is a copy of a parameter.
aa6d84
wget-1.19.5/src/url.c:2270:7: noescape: Resource "p" is not freed or pointed-to in function "number_to_string".
aa6d84
wget-1.19.5/src/utils.c:1774:25: noescape: "number_to_string(char *, wgint)" does not free or save its parameter "buffer".
aa6d84
wget-1.19.5/src/url.c:2270:7: var_assign: Assigning: "p" = "number_to_string(p, url->port)".
aa6d84
wget-1.19.5/src/url.c:2273:3: noescape: Resource "p" is not freed or pointed-to in function "full_path_write".
aa6d84
wget-1.19.5/src/url.c:1078:47: noescape: "full_path_write(struct url const *, char *)" does not free or save its parameter "where".
aa6d84
wget-1.19.5/src/url.c:2287:3: return_alloc: Returning allocated memory "result".
aa6d84
wget-1.19.5/src/http.c:4486: var_assign: Assigning: "hurl" = storage returned from "url_string(u, URL_AUTH_HIDE_PASSWD)".
aa6d84
wget-1.19.5/src/http.c:4487: noescape: Resource "hurl" is not freed or pointed-to in "logprintf".
aa6d84
wget-1.19.5/src/http.c:4513: leaked_storage: Variable "hurl" going out of scope leaks the storage it points to.
aa6d84
\# 4511|               {
aa6d84
\# 4512|                 printwhat (count, opt.ntry);
aa6d84
\# 4513|->               continue;
aa6d84
\# 4514|               }
aa6d84
\# 4515|             else
aa6d84
aa6d84
There are two conditional branches, which call continue, without freeing memory potentially allocated and pointed to by"hurl" pointer. In fase "!opt.verbose" is True and some of the appropriate conditions in the following if/else if construction, in which "continue" is called, are also true, then the memory allocated to "hurl" will leak.
aa6d84
aa6d84
Signed-off-by: Tomas Hozza <thozza@redhat.com>
aa6d84
---
aa6d84
 src/http.c | 2 ++
aa6d84
 1 file changed, 2 insertions(+)
aa6d84
aa6d84
diff --git a/src/http.c b/src/http.c
aa6d84
index 4e0d467a..46fde6f2 100644
aa6d84
--- a/src/http.c
aa6d84
+++ b/src/http.c
aa6d84
@@ -4492,6 +4492,7 @@ http_loop (const struct url *u, struct url *original_url, char **newloc,
aa6d84
               && (hstat.statcode == 500 || hstat.statcode == 501))
aa6d84
             {
aa6d84
               got_head = true;
aa6d84
+              xfree (hurl);
aa6d84
               continue;
aa6d84
             }
aa6d84
           /* Maybe we should always keep track of broken links, not just in
aa6d84
@@ -4510,6 +4511,7 @@ Remote file does not exist -- broken link!!!\n"));
aa6d84
           else if (check_retry_on_http_error (hstat.statcode))
aa6d84
             {
aa6d84
               printwhat (count, opt.ntry);
aa6d84
+              xfree (hurl);
aa6d84
               continue;
aa6d84
             }
aa6d84
           else
aa6d84
-- 
aa6d84
2.17.1
aa6d84
aa6d84
aa6d84
From c045cdded4e3850724d8bb3a655852948e62c0df Mon Sep 17 00:00:00 2001
aa6d84
From: Tomas Hozza <thozza@redhat.com>
aa6d84
Date: Thu, 2 Aug 2018 13:49:52 +0200
aa6d84
Subject: [PATCH 4/6] * src/utils.c (open_stat): Fix RESOURCE LEAK found by
aa6d84
 Coverity
aa6d84
aa6d84
Error: RESOURCE_LEAK (CWE-772):
aa6d84
wget-1.19.5/src/utils.c:914: open_fn: Returning handle opened by "open". [Note: The source code implementation of the function has been overridden by a user model.]
aa6d84
wget-1.19.5/src/utils.c:914: var_assign: Assigning: "fd" = handle returned from "open(fname, flags, mode)".
aa6d84
wget-1.19.5/src/utils.c:921: noescape: Resource "fd" is not freed or pointed-to in "fstat". [Note: The source code implementation of the function has been overridden by a builtin model.]
aa6d84
wget-1.19.5/src/utils.c:924: leaked_handle: Handle variable "fd" going out of scope leaks the handle.
aa6d84
\#  922|     {
aa6d84
\#  923|       logprintf (LOG_NOTQUIET, _("Failed to stat file %s, error: %s\n"), fname, strerror(errno));
aa6d84
\#  924|->     return -1;
aa6d84
\#  925|     }
aa6d84
\#  926|   #if !(defined(WINDOWS) || defined(__VMS))
aa6d84
aa6d84
This seems to be a real issue, since the opened file descriptor in "fd"
aa6d84
would leak. There is also additional check below the "fstat" call, which
aa6d84
closes the opened "fd".
aa6d84
aa6d84
Signed-off-by: Tomas Hozza <thozza@redhat.com>
aa6d84
---
aa6d84
 src/utils.c | 1 +
aa6d84
 1 file changed, 1 insertion(+)
aa6d84
aa6d84
diff --git a/src/utils.c b/src/utils.c
aa6d84
index 0cb905ad..c6258083 100644
aa6d84
--- a/src/utils.c
aa6d84
+++ b/src/utils.c
aa6d84
@@ -921,6 +921,7 @@ open_stat(const char *fname, int flags, mode_t mode, file_stats_t *fstats)
aa6d84
   if (fstat (fd, &fdstats) == -1)
aa6d84
   {
aa6d84
     logprintf (LOG_NOTQUIET, _("Failed to stat file %s, error: %s\n"), fname, strerror(errno));
aa6d84
+    close (fd);
aa6d84
     return -1;
aa6d84
   }
aa6d84
 #if !(defined(WINDOWS) || defined(__VMS))
aa6d84
-- 
aa6d84
2.17.1
aa6d84
aa6d84
aa6d84
From 8b451f9f21cc1b00d1a08116b542fb7bd7589405 Mon Sep 17 00:00:00 2001
aa6d84
From: Tomas Hozza <thozza@redhat.com>
aa6d84
Date: Fri, 3 Aug 2018 16:19:20 +0200
aa6d84
Subject: [PATCH 5/6] * src/warc.c (warc_write_start_record): Fix potential
aa6d84
 RESOURCE LEAK
aa6d84
aa6d84
In warc_write_start_record() function, the reutrn value of dup() is
aa6d84
directly used in gzdopen() call and not stored anywhere. However the
aa6d84
zlib documentation says that "The duplicated descriptor should be saved
aa6d84
to avoid a leak, since gzdopen does not close fd if it fails." [1].
aa6d84
This change stores the FD in a variable and closes it in case gzopen()
aa6d84
fails.
aa6d84
aa6d84
[1] https://www.zlib.net/manual.html
aa6d84
aa6d84
Error: RESOURCE_LEAK (CWE-772):
aa6d84
wget-1.19.5/src/warc.c:217: open_fn: Returning handle opened by "dup".
aa6d84
wget-1.19.5/src/warc.c:217: leaked_handle: Failing to save or close handle opened by "dup(fileno(warc_current_file))" leaks it.
aa6d84
\#  215|
aa6d84
\#  216|         /* Start a new GZIP stream. */
aa6d84
\#  217|->       warc_current_gzfile = gzdopen (dup (fileno (warc_current_file)), "wb9");
aa6d84
\#  218|         warc_current_gzfile_uncompressed_size = 0;
aa6d84
\#  219|
aa6d84
aa6d84
Signed-off-by: Tomas Hozza <thozza@redhat.com>
aa6d84
---
aa6d84
 src/warc.c | 13 ++++++++++++-
aa6d84
 1 file changed, 12 insertions(+), 1 deletion(-)
aa6d84
aa6d84
diff --git a/src/warc.c b/src/warc.c
aa6d84
index 3482cf3b..5ebd04d7 100644
aa6d84
--- a/src/warc.c
aa6d84
+++ b/src/warc.c
aa6d84
@@ -203,6 +203,7 @@ warc_write_start_record (void)
aa6d84
   /* Start a GZIP stream, if required. */
aa6d84
   if (opt.warc_compression_enabled)
aa6d84
     {
aa6d84
+      int dup_fd;
aa6d84
       /* Record the starting offset of the new record. */
aa6d84
       warc_current_gzfile_offset = ftello (warc_current_file);
aa6d84
 
aa6d84
@@ -214,13 +215,23 @@ warc_write_start_record (void)
aa6d84
       fflush (warc_current_file);
aa6d84
 
aa6d84
       /* Start a new GZIP stream. */
aa6d84
-      warc_current_gzfile = gzdopen (dup (fileno (warc_current_file)), "wb9");
aa6d84
+      dup_fd = dup (fileno (warc_current_file));
aa6d84
+      if (dup_fd < 0)
aa6d84
+        {
aa6d84
+          logprintf (LOG_NOTQUIET,
aa6d84
+_("Error duplicating WARC file file descriptor.\n"));
aa6d84
+          warc_write_ok = false;
aa6d84
+          return false;
aa6d84
+        }
aa6d84
+
aa6d84
+      warc_current_gzfile = gzdopen (dup_fd, "wb9");
aa6d84
       warc_current_gzfile_uncompressed_size = 0;
aa6d84
 
aa6d84
       if (warc_current_gzfile == NULL)
aa6d84
         {
aa6d84
           logprintf (LOG_NOTQUIET,
aa6d84
 _("Error opening GZIP stream to WARC file.\n"));
aa6d84
+          close (dup_fd);
aa6d84
           warc_write_ok = false;
aa6d84
           return false;
aa6d84
         }
aa6d84
-- 
aa6d84
2.17.1
aa6d84
aa6d84
aa6d84
From 2f451dbf4e83c751f6bbba7ed26d90bf275fcbf7 Mon Sep 17 00:00:00 2001
aa6d84
From: Tomas Hozza <thozza@redhat.com>
aa6d84
Date: Fri, 24 Aug 2018 16:57:37 +0200
aa6d84
Subject: [PATCH 6/6] * src/warc.c (warc_write_cdx_record): Fix RESOURCE LEAK
aa6d84
 found by Coverity
aa6d84
aa6d84
Error: RESOURCE_LEAK (CWE-772): - REAL ERROR
aa6d84
wget-1.19.5/src/warc.c:1376: alloc_fn: Storage is returned from allocation function "url_escape".
aa6d84
wget-1.19.5/src/url.c:284:3: alloc_fn: Storage is returned from allocation function "url_escape_1".
aa6d84
wget-1.19.5/src/url.c:255:3: alloc_fn: Storage is returned from allocation function "xmalloc".
aa6d84
wget-1.19.5/lib/xmalloc.c:41:11: alloc_fn: Storage is returned from allocation function "malloc".
aa6d84
wget-1.19.5/lib/xmalloc.c:41:11: var_assign: Assigning: "p" = "malloc(n)".
aa6d84
wget-1.19.5/lib/xmalloc.c:44:3: return_alloc: Returning allocated memory "p".
aa6d84
wget-1.19.5/src/url.c:255:3: var_assign: Assigning: "newstr" = "xmalloc(newlen + 1)".
aa6d84
wget-1.19.5/src/url.c:258:3: var_assign: Assigning: "p2" = "newstr".
aa6d84
wget-1.19.5/src/url.c:275:3: return_alloc: Returning allocated memory "newstr".
aa6d84
wget-1.19.5/src/url.c:284:3: return_alloc_fn: Directly returning storage allocated by "url_escape_1".
aa6d84
wget-1.19.5/src/warc.c:1376: var_assign: Assigning: "redirect_location" = storage returned from "url_escape(redirect_location)".
aa6d84
wget-1.19.5/src/warc.c:1381: noescape: Resource "redirect_location" is not freed or pointed-to in "fprintf".
aa6d84
wget-1.19.5/src/warc.c:1387: leaked_storage: Returning without freeing "redirect_location" leaks the storage that it points to.
aa6d84
\# 1385|     fflush (warc_current_cdx_file);
aa6d84
\# 1386|
aa6d84
\# 1387|->   return true;
aa6d84
\# 1388|   }
aa6d84
\# 1389|
aa6d84
aa6d84
url_escape() really returns a newly allocated memory and it leaks when the warc_write_cdx_record() returns. The memory returned from url_escape() is usually stored in a temporary variable in other parts of the project and then freed. I took the same approach.
aa6d84
aa6d84
Signed-off-by: Tomas Hozza <thozza@redhat.com>
aa6d84
---
aa6d84
 src/warc.c | 8 +++++---
aa6d84
 1 file changed, 5 insertions(+), 3 deletions(-)
aa6d84
aa6d84
diff --git a/src/warc.c b/src/warc.c
aa6d84
index 5ebd04d7..2eb74966 100644
aa6d84
--- a/src/warc.c
aa6d84
+++ b/src/warc.c
aa6d84
@@ -1364,6 +1364,7 @@ warc_write_cdx_record (const char *url, const char *timestamp_str,
aa6d84
   char timestamp_str_cdx[15];
aa6d84
   char offset_string[MAX_INT_TO_STRING_LEN(off_t)];
aa6d84
   const char *checksum;
aa6d84
+  char *tmp_location = NULL;
aa6d84
 
aa6d84
   memcpy (timestamp_str_cdx     , timestamp_str     , 4); /* "YYYY" "-" */
aa6d84
   memcpy (timestamp_str_cdx +  4, timestamp_str +  5, 2); /* "mm"   "-" */
aa6d84
@@ -1382,18 +1383,19 @@ warc_write_cdx_record (const char *url, const char *timestamp_str,
aa6d84
   if (mime_type == NULL || strlen(mime_type) == 0)
aa6d84
     mime_type = "-";
aa6d84
   if (redirect_location == NULL || strlen(redirect_location) == 0)
aa6d84
-    redirect_location = "-";
aa6d84
+    tmp_location = strdup ("-");
aa6d84
   else
aa6d84
-    redirect_location = url_escape(redirect_location);
aa6d84
+    tmp_location = url_escape(redirect_location);
aa6d84
 
aa6d84
   number_to_string (offset_string, offset);
aa6d84
 
aa6d84
   /* Print the CDX line. */
aa6d84
   fprintf (warc_current_cdx_file, "%s %s %s %s %d %s %s - %s %s %s\n", url,
aa6d84
            timestamp_str_cdx, url, mime_type, response_code, checksum,
aa6d84
-           redirect_location, offset_string, warc_current_filename,
aa6d84
+           tmp_location, offset_string, warc_current_filename,
aa6d84
            response_uuid);
aa6d84
   fflush (warc_current_cdx_file);
aa6d84
+  free (tmp_location);
aa6d84
 
aa6d84
   return true;
aa6d84
 }
aa6d84
-- 
aa6d84
2.17.1
aa6d84