1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Don't pad shrunk POST'ed files.

Message-ID: <m3u17dn1qk.fsf@hniksic.iskon.hr>
This commit is contained in:
hniksic 2003-09-15 15:09:17 -07:00
parent d54b2a086d
commit 0e77942233
2 changed files with 13 additions and 24 deletions

View File

@ -1,3 +1,8 @@
2003-09-16 Hrvoje Niksic <hniksic@xemacs.org>
* http.c (post_file): Don't pad the file if it's not large
enough. Bail out instead.
2003-09-15 Hrvoje Niksic <hniksic@xemacs.org> 2003-09-15 Hrvoje Niksic <hniksic@xemacs.org>
* retr.c (get_contents): Reduce the buffer size to the amount of * retr.c (get_contents): Reduce the buffer size to the amount of

View File

@ -185,8 +185,7 @@ parse_http_status_line (const char *line, const char **reason_phrase_ptr)
/* Send the contents of FILE_NAME to SOCK/SSL. Make sure that exactly /* Send the contents of FILE_NAME to SOCK/SSL. Make sure that exactly
PROMISED_SIZE bytes are sent over the wire -- if the file is PROMISED_SIZE bytes are sent over the wire -- if the file is
longer, read only that much; if the file is shorter, pad it with longer, read only that much; if the file is shorter, report an error. */
zeros. */
static int static int
post_file (int sock, void *ssl, const char *file_name, long promised_size) post_file (int sock, void *ssl, const char *file_name, long promised_size)
@ -204,8 +203,8 @@ post_file (int sock, void *ssl, const char *file_name, long promised_size)
fp = fopen (file_name, "rb"); fp = fopen (file_name, "rb");
if (!fp) if (!fp)
goto pad; return -1;
while (written < promised_size) while (!feof (fp) && written < promised_size)
{ {
int towrite; int towrite;
int length = fread (chunk, 1, sizeof (chunk), fp); int length = fread (chunk, 1, sizeof (chunk), fp);
@ -227,29 +226,14 @@ post_file (int sock, void *ssl, const char *file_name, long promised_size)
} }
fclose (fp); fclose (fp);
pad: /* If we've written less than was promised, report a (probably
nonsensical) error rather than break the promise. */
if (written < promised_size) if (written < promised_size)
{ {
/* This highly unlikely case can happen only if the file has errno = EINVAL;
shrunk under us. To uphold the promise that exactly return -1;
promised_size bytes would be delivered, pad the remaining
data with zeros. #### Should we abort instead? */
DEBUGP (("padding %ld bytes ... ", promised_size - written));
memset (chunk, '\0', sizeof (chunk));
while (written < promised_size)
{
int towrite = WMIN (promised_size - written, sizeof (chunk));
#ifdef HAVE_SSL
if (ssl)
write_error = ssl_iwrite (ssl, chunk, towrite);
else
#endif
write_error = iwrite (sock, chunk, towrite);
if (write_error < 0)
return -1;
written += towrite;
}
} }
assert (written == promised_size); assert (written == promised_size);
DEBUGP (("done]\n")); DEBUGP (("done]\n"));
return 0; return 0;