mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-02 07:28:21 +00:00
socket: fix invalid unix paths being used
This commit is contained in:
@@ -127,9 +127,11 @@ typedef struct {
|
|||||||
|
|
||||||
typedef unsigned socklen_t;
|
typedef unsigned socklen_t;
|
||||||
|
|
||||||
|
#define ABISOCKADDR_UN_MAX 108
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned short type;
|
unsigned short type;
|
||||||
char addr[14];
|
char addr[ABISOCKADDR_UN_MAX];
|
||||||
} abisockaddr_t;
|
} abisockaddr_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -140,7 +142,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t sun_family;
|
uint16_t sun_family;
|
||||||
char sun_path[108];
|
char sun_path[ABISOCKADDR_UN_MAX];
|
||||||
} __attribute__((packed)) unaddr_t;
|
} __attribute__((packed)) unaddr_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@@ -151,7 +151,11 @@ static inline int sock_convertaddress(sockaddr_t *sockaddr, abisockaddr_t *abiso
|
|||||||
break;
|
break;
|
||||||
case AF_LOCAL:
|
case AF_LOCAL:
|
||||||
unaddr_t *unaddr = (unaddr_t *)abisockaddr;
|
unaddr_t *unaddr = (unaddr_t *)abisockaddr;
|
||||||
strcpy(sockaddr->path, unaddr->sun_path);
|
size_t length = strnlen(unaddr->sun_path, ABISOCKADDR_UN_MAX);
|
||||||
|
if (length == ABISOCKADDR_UN_MAX)
|
||||||
|
return EINVAL;
|
||||||
|
|
||||||
|
memcpy(sockaddr->path, unaddr->sun_path, length + 1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|||||||
Reference in New Issue
Block a user