~ubuntu-branches/ubuntu/lucid/libsoup2.4/lucid

« back to all changes in this revision

Viewing changes to libsoup/soup-multipart.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2009-12-01 16:23:28 UTC
  • mfrom: (10.1.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20091201162328-99owgw0n523dgf7b
Tags: 2.29.3-1
* New upstream development release:
  + debian/rules:
    - Include check-dist.mk to prevent accidental uploads to unstable.
    - Update SHVER to 2.29.3 for new API.
  + debian/patches/redirect_head.patch,
    debian/patches/sqlite_strcmp_null_string.patch:
    - Dropped, merged upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
}
99
99
 
100
100
static const char *
101
 
find_boundary (const char *start, const char *boundary, int boundary_len)
 
101
find_boundary (const char *start, const char *end,
 
102
               const char *boundary, int boundary_len)
102
103
{
103
 
        const char *b, *end;
104
 
 
105
 
        end = start + 2;
106
 
        while ((b = strstr (end, boundary))) {
107
 
                end = b + boundary_len;
108
 
                if (b[-1] == '-' && b[-2] == '-' &&
109
 
                    (b == start + 2 || (b[-3] == '\n' && b[-4] == '\r'))) {
110
 
                        if ((end[0] == '-' && end[1] == '-') ||
111
 
                            (end[0] == '\r' && end[1] == '\n'))
112
 
                                return b - 2;
113
 
                }
 
104
        const char *b;
 
105
 
 
106
        for (b = memchr (start, '-', end - start);
 
107
             b && b + boundary_len + 4 < end;
 
108
             b = memchr (b + 2, '-', end - (b + 2))) {
 
109
                /* Check for "--boundary" */
 
110
                if (b[1] != '-' ||
 
111
                    memcmp (b + 2, boundary, boundary_len) != 0)
 
112
                        continue;
 
113
 
 
114
                /* Check that it's at start of line */
 
115
                if (!(b == start || (b[-1] == '\n' && b[-2] == '\r')))
 
116
                        continue;
 
117
 
 
118
                /* Check for "--" or "\r\n" after boundary */
 
119
                if ((b[boundary_len + 2] == '-' && b[boundary_len + 3] == '-') ||
 
120
                    (b[boundary_len + 2] == '\r' && b[boundary_len + 3] == '\n'))
 
121
                        return b;
114
122
        }
115
123
        return NULL;
116
124
}
136
144
        GHashTable *params;
137
145
        int boundary_len;
138
146
        SoupBuffer *flattened;
139
 
        const char *start, *split, *end;
 
147
        const char *start, *split, *end, *body_end;
140
148
        SoupMessageHeaders *part_headers;
141
149
        SoupBuffer *part_body;
142
150
 
155
163
        g_hash_table_destroy (params);
156
164
 
157
165
        flattened = soup_message_body_flatten (body);
 
166
        body_end = flattened->data + flattened->length;
158
167
        boundary = multipart->boundary;
159
168
        boundary_len = strlen (boundary);
160
169
 
161
170
        /* skip preamble */
162
 
        start = find_boundary (flattened->data, boundary, boundary_len);
 
171
        start = find_boundary (flattened->data, body_end,
 
172
                               boundary, boundary_len);
163
173
        if (!start) {
164
174
                soup_multipart_free (multipart);
165
175
                soup_buffer_free (flattened);
167
177
        }
168
178
 
169
179
        while (start[2 + boundary_len] != '-') {
170
 
                end = find_boundary (start + 2 + boundary_len, boundary, boundary_len);
 
180
                end = find_boundary (start + 2 + boundary_len, body_end,
 
181
                                     boundary, boundary_len);
171
182
                if (!end) {
172
183
                        soup_multipart_free (multipart);
173
184
                        soup_buffer_free (flattened);