Skip to content

Commit 615960b

Browse files
committed
ext/phar: Refer to zend_string* length directly
This makes it more obvious that the host_len is that of resource->host
1 parent 839952c commit 615960b

File tree

2 files changed

+10
-20
lines changed

2 files changed

+10
-20
lines changed

ext/phar/dirstream.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,10 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path,
319319
return NULL;
320320
}
321321

322-
size_t host_len = ZSTR_LEN(resource->host);
323322
phar_request_initialize();
324323
internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */
325324

326-
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) {
325+
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, &error)) {
327326
if (error) {
328327
php_stream_wrapper_log_error(wrapper, options, "%s", error);
329328
efree(error);
@@ -436,9 +435,7 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo
436435
return 0;
437436
}
438437

439-
size_t host_len = ZSTR_LEN(resource->host);
440-
441-
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) {
438+
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, &error)) {
442439
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", error retrieving phar information: %s", ZSTR_VAL(resource->path) + 1, ZSTR_VAL(resource->host), error);
443440
efree(error);
444441
php_url_free(resource);
@@ -567,9 +564,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options
567564
return 0;
568565
}
569566

570-
size_t host_len = ZSTR_LEN(resource->host);
571-
572-
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) {
567+
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, &error)) {
573568
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", error retrieving phar information: %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error);
574569
efree(error);
575570
php_url_free(resource);

ext/phar/stream.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,12 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
186186
return NULL;
187187
}
188188

189-
size_t host_len = ZSTR_LEN(resource->host);
190189
phar_request_initialize();
191190

192191
/* strip leading "/" */
193192
internal_file = estrndup(ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1);
194193
if (mode[0] == 'w' || (mode[0] == 'r' && mode[1] == '+')) {
195-
if (NULL == (idata = phar_get_or_create_entry_data(ZSTR_VAL(resource->host), host_len, internal_file, strlen(internal_file), mode, 0, &error, 1))) {
194+
if (NULL == (idata = phar_get_or_create_entry_data(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), internal_file, strlen(internal_file), mode, 0, &error, 1))) {
196195
if (error) {
197196
php_stream_wrapper_log_error(wrapper, options, "%s", error);
198197
efree(error);
@@ -236,14 +235,14 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
236235
} else {
237236
if (!*internal_file && (options & STREAM_OPEN_FOR_INCLUDE)) {
238237
/* retrieve the stub */
239-
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, NULL)) {
238+
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, NULL)) {
240239
php_stream_wrapper_log_error(wrapper, options, "file %s is not a valid phar archive", ZSTR_VAL(resource->host));
241240
efree(internal_file);
242241
php_url_free(resource);
243242
return NULL;
244243
}
245244
if (phar->is_tar || phar->is_zip) {
246-
if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), host_len, ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0, &error, 0)) || !idata) {
245+
if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0, &error, 0)) || !idata) {
247246
goto idata_error;
248247
}
249248
efree(internal_file);
@@ -292,7 +291,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
292291
}
293292
}
294293
/* read-only access is allowed to magic files in .phar directory */
295-
if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), host_len, internal_file, strlen(internal_file), "r", 0, &error, 0)) || !idata) {
294+
if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), internal_file, strlen(internal_file), "r", 0, &error, 0)) || !idata) {
296295
idata_error:
297296
if (error) {
298297
php_stream_wrapper_log_error(wrapper, options, "%s", error);
@@ -580,12 +579,11 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f
580579
return FAILURE;
581580
}
582581

583-
size_t host_len = ZSTR_LEN(resource->host);
584582
phar_request_initialize();
585583

586584
internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */
587585
/* find the phar in our trusty global hash indexed by alias (host of phar://blah.phar/file.whatever) */
588-
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), host_len, NULL, 0, &error)) {
586+
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, &error)) {
589587
php_url_free(resource);
590588
if (error) {
591589
efree(error);
@@ -690,7 +688,6 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
690688
return 0;
691689
}
692690

693-
size_t host_len = ZSTR_LEN(resource->host);
694691
phar_request_initialize();
695692

696693
pphar = zend_hash_find_ptr(&(PHAR_G(phar_fname_map)), resource->host);
@@ -703,7 +700,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
703700
/* need to copy to strip leading "/", will get touched again */
704701
internal_file = estrndup(ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1);
705702
internal_file_len = ZSTR_LEN(resource->path) - 1;
706-
if (FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), host_len, internal_file, internal_file_len, "r", 0, &error, 1)) {
703+
if (FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), internal_file, internal_file_len, "r", 0, &error, 1)) {
707704
/* constraints of fp refcount were not met */
708705
if (error) {
709706
php_stream_wrapper_log_error(wrapper, options, "unlink of \"%s\" failed: %s", url, error);
@@ -818,9 +815,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
818815
return 0;
819816
}
820817

821-
size_t host_len = ZSTR_LEN(resource_from->host);
822-
823-
if (SUCCESS != phar_get_archive(&phar, ZSTR_VAL(resource_from->host), host_len, NULL, 0, &error)) {
818+
if (SUCCESS != phar_get_archive(&phar, ZSTR_VAL(resource_from->host), ZSTR_LEN(resource_from->host), NULL, 0, &error)) {
824819
php_url_free(resource_from);
825820
php_url_free(resource_to);
826821
php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": %s", url_from, url_to, error);

0 commit comments

Comments
 (0)