Skip to content

Commit e7df639

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/sockets: bound interface name copy in from_zval_write_ifindex()
2 parents 121d19f + 009a0c2 commit e7df639

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

ext/sockets/conversions.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,11 +1281,10 @@ static void from_zval_write_ifindex(const zval *zv, char *uinteger, ser_context
12811281
#elif defined(SIOCGIFINDEX)
12821282
{
12831283
struct ifreq ifr;
1284-
if (ZSTR_LEN(str) >= sizeof(ifr.ifr_name)) {
1284+
if (strlcpy(ifr.ifr_name, ZSTR_VAL(str), sizeof(ifr.ifr_name))
1285+
>= sizeof(ifr.ifr_name)) {
12851286
do_from_zval_err(ctx, "the interface name \"%s\" is too large ", ZSTR_VAL(str));
1286-
}
1287-
memcpy(ifr.ifr_name, ZSTR_VAL(str), ZSTR_LEN(str) + 1);
1288-
if (ioctl(ctx->sock->bsd_socket, SIOCGIFINDEX, &ifr) < 0) {
1287+
} else if (ioctl(ctx->sock->bsd_socket, SIOCGIFINDEX, &ifr) < 0) {
12891288
if (errno == ENODEV) {
12901289
do_from_zval_err(ctx, "no interface with name \"%s\" could be "
12911290
"found", ZSTR_VAL(str));

0 commit comments

Comments
 (0)