Skip to content

Commit

Permalink
Fix of undefined behavior of null referencing (netty#10016)
Browse files Browse the repository at this point in the history
Motivation:

Current code depends on some "undefined behaviour".

Modification:

Fix of undefined behavior of null referencing

Result:

Correct c code.
  • Loading branch information
vitalybuka authored Feb 11, 2020
1 parent a6896ea commit b410ff9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion transport-native-unix-common/src/main/c/netty_unix_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -50,7 +51,7 @@ extern int accept4(int sockFd, struct sockaddr* addr, socklen_t* addrlen, int fl

// macro to calculate the length of a sockaddr_un struct for a given path length.
// see sys/un.h#SUN_LEN, this is modified to allow nul bytes
#define _UNIX_ADDR_LENGTH(path_len) (uintptr_t) (((struct sockaddr_un *) 0)->sun_path) + path_len
#define _UNIX_ADDR_LENGTH(path_len) ((uintptr_t) offsetof(struct sockaddr_un, sun_path) + (uintptr_t) path_len)

static int nettyNonBlockingSocket(int domain, int type, int protocol) {
#ifdef SOCK_NONBLOCK
Expand Down

0 comments on commit b410ff9

Please sign in to comment.