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