Skip to content

Commit

Permalink
Fix #183: recv() returns ssize_t, not size_t
Browse files Browse the repository at this point in the history
We use ECONNRESET to signal the callee of EOF.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
  • Loading branch information
troglobit committed Oct 1, 2022
1 parent 0828918 commit 3fb2fbb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,25 @@ int ipc_send(int sd, char *buf, size_t len)
*/
void *ipc_receive(int sd, char *buf, size_t len)
{
size_t sz;
ssize_t sz;

sz = recv(sd, buf, len - 1, 0);
if (!sz) {
errno = ECONNRESET;
if (sz <= 0)
if (!sz)
errno = ECONNRESET;
return NULL;
}

/* successful read */
if (sz >= sizeof(struct ipc_msg)) {
if ((size_t)sz >= sizeof(struct ipc_msg)) {
struct ipc_msg *msg = (struct ipc_msg *)buf;

/* Make sure to always have at least one NUL, for strlen() */
buf[sz] = 0;

if (sz == msg->len) {
char *ptr;
if ((size_t)sz == msg->len) {
size_t i, count;
char *ptr;

/* Upper bound: smcroutectl add in1 source group out1 out2 .. out32 */
count = msg->count;
Expand Down

0 comments on commit 3fb2fbb

Please sign in to comment.