Commit 4bdb664c authored by Olaf Flebbe's avatar Olaf Flebbe Committed by Yang Tse
Browse files

tool_cb_dbg.c: fix tool_cb_dbg() to behave properly even for size 0

curl segfault in debug callback triggered with CURLINFO_HEADER_OUT and size 0

bug: http://curl.haxx.se/bug/view.cgi?id=3511794
parent 459435dc
Loading
Loading
Loading
Loading
+12 −10
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ int tool_debug_cb(CURL *handle, curl_infotype type,

    switch(type) {
    case CURLINFO_HEADER_OUT:
      if(size > 0) {
        for(i = 0; i < size - 1; i++) {
          if(data[i] == '\n') { /* LF */
            if(!newl) {
@@ -121,6 +122,7 @@ int tool_debug_cb(CURL *handle, curl_infotype type,
        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;