From 1530e613e7cccb77b294e7ab852fa3bf7fdbc567 Mon Sep 17 00:00:00 2001 From: Dave Brolley Date: Wed, 13 Oct 2010 16:15:58 -0400 Subject: [PATCH] Translate transmission/reception of the expected package size to/from network byte order. --- stap-client-connect.c | 13 ++++++++++--- stap-server-connect.c | 12 +++++++----- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/stap-client-connect.c b/stap-client-connect.c index 6e1422651..3521feb8e 100644 --- a/stap-client-connect.c +++ b/stap-client-connect.c @@ -247,9 +247,13 @@ handle_connection( } /* 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, @@ -257,7 +261,10 @@ handle_connection( 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. */ diff --git a/stap-server-connect.c b/stap-server-connect.c index fdf7f4e4d..d9409ebe9 100644 --- a/stap-server-connect.c +++ b/stap-server-connect.c @@ -97,7 +97,7 @@ exitErr(char *function) static SECStatus readDataFromSocket(PRFileDesc *sslSocket, const char *requestFileName) { PRFileDesc *local_file_fd; - PRFileInfo info; + PRInt32 numBytesExpected; PRInt32 numBytesRead; PRInt32 numBytesWritten; PRInt32 totalBytes; @@ -115,7 +115,7 @@ static SECStatus readDataFromSocket(PRFileDesc *sslSocket, const char *requestFi /* 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"); @@ -126,9 +126,11 @@ static SECStatus readDataFromSocket(PRFileDesc *sslSocket, const char *requestFi 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) @@ -155,9 +157,9 @@ static SECStatus readDataFromSocket(PRFileDesc *sslSocket, const char *requestFi #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; } -- 2.43.5