bgoncalv / rpms / curl

Forked from rpms/curl 5 years ago
Clone
f7c8df0
From 61ae7e9ce77af86a7290fca8bf73c9798f80845c Mon Sep 17 00:00:00 2001
f7c8df0
From: Daniel Stenberg <daniel@haxx.se>
f7c8df0
Date: Sun, 21 Aug 2011 12:59:06 +0200
f7c8df0
Subject: [PATCH] main: fix segfault
f7c8df0
f7c8df0
Follow-up to commit 5eb2396cd as that wasn't complete.
f7c8df0
f7c8df0
At times HEADERFUNCTION+HEADERDATA was set only to have only HEADERDATA
f7c8df0
set in the subsequent loop which could cause a NULL to get sent as
f7c8df0
userdata to 'header_callback' which wasn't made to handle that.
f7c8df0
f7c8df0
Now HEADERFUNCTION is explicitly set to NULL if it isn't set to the
f7c8df0
callback.
f7c8df0
---
f7c8df0
 src/main.c |    8 ++++++--
f7c8df0
 1 files changed, 6 insertions(+), 2 deletions(-)
f7c8df0
f7c8df0
diff --git a/src/main.c b/src/main.c
f7c8df0
index 276718b..56cd133 100644
f7c8df0
--- a/src/main.c
f7c8df0
+++ b/src/main.c
e16b731
@@ -5270,8 +5270,6 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
f7c8df0
         my_setopt(curl, CURLOPT_QUOTE, config->quote);
f7c8df0
         my_setopt(curl, CURLOPT_POSTQUOTE, config->postquote);
f7c8df0
         my_setopt(curl, CURLOPT_PREQUOTE, config->prequote);
f7c8df0
-        my_setopt(curl, CURLOPT_HEADERDATA,
f7c8df0
-                  config->headerfile?&heads:NULL);
f7c8df0
         my_setopt_str(curl, CURLOPT_COOKIEFILE, config->cookiefile);
f7c8df0
         /* cookie jar was added in 7.9 */
f7c8df0
         if(config->cookiejar)
e16b731
@@ -5474,6 +5472,12 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
f7c8df0
           my_setopt(curl, CURLOPT_HEADERFUNCTION, header_callback);
f7c8df0
           my_setopt(curl, CURLOPT_HEADERDATA, &outs);
f7c8df0
         }
f7c8df0
+        else {
f7c8df0
+          /* if HEADERFUNCTION was set to something in the previous loop, it
f7c8df0
+             is important that we set it (back) to NULL now */
f7c8df0
+          my_setopt(curl, CURLOPT_HEADERFUNCTION, NULL);
f7c8df0
+          my_setopt(curl, CURLOPT_HEADERDATA, config->headerfile?&heads:NULL);
f7c8df0
+        }
f7c8df0
 
f7c8df0
         if(config->resolve)
f7c8df0
           /* new in 7.21.3 */
f7c8df0
-- 
f7c8df0
1.7.6
f7c8df0