Skip to content

Commit 4f13125

Browse files
committed
update: per kgaillot review
* remove pid/euid from qb_ipcc_connection * use proper #elif defines * return NULL instead of 0 for pointers * return -ENOMEM when malloc fails * remove redundant if check * use -1 for uid to chown()
1 parent 8668d05 commit 4f13125

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

lib/ipc_int.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ struct qb_ipcc_funcs {
9191
struct qb_ipcc_connection {
9292
char name[NAME_MAX];
9393
int32_t needs_sock_for_poll;
94-
pid_t pid;
95-
uid_t euid;
9694
gid_t egid;
9795
struct qb_ipc_one_way setup;
9896
struct qb_ipc_one_way request;

lib/ipc_setup.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ qb_ipc_auth_creds(struct ipc_auth_data *data)
340340
res = -errno;
341341
}
342342
}
343-
#elif HAVE_GETPEEREID
343+
#elif defined(HAVE_GETPEEREID)
344344
/*
345345
* Usually MacOSX systems
346346
*/
@@ -356,7 +356,7 @@ qb_ipc_auth_creds(struct ipc_auth_data *data)
356356
}
357357
}
358358

359-
#elif SO_PASSCRED
359+
#elif defined(SO_PASSCRED)
360360
/*
361361
* Usually Linux systems
362362
*/
@@ -406,8 +406,9 @@ init_ipc_auth_data(int sock, size_t len)
406406
{
407407
struct ipc_auth_data *data = calloc(1, sizeof(struct ipc_auth_data));
408408

409-
if (data == NULL)
410-
return 0;
409+
if (data == NULL) {
410+
return NULL;
411+
}
411412

412413
data->msg_recv.msg_iov = &data->iov_recv;
413414
data->msg_recv.msg_iovlen = 1;
@@ -418,7 +419,7 @@ init_ipc_auth_data(int sock, size_t len)
418419
data->cmsg_cred = calloc(1, CMSG_SPACE(sizeof(struct ucred)));
419420
if (data->cmsg_cred == NULL) {
420421
destroy_ipc_auth_data(data);
421-
return 0;
422+
return NULL;
422423
}
423424
data->msg_recv.msg_control = (void *)data->cmsg_cred;
424425
data->msg_recv.msg_controllen = CMSG_SPACE(sizeof(struct ucred));
@@ -472,7 +473,7 @@ qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c,
472473
data = init_ipc_auth_data(c->setup.u.us.sock, sizeof(struct qb_ipc_connection_response));
473474
if (data == NULL) {
474475
qb_ipcc_us_sock_close(c->setup.u.us.sock);
475-
return -1;
476+
return -ENOMEM;
476477
}
477478

478479
qb_ipc_us_ready(&c->setup, NULL, -1, POLLIN);
@@ -491,17 +492,10 @@ qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c,
491492
memcpy(r, &data->msg.res, sizeof(struct qb_ipc_connection_response));
492493

493494
qb_ipc_auth_creds(data);
494-
c->pid = data->ugp.pid;
495-
c->euid = data->ugp.uid;
496495
c->egid = data->ugp.gid;
497496

498-
if (r->hdr.error != 0) {
499-
destroy_ipc_auth_data(data);
500-
return r->hdr.error;
501-
}
502-
503497
destroy_ipc_auth_data(data);
504-
return 0;
498+
return r->hdr.error;
505499
}
506500

507501
/*

lib/ipc_socket.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ qb_ipc_dgram_sock_setup(const char *base_name,
8787
sizeof(local_address));
8888
#if !(defined(QB_LINUX) || defined(QB_CYGWIN))
8989
chmod(local_address.sun_path, 0660);
90-
chown(local_address.sun_path, getuid(), gid);
90+
chown(local_address.sun_path, -1, gid);
9191
#endif
9292
if (res < 0) {
9393
goto error_connect;

0 commit comments

Comments
 (0)