You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by mt...@apache.org on 2021/11/19 17:02:48 UTC

svn commit: r1895179 - /apr/apr/trunk/file_io/win32/pipe.c

Author: mturk
Date: Fri Nov 19 17:02:48 2021
New Revision: 1895179

URL: http://svn.apache.org/viewvc?rev=1895179&view=rev
Log:
Use random bytes like with named pipes as socket pipe identifier

Modified:
    apr/apr/trunk/file_io/win32/pipe.c

Modified: apr/apr/trunk/file_io/win32/pipe.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/file_io/win32/pipe.c?rev=1895179&r1=1895178&r2=1895179&view=diff
==============================================================================
--- apr/apr/trunk/file_io/win32/pipe.c (original)
+++ apr/apr/trunk/file_io/win32/pipe.c Fri Nov 19 17:02:48 2021
@@ -289,7 +289,6 @@ APR_DECLARE(apr_status_t) apr_os_pipe_pu
 
 static apr_status_t create_socket_pipe(SOCKET *rd, SOCKET *wr)
 {
-    static int id = 0;
     FD_SET rs;
     SOCKET ls;
     struct timeval socktm;
@@ -297,12 +296,12 @@ static apr_status_t create_socket_pipe(S
     struct sockaddr_in la;
     struct sockaddr_in ca;
     int nrd;
-    apr_status_t rv = APR_SUCCESS;
+    apr_status_t rv;
     int ll = sizeof(la);
     int lc = sizeof(ca);
     unsigned long bm = 1;
-    int uid[2];
-    int iid[2];
+    char uid[8];
+    char iid[8];
 
     *rd = INVALID_SOCKET;
     *wr = INVALID_SOCKET;
@@ -311,8 +310,11 @@ static apr_status_t create_socket_pipe(S
      * so that we know the connection originated
      * from us.
      */
-    uid[0] = getpid();
-    uid[1] = id++;
+    rv = apr_generate_random_bytes(uid, sizeof(uid));
+    if (rv != APR_SUCCESS) {
+        return rv;
+    }
+
     if ((ls = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == INVALID_SOCKET) {
         return apr_get_netos_error();
     }
@@ -341,7 +343,7 @@ static apr_status_t create_socket_pipe(S
         rv =  apr_get_netos_error();
         goto cleanup;
     }
-    if (send(*wr, (char *)uid, sizeof(uid), 0) != sizeof(uid)) {
+    if (send(*wr, uid, sizeof(uid), 0) != sizeof(uid)) {
         if ((rv =  apr_get_netos_error()) == 0) {
             rv = APR_EINVAL;
         }
@@ -384,7 +386,7 @@ static apr_status_t create_socket_pipe(S
             rv = apr_get_netos_error();
             goto cleanup;
         }
-        nrd = recv(*rd, (char *)iid, sizeof(iid), 0);
+        nrd = recv(*rd, iid, sizeof(iid), 0);
         if (nrd == SOCKET_ERROR) {
             rv = apr_get_netos_error();
             goto cleanup;