]> granicus.if.org Git - curl/commitdiff
tool_cb_dbg.c: fix tool_cb_dbg() to behave properly even for size 0
authorOlaf Flebbe <o.flebbe@science-computing.de>
Tue, 27 Mar 2012 07:32:19 +0000 (09:32 +0200)
committerYang Tse <yangsita@gmail.com>
Tue, 27 Mar 2012 20:16:25 +0000 (22:16 +0200)
curl segfault in debug callback triggered with CURLINFO_HEADER_OUT and size 0

bug: http://curl.haxx.se/bug/view.cgi?id=3511794

src/tool_cb_dbg.c

index 7ac9a7339a974332461b15f9f74fc11c877528a3..e92ad1ade8e54a8d83b30bc35a2d534985e1b9bf 100644 (file)
@@ -108,19 +108,21 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
 
     switch(type) {
     case CURLINFO_HEADER_OUT:
-      for(i = 0; i < size - 1; i++) {
-        if(data[i] == '\n') { /* LF */
-          if(!newl) {
-            fprintf(output, "%s%s ", timebuf, s_infotype[type]);
+      if(size > 0) {
+        for(i = 0; i < size - 1; i++) {
+          if(data[i] == '\n') { /* LF */
+            if(!newl) {
+              fprintf(output, "%s%s ", timebuf, s_infotype[type]);
+            }
+            (void)fwrite(data + st, i - st + 1, 1, output);
+            st = i + 1;
+            newl = FALSE;
           }
-          (void)fwrite(data + st, i - st + 1, 1, output);
-          st = i + 1;
-          newl = FALSE;
         }
+        if(!newl)
+          fprintf(output, "%s%s ", timebuf, s_infotype[type]);
+        (void)fwrite(data + st, i - st + 1, 1, output);
       }
-      if(!newl)
-        fprintf(output, "%s%s ", timebuf, s_infotype[type]);
-      (void)fwrite(data + st, i - st + 1, 1, output);
       newl = (size && (data[size - 1] != '\n')) ? TRUE : FALSE;
       traced_data = FALSE;
       break;