Skip to content

analyzer does not know that failed syscalls set errno #43015

Open
@nolange

Description

@nolange
Bugzilla Link 43670
Version 9.0
OS Linux
CC @devincoughlin,@haoNoQ

Extended Description

The following code will produce a report, even though the analyzer could/should deduce that errno is set to non-zero if socket returns < 0.
Adding the __builtin_unreachable fixes the report, but this should be automatic for reading errno after entering a branch that requires a failed syscall.

#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>
#include <limits.h>
#include <unistd.h>
#include <assert.h>
#include <stdlib.h>

extern int dosomething(char *);

static int connect_socket(char **mname) {
int ret;
*mname = (char *)malloc(PATH_MAX);

int fd = socket(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0);
if (fd < 0) {
ret = errno;
// if (ret == 0)
// __builtin_unreachable();
free(*mname);
return ret;
}

{
ret = recv(fd, *mname, PATH_MAX, 0);
if (ret > 0) return 0;
}
close(fd);
return ret;
}

int do_init()
{
char *mname;
int ret = connect_socket(&mname);
if (ret)
return ret;

return dosomething(mname);

}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions