Skip to content

Commit d59af68

Browse files
committed
Make sure to copy the right amount of mem over. IPv6 can be larger than struct sockaddr
1 parent 7373ce9 commit d59af68

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ext/sockets/sockets.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,7 @@ PHP_FUNCTION(socket_addrinfo_lookup)
25332533
if (strcmp(ZSTR_VAL(key), "ai_flags") == 0) {
25342534
hints.ai_flags = Z_LVAL_P(hint);
25352535
} else if (strcmp(ZSTR_VAL(key), "ai_socktype") == 0) {
2536-
hints.ai_socktype= Z_LVAL_P(hint);
2536+
hints.ai_socktype = Z_LVAL_P(hint);
25372537
} else if (strcmp(ZSTR_VAL(key), "ai_protocol") == 0) {
25382538
hints.ai_protocol = Z_LVAL_P(hint);
25392539
} else if (strcmp(ZSTR_VAL(key), "ai_family") == 0) {
@@ -2556,8 +2556,8 @@ PHP_FUNCTION(socket_addrinfo_lookup)
25562556
res = emalloc(sizeof(struct addrinfo));
25572557
memcpy(res, rp, sizeof(struct addrinfo));
25582558

2559-
res->ai_addr = emalloc(sizeof(struct sockaddr));
2560-
memcpy(res->ai_addr, rp->ai_addr, sizeof(struct sockaddr));
2559+
res->ai_addr = emalloc(rp->ai_addrlen);
2560+
memcpy(res->ai_addr, rp->ai_addr, rp->ai_addrlen);
25612561

25622562
if (rp->ai_canonname != NULL) {
25632563
res->ai_canonname = estrdup(rp->ai_canonname);
@@ -2723,7 +2723,7 @@ PHP_FUNCTION(socket_addrinfo_explain)
27232723
}
27242724

27252725
array_init(&sockaddr);
2726-
switch(ai->ai_addr->sa_family) {
2726+
switch(ai->ai_family) {
27272727
case AF_INET:
27282728
{
27292729
struct sockaddr_in *sa = (struct sockaddr_in *) ai->ai_addr;

0 commit comments

Comments
 (0)