]> sourceware.org Git - systemtap.git/commitdiff
Translate transmission/reception of the expected package size to/from network byte...
authorDave Brolley <brolley@redhat.com>
Wed, 13 Oct 2010 20:15:58 +0000 (16:15 -0400)
committerDave Brolley <brolley@redhat.com>
Wed, 13 Oct 2010 20:21:42 +0000 (16:21 -0400)
stap-client-connect.c
stap-server-connect.c

index 6e14226518afa7f20f0ff356a4236e0da4799d4e..3521feb8e3fe438ca0c7c0d5613e061088615d10 100644 (file)
@@ -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. */
index fdf7f4e4dc6062116f279766943a6d4cbdd827d5..d9409ebe92f7f044456963d837187b0fdf32fc04 100644 (file)
@@ -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;
     }
 
This page took 0.02917 seconds and 5 git commands to generate.