}
/* Send the file size first, so the server knows when it has the entire file. */
- numBytes = PR_Write(sslSocket, & info.size, sizeof (info.size));
+ numBytes = htonl ((PRInt32)info.size);
+ numBytes = PR_Write(sslSocket, & numBytes, sizeof (numBytes));
if (numBytes < 0)
- return SECFailure;
+ {
+ PR_Close(local_file_fd);
+ return SECFailure;
+ }
/* Transmit the local file across the socket. */
numBytes = PR_TransmitFile(sslSocket, local_file_fd,
PR_TRANSMITFILE_KEEP_OPEN,
PR_INTERVAL_NO_TIMEOUT);
if (numBytes < 0)
- return SECFailure;
+ {
+ PR_Close(local_file_fd);
+ return SECFailure;
+ }
#if DEBUG
/* Transmitted bytes successfully. */
static SECStatus readDataFromSocket(PRFileDesc *sslSocket, const char *requestFileName)
{
PRFileDesc *local_file_fd;
- PRFileInfo info;
+ PRInt32 numBytesExpected;
PRInt32 numBytesRead;
PRInt32 numBytesWritten;
PRInt32 totalBytes;
/* Read the number of bytes to be received. */
/* XXX: impose a limit to prevent disk space consumption DoS */
- numBytesRead = PR_Read(sslSocket, & info.size, sizeof (info.size));
+ numBytesRead = PR_Read(sslSocket, & numBytesExpected, sizeof (numBytesExpected));
if (numBytesRead == 0) /* EOF */
{
fprintf (stderr, "Error reading size of request file\n");
errWarn("PR_Read");
return SECFailure;
}
+ /* Convert numBytesExpected from network byte order to host byte order. */
+ numBytesExpected = ntohl (numBytesExpected);
/* Read until EOF or until the expected number of bytes has been read. */
- for (totalBytes = 0; totalBytes < info.size; totalBytes += numBytesRead)
+ for (totalBytes = 0; totalBytes < numBytesExpected; totalBytes += numBytesRead)
{
numBytesRead = PR_Read(sslSocket, buffer, READ_BUFFER_SIZE);
if (numBytesRead == 0)
#endif
}
- if (totalBytes != info.size)
+ if (totalBytes != numBytesExpected)
{
- fprintf (stderr, "Expected %d bytes, got %d\n", info.size, totalBytes);
+ fprintf (stderr, "Expected %d bytes, got %d\n", numBytesExpected, totalBytes);
return SECFailure;
}