1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

If there is nothing to write do not even open the file for write (test

formdata length). Patch by Alexey Tourbin.
This commit is contained in:
Laurent MONIN 2007-03-05 21:37:24 +01:00 committed by Laurent MONIN
parent edb8d9001c
commit 5acb3a68fb

View File

@ -219,7 +219,7 @@ save_form_data_to_file(struct uri *uri)
unsigned char *filename = get_tempdir_filename("elinks-XXXXXX"); unsigned char *filename = get_tempdir_filename("elinks-XXXXXX");
int fd; int fd;
FILE *fp; FILE *fp;
size_t nmemb; size_t nmemb, len;
unsigned char *formdata; unsigned char *formdata;
if (!filename) return NULL; if (!filename) return NULL;
@ -232,6 +232,12 @@ save_form_data_to_file(struct uri *uri)
if (!uri->post) return filename; if (!uri->post) return filename;
/* Jump the content type */
formdata = strchr(uri->post, '\n');
formdata = formdata ? formdata + 1 : uri->post;
len = strlen(formdata);
if (len == 0) return filename;
fp = fdopen(fd, "w"); fp = fdopen(fd, "w");
if (!fp) { if (!fp) {
@ -242,11 +248,7 @@ error:
return NULL; return NULL;
} }
/* Jump the content type */ nmemb = fwrite(formdata, len, 1, fp);
formdata = strchr(uri->post, '\n');
formdata = formdata ? formdata + 1 : uri->post;
nmemb = fwrite(formdata, strlen(formdata), 1, fp);
if (nmemb != 1) { if (nmemb != 1) {
fclose(fp); fclose(fp);
goto error; goto error;