Skip to content

Commit d2c212d

Browse files
committed
stream: fix empty wrapper check in error displaying
1 parent c4727d1 commit d2c212d

File tree

2 files changed

+43
-37
lines changed

2 files changed

+43
-37
lines changed

main/streams/php_stream_errors.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ BEGIN_EXTERN_C()
125125
#define STREAM_ERROR_CODE_USERSPACE_CALL_FAILED 162
126126

127127
/* Wrapper name for PHP errors */
128-
#define PHP_STREAM_ERROR_WRAPPER_NAME(_wrapper) (_wrapper ? _wrapper->wops->label : "unknown")
128+
#define PHP_STREAM_ERROR_WRAPPER_DEFAULT_NAME ":na"
129+
#define PHP_STREAM_ERROR_WRAPPER_NAME(_wrapper) \
130+
(_wrapper ? _wrapper->wops->label : PHP_STREAM_ERROR_WRAPPER_DEFAULT_NAME)
129131

130132
/* Stored error entry */
131133
typedef struct {

main/streams/stream_errors.c

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -483,48 +483,52 @@ PHPAPI void php_stream_display_wrapper_name_errors(const char *wrapper_name,
483483
}
484484

485485
char *tmp = estrdup(path);
486-
zend_llist *err_list = php_stream_get_wrapper_errors_list(wrapper_name);
487-
if (err_list) {
488-
size_t l = 0;
489-
int brlen;
490-
int i;
491-
int count = (int) zend_llist_count(err_list);
492-
const char *br;
493-
php_stream_error_entry **err_entry_p;
494-
zend_llist_position pos;
495-
496-
if (PG(html_errors)) {
497-
brlen = 7;
498-
br = "<br />\n";
499-
} else {
500-
brlen = 1;
501-
br = "\n";
502-
}
486+
if (strcmp(wrapper_name, PHP_STREAM_ERROR_WRAPPER_DEFAULT_NAME)) {
487+
zend_llist *err_list = php_stream_get_wrapper_errors_list(wrapper_name);
488+
if (err_list) {
489+
size_t l = 0;
490+
int brlen;
491+
int i;
492+
int count = (int) zend_llist_count(err_list);
493+
const char *br;
494+
php_stream_error_entry **err_entry_p;
495+
zend_llist_position pos;
496+
497+
if (PG(html_errors)) {
498+
brlen = 7;
499+
br = "<br />\n";
500+
} else {
501+
brlen = 1;
502+
br = "\n";
503+
}
503504

504-
for (err_entry_p = zend_llist_get_first_ex(err_list, &pos), i = 0; err_entry_p;
505-
err_entry_p = zend_llist_get_next_ex(err_list, &pos), i++) {
506-
l += ZSTR_LEN((*err_entry_p)->message);
507-
if (i < count - 1) {
508-
l += brlen;
505+
for (err_entry_p = zend_llist_get_first_ex(err_list, &pos), i = 0; err_entry_p;
506+
err_entry_p = zend_llist_get_next_ex(err_list, &pos), i++) {
507+
l += ZSTR_LEN((*err_entry_p)->message);
508+
if (i < count - 1) {
509+
l += brlen;
510+
}
509511
}
510-
}
511-
msg = emalloc(l + 1);
512-
msg[0] = '\0';
513-
for (err_entry_p = zend_llist_get_first_ex(err_list, &pos), i = 0; err_entry_p;
514-
err_entry_p = zend_llist_get_next_ex(err_list, &pos), i++) {
515-
strcat(msg, ZSTR_VAL((*err_entry_p)->message));
516-
if (i < count - 1) {
517-
strcat(msg, br);
512+
msg = emalloc(l + 1);
513+
msg[0] = '\0';
514+
for (err_entry_p = zend_llist_get_first_ex(err_list, &pos), i = 0; err_entry_p;
515+
err_entry_p = zend_llist_get_next_ex(err_list, &pos), i++) {
516+
strcat(msg, ZSTR_VAL((*err_entry_p)->message));
517+
if (i < count - 1) {
518+
strcat(msg, br);
519+
}
518520
}
519-
}
520521

521-
free_msg = 1;
522-
} else {
523-
if (!strcmp(wrapper_name, php_plain_files_wrapper.wops->label)) {
524-
msg = php_socket_strerror_s(errno, errstr, sizeof(errstr));
522+
free_msg = 1;
525523
} else {
526-
msg = "operation failed";
524+
if (!strcmp(wrapper_name, php_plain_files_wrapper.wops->label)) {
525+
msg = php_socket_strerror_s(errno, errstr, sizeof(errstr));
526+
} else {
527+
msg = "operation failed";
528+
}
527529
}
530+
} else {
531+
msg = "no suitable wrapper could be found";
528532
}
529533

530534
php_strip_url_passwd(tmp);

0 commit comments

Comments
 (0)