|
Lines 192-199
static size_t
Link Here
|
| 192 |
parse_content_len(const char *data, size_t data_len) |
192 |
parse_content_len(const char *data, size_t data_len) |
| 193 |
{ |
193 |
{ |
| 194 |
size_t content_len = 0; |
194 |
size_t content_len = 0; |
|
|
195 |
const char *p = NULL; |
| 195 |
|
196 |
|
| 196 |
sscanf(data, "Content-Length: %d", &content_len); |
197 |
/* This is still technically wrong, since headers are case-insensitive |
|
|
198 |
* [RFC 2616, section 4.2], though this ought to catch the normal case. |
| 199 |
* Note: data is _not_ nul-terminated. |
| 200 |
*/ |
| 201 |
if (data_len > 16) { |
| 202 |
p = strncmp(data, "Content-Length: ", 16) == 0? data: NULL; |
| 203 |
if (!p) { |
| 204 |
p = g_strstr_len(data, data_len, "\nContent-Length: "); |
| 205 |
if (p) |
| 206 |
p += 1; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
/* If we can find a Content-Length header at all, try to sscanf it. |
| 211 |
* Response headers should end with at least \r\n, so sscanf is safe, |
| 212 |
* if we make sure that there is indeed a \n in our header. |
| 213 |
*/ |
| 214 |
if (p && g_strstr_len(p, data_len - (p - data), "\n")) { |
| 215 |
sscanf(p, "Content-Length: %u", (int *)&content_len); |
| 216 |
} |
| 197 |
|
217 |
|
| 198 |
return content_len; |
218 |
return content_len; |
| 199 |
} |
219 |
} |
|
Lines 272-278
static void grab_url_callback(gpointer d
Link Here
|
| 272 |
|
292 |
|
| 273 |
/* In with the new. */ |
293 |
/* In with the new. */ |
| 274 |
gunk->data_len = content_len; |
294 |
gunk->data_len = content_len; |
| 275 |
gunk->webdata = g_malloc(gunk->data_len); |
295 |
gunk->webdata = g_try_malloc(gunk->data_len); |
|
|
296 |
if (gunk->webdata == NULL) { |
| 297 |
gaim_debug(GAIM_DEBUG_ERROR, "gaim_url_fetch", "Failed to allocate %u bytes: %s\n", gunk->data_len, strerror(errno)); |
| 298 |
gaim_input_remove(gunk->inpa); |
| 299 |
close(sock); |
| 300 |
gunk->callback(gunk->data, NULL, 0); |
| 301 |
g_free(gunk->webdata); |
| 302 |
g_free(gunk->website); |
| 303 |
g_free(gunk->url); |
| 304 |
g_free(gunk); |
| 305 |
} |
| 306 |
|
| 276 |
} |
307 |
} |
| 277 |
else |
308 |
else |
| 278 |
gunk->newline = TRUE; |
309 |
gunk->newline = TRUE; |