@@ -1009,6 +1009,29 @@ static char *zend_file_cache_get_bin_file_path(zend_string *script_path)
1009
1009
return filename ;
1010
1010
}
1011
1011
1012
+ /**
1013
+ * Helper function for zend_file_cache_script_store().
1014
+ *
1015
+ * @return true on success, false on error
1016
+ */
1017
+ static bool zend_file_cache_script_write (int fd , const zend_persistent_script * script , const zend_file_cache_metainfo * info , const void * buf , const zend_string * s )
1018
+ {
1019
+ #ifdef HAVE_SYS_UIO_H
1020
+ const struct iovec vec [] = {
1021
+ { .iov_base = (void * )info , .iov_len = sizeof (* info ) },
1022
+ { .iov_base = (void * )buf , .iov_len = script -> size },
1023
+ { .iov_base = (void * )ZSTR_VAL (s ), .iov_len = info -> str_size },
1024
+ };
1025
+
1026
+ return writev (fd , vec , sizeof (vec ) / sizeof (vec [0 ])) == (ssize_t )(sizeof (* info ) + script -> size + info -> str_size );
1027
+ #else
1028
+ return ZEND_LONG_MAX >= (zend_long )(sizeof (* info ) + script -> size + info -> str_size ) &&
1029
+ write (fd , info , sizeof (* info )) == sizeof (* info ) &&
1030
+ write (fd , buf , script -> size ) == script -> size &&
1031
+ write (fd , ZSTR_VAL (s ), info -> str_size ) == info -> str_size ;
1032
+ #endif
1033
+ }
1034
+
1012
1035
int zend_file_cache_script_store (zend_persistent_script * script , bool in_shm )
1013
1036
{
1014
1037
int fd ;
@@ -1079,14 +1102,7 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
1079
1102
__msan_unpoison (buf , script -> size );
1080
1103
#endif
1081
1104
1082
- #ifdef HAVE_SYS_UIO_H
1083
- const struct iovec vec [] = {
1084
- { .iov_base = (void * )& info , .iov_len = sizeof (info ) },
1085
- { .iov_base = buf , .iov_len = script -> size },
1086
- { .iov_base = ZSTR_VAL (s ), .iov_len = info .str_size },
1087
- };
1088
-
1089
- if (writev (fd , vec , sizeof (vec ) / sizeof (vec [0 ])) != (ssize_t )(sizeof (info ) + script -> size + info .str_size )) {
1105
+ if (!zend_file_cache_script_write (fd , script , & info , buf , s )) {
1090
1106
zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot write to file '%s'\n" , filename );
1091
1107
zend_string_release_ex (s , 0 );
1092
1108
close (fd );
@@ -1095,21 +1111,6 @@ int zend_file_cache_script_store(zend_persistent_script *script, bool in_shm)
1095
1111
efree (filename );
1096
1112
return FAILURE ;
1097
1113
}
1098
- #else
1099
- if (ZEND_LONG_MAX < (zend_long )(sizeof (info ) + script -> size + info .str_size ) ||
1100
- write (fd , & info , sizeof (info )) != sizeof (info ) ||
1101
- write (fd , buf , script -> size ) != script -> size ||
1102
- write (fd , ZSTR_VAL (s ), info .str_size ) != info .str_size
1103
- ) {
1104
- zend_accel_error (ACCEL_LOG_WARNING , "opcache cannot write to file '%s'\n" , filename );
1105
- zend_string_release_ex (s , 0 );
1106
- close (fd );
1107
- efree (mem );
1108
- zend_file_cache_unlink (filename );
1109
- efree (filename );
1110
- return FAILURE ;
1111
- }
1112
- #endif
1113
1114
1114
1115
zend_string_release_ex (s , 0 );
1115
1116
efree (mem );
0 commit comments