@@ -240,16 +240,15 @@ static void from_zval_write_aggregation(const zval *container,
240
240
const field_descriptor * descr ;
241
241
zval * elem ;
242
242
243
- if (Z_TYPE_P (container ) != IS_ARRAY ) {
244
- zend_type_error ("Expected array" );
245
- return ;
246
- }
243
+ ZEND_ASSERT (descriptors -> from_zval );
247
244
248
245
for (descr = descriptors ; descr -> name != NULL && !ctx -> err .has_error ; descr ++ ) {
249
246
if ((elem = zend_hash_str_find (Z_ARRVAL_P (container ),
250
247
descr -> name , descr -> name_size - 1 )) != NULL ) {
251
248
252
249
if (descr -> from_zval == NULL ) {
250
+ ctx -> err .has_error = 1 ;
251
+ ctx -> err .should_free = 1 ;
253
252
zend_value_error ("Impossible to convert value of key '%s'" , descr -> name );
254
253
return ;
255
254
}
@@ -259,6 +258,8 @@ static void from_zval_write_aggregation(const zval *container,
259
258
zend_llist_remove_tail (& ctx -> keys );
260
259
261
260
} else if (descr -> required ) {
261
+ ctx -> err .has_error = 1 ;
262
+ ctx -> err .should_free = 1 ;
262
263
zend_value_error ("The key '%s' is required" , descr -> name );
263
264
return ;
264
265
}
@@ -339,11 +340,15 @@ static zend_long from_zval_integer_common(const zval *arr_value, ser_context *ct
339
340
}
340
341
341
342
/* if we get here, we don't have a numeric string */
343
+ ctx -> err .has_error = 1 ;
344
+ ctx -> err .should_free = 1 ;
342
345
zend_type_error ("Expected an integer, received a non numeric string: '%s'" , Z_STRVAL_P (arr_value ));
343
346
return ret ;
344
347
}
345
348
346
349
default :
350
+ ctx -> err .has_error = 1 ;
351
+ ctx -> err .should_free = 1 ;
347
352
zend_type_error ("Expected an integer" );
348
353
return ret ;
349
354
}
@@ -363,6 +368,8 @@ void from_zval_write_int(const zval *arr_value, char *field, ser_context *ctx)
363
368
}
364
369
365
370
if (lval > INT_MAX || lval < INT_MIN ) {
371
+ ctx -> err .has_error = 1 ;
372
+ ctx -> err .should_free = 1 ;
366
373
zend_value_error ("Provided PHP integer is out of bounds for a native int" );
367
374
return ;
368
375
}
@@ -381,6 +388,8 @@ static void from_zval_write_uint32(const zval *arr_value, char *field, ser_conte
381
388
}
382
389
383
390
if (sizeof (zend_long ) > sizeof (uint32_t ) && (lval < 0 || lval > 0xFFFFFFFF )) {
391
+ ctx -> err .has_error = 1 ;
392
+ ctx -> err .should_free = 1 ;
384
393
zend_value_error ("Provided PHP integer is out of bounds for an unsigned 32-bit integer" );
385
394
return ;
386
395
}
@@ -399,6 +408,8 @@ static void from_zval_write_net_uint16(const zval *arr_value, char *field, ser_c
399
408
}
400
409
401
410
if (lval < 0 || lval > 0xFFFF ) {
411
+ ctx -> err .has_error = 1 ;
412
+ ctx -> err .should_free = 1 ;
402
413
zend_value_error ("Provided PHP integer is out of bounds for an unsigned 16-bit integer" );
403
414
return ;
404
415
}
@@ -417,6 +428,8 @@ static void from_zval_write_sa_family(const zval *arr_value, char *field, ser_co
417
428
}
418
429
419
430
if (lval < 0 || lval > (sa_family_t )- 1 ) { /* sa_family_t is unsigned */
431
+ ctx -> err .has_error = 1 ;
432
+ ctx -> err .should_free = 1 ;
420
433
zend_value_error ("Provided PHP integer is out of bounds for a sa_family_t value" );
421
434
return ;
422
435
}
@@ -437,6 +450,8 @@ static void from_zval_write_pid_t(const zval *arr_value, char *field, ser_contex
437
450
}
438
451
439
452
if (lval < 0 || (pid_t )lval != lval ) { /* pid_t is signed */
453
+ ctx -> err .has_error = 1 ;
454
+ ctx -> err .should_free = 1 ;
440
455
zend_value_error ("Provided PHP integer is out of bounds for a pid_t value" );
441
456
return ;
442
457
}
@@ -457,11 +472,15 @@ static void from_zval_write_uid_t(const zval *arr_value, char *field, ser_contex
457
472
/* uid_t can be signed or unsigned (generally unsigned) */
458
473
if ((uid_t )- 1 > (uid_t )0 ) {
459
474
if (sizeof (zend_long ) > sizeof (uid_t ) && (lval < 0 || (uid_t )lval != lval )) {
475
+ ctx -> err .has_error = 1 ;
476
+ ctx -> err .should_free = 1 ;
460
477
zend_value_error ("Provided PHP integer is out of bounds for a uid_t value" );
461
478
return ;
462
479
}
463
480
} else {
464
481
if (sizeof (zend_long ) > sizeof (uid_t ) && (uid_t )lval != lval ) {
482
+ ctx -> err .has_error = 1 ;
483
+ ctx -> err .should_free = 1 ;
465
484
zend_value_error ("Provided PHP integer is out of bounds for a uid_t value" );
466
485
return ;
467
486
}
@@ -554,6 +573,8 @@ static void to_zval_read_sin_addr(const char *data, zval *zv, res_context *ctx)
554
573
ZVAL_NEW_STR (zv , str );
555
574
556
575
if (inet_ntop (AF_INET , addr , Z_STRVAL_P (zv ), size ) == NULL ) {
576
+ ctx -> err .has_error = 1 ;
577
+ ctx -> err .should_free = 1 ;
557
578
zend_value_error ("Could not convert IPv4 address to string (errno %d)" , errno );
558
579
return ;
559
580
}
@@ -605,6 +626,8 @@ static void to_zval_read_sin6_addr(const char *data, zval *zv, res_context *ctx)
605
626
ZVAL_NEW_STR (zv , str );
606
627
607
628
if (inet_ntop (AF_INET6 , addr , Z_STRVAL_P (zv ), size ) == NULL ) {
629
+ ctx -> err .has_error = 1 ;
630
+ ctx -> err .should_free = 1 ;
608
631
zend_value_error ("Could not convert IPv6 address to string (errno %d)" , errno );
609
632
return ;
610
633
}
@@ -639,11 +662,15 @@ static void from_zval_write_sun_path(const zval *path, char *sockaddr_un_c, ser_
639
662
* this is not required, at least on linux for abstract paths. It also
640
663
* assumes that the path is not empty */
641
664
if (ZSTR_LEN (path_str ) == 0 ) {
665
+ ctx -> err .has_error = 1 ;
666
+ ctx -> err .should_free = 1 ;
642
667
zend_value_error ("The path cannot be empty" );
643
668
zend_tmp_string_release (tmp_path_str );
644
669
return ;
645
670
}
646
671
if (ZSTR_LEN (path_str ) >= sizeof (saddr -> sun_path )) {
672
+ ctx -> err .has_error = 1 ;
673
+ ctx -> err .should_free = 1 ;
647
674
zend_value_error ("The path is too long, maximum permitted length is %zd" , sizeof (saddr -> sun_path ) - 1 );
648
675
zend_tmp_string_release (tmp_path_str );
649
676
return ;
@@ -660,6 +687,8 @@ static void to_zval_read_sun_path(const char *data, zval *zv, res_context *ctx)
660
687
661
688
nul_pos = memchr (& saddr -> sun_path , '\0' , sizeof (saddr -> sun_path ));
662
689
if (nul_pos == NULL ) {
690
+ ctx -> err .has_error = 1 ;
691
+ ctx -> err .should_free = 1 ;
663
692
zend_value_error ("Could not find a NUL in the path" );
664
693
return ;
665
694
}
@@ -693,6 +722,8 @@ static void from_zval_write_sockaddr_aux(const zval *container,
693
722
694
723
if (Z_TYPE_P (container ) != IS_ARRAY ) {
695
724
/* TODO improve error message? */
725
+ ctx -> err .has_error = 1 ;
726
+ ctx -> err .should_free = 1 ;
696
727
zend_type_error ("Expected array" );
697
728
return ;
698
729
}
@@ -856,6 +887,8 @@ static void from_zval_write_control(const zval *arr,
856
887
857
888
entry = get_ancillary_reg_entry (level , type );
858
889
if (entry == NULL ) {
890
+ ctx -> err .has_error = 1 ;
891
+ ctx -> err .should_free = 1 ;
859
892
zend_value_error ("cmsghdr with level %d and type %d not supported" , level , type );
860
893
return ;
861
894
}
@@ -864,6 +897,8 @@ static void from_zval_write_control(const zval *arr,
864
897
zval * data_elem ;
865
898
/* arr must be an array at this point */
866
899
if ((data_elem = zend_hash_str_find (Z_ARRVAL_P (arr ), "data" , sizeof ("data" ) - 1 )) == NULL ) {
900
+ ctx -> err .has_error = 1 ;
901
+ ctx -> err .should_free = 1 ;
867
902
zend_value_error ("cmsghdr should have a 'data' element here" );
868
903
return ;
869
904
}
@@ -910,6 +945,8 @@ static void from_zval_write_control_array(const zval *arr, char *msghdr_c, ser_c
910
945
911
946
if (Z_TYPE_P (arr ) != IS_ARRAY ) {
912
947
/* TODO Improve error message */
948
+ ctx -> err .has_error = 1 ;
949
+ ctx -> err .should_free = 1 ;
913
950
zend_type_error ("Expected array" );
914
951
return ;
915
952
}
@@ -952,6 +989,8 @@ static void to_zval_read_cmsg_data(const char *cmsghdr_c, zval *zv, res_context
952
989
953
990
entry = get_ancillary_reg_entry (cmsg -> cmsg_level , cmsg -> cmsg_type );
954
991
if (entry == NULL ) {
992
+ ctx -> err .has_error = 1 ;
993
+ ctx -> err .should_free = 1 ;
955
994
zend_value_error ("cmsghdr with level %d and type %d not supported" , cmsg -> cmsg_level , cmsg -> cmsg_type );
956
995
return ;
957
996
}
@@ -1048,6 +1087,8 @@ static void from_zval_write_msghdr_buffer_size(const zval *elem, char *msghdr_c,
1048
1087
}
1049
1088
1050
1089
if (lval < 0 || (zend_ulong )lval > MAX_USER_BUFF_SIZE ) {
1090
+ ctx -> err .has_error = 1 ;
1091
+ ctx -> err .should_free = 1 ;
1051
1092
zend_value_error ("The buffer size must be between 1 and " ZEND_LONG_FMT "; given " ZEND_LONG_FMT ,
1052
1093
(zend_long ) MAX_USER_BUFF_SIZE , lval );
1053
1094
return ;
@@ -1077,6 +1118,8 @@ static void from_zval_write_iov_array(const zval *arr, char *msghdr_c, ser_conte
1077
1118
struct msghdr * msg = (struct msghdr * )msghdr_c ;
1078
1119
1079
1120
if (Z_TYPE_P (arr ) != IS_ARRAY ) {
1121
+ ctx -> err .has_error = 1 ;
1122
+ ctx -> err .should_free = 1 ;
1080
1123
/* TODO Improve error */
1081
1124
zend_type_error ("Expected array" );
1082
1125
return ;
@@ -1102,6 +1145,8 @@ static void from_zval_write_controllen(const zval *elem, char *msghdr_c, ser_con
1102
1145
*/
1103
1146
from_zval_write_uint32 (elem , (char * )& len , ctx );
1104
1147
if (!ctx -> err .has_error && len == 0 ) {
1148
+ ctx -> err .has_error = 1 ;
1149
+ ctx -> err .should_free = 1 ;
1105
1150
zend_value_error ("controllen cannot be 0" );
1106
1151
return ;
1107
1152
}
@@ -1175,6 +1220,8 @@ static void to_zval_read_iov(const char *msghdr_c, zval *zv, res_context *ctx)
1175
1220
uint32_t i ;
1176
1221
1177
1222
if (iovlen > UINT_MAX ) {
1223
+ ctx -> err .has_error = 1 ;
1224
+ ctx -> err .should_free = 1 ;
1178
1225
zend_value_error ("Unexpectedly large value for iov_len: %lu" , (unsigned long ) iovlen );
1179
1226
}
1180
1227
array_init_size (zv , (uint32_t )iovlen );
@@ -1221,6 +1268,8 @@ static void from_zval_write_ifindex(const zval *zv, char *uinteger, ser_context
1221
1268
1222
1269
if (Z_TYPE_P (zv ) == IS_LONG ) {
1223
1270
if (Z_LVAL_P (zv ) < 0 || (zend_ulong )Z_LVAL_P (zv ) > UINT_MAX ) { /* allow 0 (unspecified interface) */
1271
+ ctx -> err .has_error = 1 ;
1272
+ ctx -> err .should_free = 1 ;
1224
1273
zend_value_error ("The interface index cannot be negative or larger than %u; given " ZEND_LONG_FMT ,
1225
1274
UINT_MAX , Z_LVAL_P (zv ));
1226
1275
} else {
@@ -1317,12 +1366,16 @@ size_t calculate_scm_rights_space(const zval *arr, ser_context *ctx)
1317
1366
1318
1367
if (Z_TYPE_P (arr ) != IS_ARRAY ) {
1319
1368
/* TODO Improve error */
1369
+ ctx -> err .has_error = 1 ;
1370
+ ctx -> err .should_free = 1 ;
1320
1371
zend_type_error ("Expected array" );
1321
1372
return (size_t )-1 ;
1322
1373
}
1323
1374
1324
1375
num_elems = zend_hash_num_elements (Z_ARRVAL_P (arr ));
1325
1376
if (num_elems == 0 ) {
1377
+ ctx -> err .has_error = 1 ;
1378
+ ctx -> err .should_free = 1 ;
1326
1379
zend_value_error ("Expected at least one element in this array" );
1327
1380
return (size_t )-1 ;
1328
1381
}
@@ -1345,6 +1398,8 @@ static void from_zval_write_fd_array_aux(zval *elem, unsigned i, void **args, se
1345
1398
1346
1399
stream = (php_stream * )zend_fetch_resource2_ex (elem , NULL , php_file_le_stream (), php_file_le_pstream ());
1347
1400
if (stream == NULL ) {
1401
+ ctx -> err .has_error = 1 ;
1402
+ ctx -> err .should_free = 1 ;
1348
1403
zend_type_error ("Resource is not a stream nor a scoket" );
1349
1404
return ;
1350
1405
}
@@ -1356,13 +1411,17 @@ static void from_zval_write_fd_array_aux(zval *elem, unsigned i, void **args, se
1356
1411
return ;
1357
1412
}
1358
1413
} else {
1414
+ ctx -> err .has_error = 1 ;
1415
+ ctx -> err .should_free = 1 ;
1359
1416
zend_type_error ("Expected a resource" );
1360
1417
}
1361
1418
}
1362
1419
void from_zval_write_fd_array (const zval * arr , char * int_arr , ser_context * ctx )
1363
1420
{
1364
1421
if (Z_TYPE_P (arr ) != IS_ARRAY ) {
1365
1422
/* TODO Improve error */
1423
+ ctx -> err .has_error = 1 ;
1424
+ ctx -> err .should_free = 1 ;
1366
1425
zend_type_error ("Expected array" );
1367
1426
return ;
1368
1427
}
@@ -1386,6 +1445,8 @@ void to_zval_read_fd_array(const char *data, zval *zv, res_context *ctx)
1386
1445
}
1387
1446
1388
1447
if (* cmsg_len < data_offset ) {
1448
+ ctx -> err .has_error = 1 ;
1449
+ ctx -> err .should_free = 1 ;
1389
1450
zend_value_error ("Length of cmsg is smaller than its data member offset (" ZEND_LONG_FMT
1390
1451
" vs " ZEND_LONG_FMT ")" , (zend_long )* cmsg_len , (zend_long )data_offset );
1391
1452
return ;
0 commit comments