~ubuntu-branches/ubuntu/lucid/curl/lucid-security

« back to all changes in this revision

Viewing changes to tests/libtest/lib553.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2009-04-29 11:10:29 UTC
  • mfrom: (3.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090429111029-2j5eiyokfw2bw049
Tags: 7.19.4-1ubuntu1
* Merge from debian unstable, remaining changes:
  - Drop build dependencies: stunnel, libdb4.6-dev, libssh2-1-dev
  - Add build-dependency on openssh-server
  - Drop libssh2-1-dev from libcurl4-openssl-dev's Depends.
  - Call automake-1.9 with --add-missing --copy --force
* drop debian/patches/security_CVE-2009-0037.patch 
  - this patch is part of 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *                            | (__| |_| |  _ <| |___
6
6
 *                             \___|\___/|_| \_\_____|
7
7
 *
8
 
 * $Id: lib553.c,v 1.2 2008-05-22 21:49:53 danf Exp $
 
8
 * $Id: lib553.c,v 1.5 2008-10-01 17:34:25 danf Exp $
9
9
 *
10
10
 * This test case and code is based on the bug recipe Joe Malicki provided for
11
11
 * bug report #1871269, fixed on Jan 14 2008 before the 7.18.0 release.
13
13
 
14
14
#include "test.h"
15
15
 
 
16
#include "memdebug.h"
 
17
 
16
18
#define POSTLEN 40960
17
19
 
18
20
static size_t myreadfunc(void *ptr, size_t size, size_t nmemb, void *stream)
39
41
#define SIZE_HEADERS 5000
40
42
 
41
43
static char buf[SIZE_HEADERS + 100];
 
44
 
42
45
int test(char *URL)
43
46
{
44
47
  CURL *curl;
45
 
  CURLcode res;
 
48
  CURLcode res = CURLE_FAILED_INIT;
46
49
  int i;
47
 
  struct curl_slist *headerlist=NULL;
 
50
  struct curl_slist *headerlist=NULL, *hl;
48
51
 
49
52
  curl_global_init(CURL_GLOBAL_ALL);
50
53
  curl = curl_easy_init();
51
54
 
52
 
  for (i = 0; i < NUM_HEADERS; i++) {
53
 
    int len;
54
 
    len = sprintf(buf, "Header%d: ", i);
55
 
    memset(&buf[len], 'A', SIZE_HEADERS);
56
 
    buf[len + SIZE_HEADERS]=0; /* zero terminate */
57
 
    headerlist = curl_slist_append(headerlist,  buf);
 
55
  if(curl) {
 
56
    for (i = 0; i < NUM_HEADERS; i++) {
 
57
      int len = sprintf(buf, "Header%d: ", i);
 
58
      memset(&buf[len], 'A', SIZE_HEADERS);
 
59
      buf[len + SIZE_HEADERS]=0; /* zero terminate */
 
60
      hl = curl_slist_append(headerlist,  buf);
 
61
      if (!hl)
 
62
        goto errout;
 
63
      headerlist = hl;
 
64
    }
 
65
    hl = curl_slist_append(headerlist, "Expect: ");
 
66
    if (!hl)
 
67
      goto errout;
 
68
    headerlist = hl;
 
69
 
 
70
    curl_easy_setopt(curl, CURLOPT_URL, URL);
 
71
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
 
72
    curl_easy_setopt(curl, CURLOPT_POST, 1L);
 
73
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
 
74
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
 
75
    curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
 
76
    curl_easy_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
 
77
    res = curl_easy_perform(curl);
 
78
 
 
79
errout:
 
80
    curl_easy_cleanup(curl);
 
81
 
 
82
    curl_slist_free_all(headerlist);
58
83
  }
59
 
  headerlist = curl_slist_append(headerlist, "Expect: ");
60
 
 
61
 
  curl_easy_setopt(curl, CURLOPT_URL, URL);
62
 
  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
63
 
  curl_easy_setopt(curl, CURLOPT_POST, 1L);
64
 
  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)POSTLEN);
65
 
  curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
66
 
  curl_easy_setopt(curl, CURLOPT_HEADER, 1L);
67
 
  curl_easy_setopt(curl, CURLOPT_READFUNCTION, myreadfunc);
68
 
  res = curl_easy_perform(curl);
69
 
  curl_easy_cleanup(curl);
70
 
 
71
 
  curl_slist_free_all(headerlist);
 
84
  curl_global_cleanup();
72
85
 
73
86
  return (int)res;
74
87
}