Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check returns from setsockopt() calls #498

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions lib/ipc_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,14 @@ qb_ipcc_us_setup_connect(struct qb_ipcc_connection *c,
return res;
}
#ifdef QB_LINUX
setsockopt(c->setup.u.us.sock, SOL_SOCKET, SO_PASSCRED, &on,
sizeof(on));
res = setsockopt(c->setup.u.us.sock, SOL_SOCKET, SO_PASSCRED, &on,
sizeof(on));
if (res != 0) {
int err = errno;
qb_ipcc_us_sock_close(c->setup.u.us.sock);
errno = err;
return res;
}
#endif

memset(&request, 0, sizeof(request));
Expand All @@ -481,6 +487,7 @@ int qb_ipcc_setup_connect_continue(struct qb_ipcc_connection *c, struct qb_ipc_c
{
struct ipc_auth_data *data;
int32_t res;
int res1;
int retry_count = 0;
#ifdef QB_LINUX
int off = 0;
Expand All @@ -500,8 +507,14 @@ int qb_ipcc_setup_connect_continue(struct qb_ipcc_connection *c, struct qb_ipc_c
}

#ifdef QB_LINUX
setsockopt(c->setup.u.us.sock, SOL_SOCKET, SO_PASSCRED, &off,
sizeof(off));
res1 = setsockopt(c->setup.u.us.sock, SOL_SOCKET, SO_PASSCRED, &off,
sizeof(off));
if (res1 != 0) {
int err = errno;
destroy_ipc_auth_data(data);
errno = err;
return res;
}
#endif

if (res != data->len) {
Expand Down Expand Up @@ -793,6 +806,7 @@ process_auth(int32_t fd, int32_t revents, void *d)
struct ipc_auth_data *data = (struct ipc_auth_data *) d;

int32_t res = 0;
int res1;
#ifdef SO_PASSCRED
int off = 0;
#endif
Expand Down Expand Up @@ -832,7 +846,13 @@ process_auth(int32_t fd, int32_t revents, void *d)

cleanup_and_return:
#ifdef SO_PASSCRED
setsockopt(data->sock, SOL_SOCKET, SO_PASSCRED, &off, sizeof(off));
res1 = setsockopt(data->sock, SOL_SOCKET, SO_PASSCRED, &off, sizeof(off));
if (res1 != 0) {
int err = errno;
close(data->sock);
errno = err;
return res;
}
#endif

(void)data->s->poll_fns.dispatch_del(data->sock);
Expand All @@ -853,6 +873,7 @@ static void
qb_ipcs_uc_recv_and_auth(int32_t sock, struct qb_ipcs_service *s)
{
int res = 0;
int res1;
struct ipc_auth_data *data = NULL;
#ifdef SO_PASSCRED
int on = 1;
Expand All @@ -869,7 +890,11 @@ qb_ipcs_uc_recv_and_auth(int32_t sock, struct qb_ipcs_service *s)
qb_ipcs_ref(data->s);

#ifdef SO_PASSCRED
setsockopt(sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
res1 = setsockopt(sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
if (res1 != 0) {
close(sock);
return;
}
#endif

res = s->poll_fns.dispatch_add(s->poll_priority,
Expand Down