summaryrefslogtreecommitdiff
path: root/file_io/win32
diff options
context:
space:
mode:
authorMladen Turk <mturk@apache.org>2021-11-19 17:02:48 +0000
committerMladen Turk <mturk@apache.org>2021-11-19 17:02:48 +0000
commitf3cd94a911b93e56b20ca1743e1cc546b2ea5960 (patch)
tree1f083a566fbbb5d90f54c7f368ed463e5314cab7 /file_io/win32
parent1d69dacc2b034e7f55e311e386ea68bfcafcf012 (diff)
downloadapr-f3cd94a911b93e56b20ca1743e1cc546b2ea5960.tar.gz
Use random bytes like with named pipes as socket pipe identifier
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1895179 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'file_io/win32')
-rw-r--r--file_io/win32/pipe.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/file_io/win32/pipe.c b/file_io/win32/pipe.c
index fbf7a05d4..18f6d4a97 100644
--- a/file_io/win32/pipe.c
+++ b/file_io/win32/pipe.c
@@ -289,7 +289,6 @@ APR_DECLARE(apr_status_t) apr_os_pipe_put(apr_file_t **file,
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(SOCKET *rd, SOCKET *wr)
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(SOCKET *rd, SOCKET *wr)
* 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(SOCKET *rd, SOCKET *wr)
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(SOCKET *rd, SOCKET *wr)
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;