[php-src] master: `sdl_set_uri_credentials()`: use early returns to improve readability

From: Date: Mon, 19 Oct 2026 22:35:06 +0000
Subject: [php-src] master: `sdl_set_uri_credentials()`: use early returns to improve readability
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142481@lists.php.net to get a copy of this message
Author: Daniel Scherzer (DanielEScherzer) Date: 2026-10-19T14:33:22-07:00 Commit: https://github.com/php/php-src/commit/c1873412a51a20ea6366e2352004b6c8cd240ddb Raw diff: https://github.com/php/php-src/commit/c1873412a51a20ea6366e2352004b6c8cd240ddb.diff sdl_set_uri_credentials(): use early returns to improve readability Changed paths: M ext/soap/php_sdl.c Diff: diff --git a/ext/soap/php_sdl.c b/ext/soap/php_sdl.c index 3ffa67cfb910..517f8a6afd2f 100644 --- a/ext/soap/php_sdl.c +++ b/ext/soap/php_sdl.c @@ -248,33 +248,39 @@ void sdl_set_uri_credentials(sdlCtx *ctx, char *uri) l2 -= 4; } } - if (l1 != l2 || memcmp(ctx->sdl->source, uri, l1) != 0) { - /* another server. clear authentication credentals */ - php_libxml_switch_context(NULL, &context); - php_libxml_switch_context(&context, NULL); - if (Z_TYPE(context) != IS_UNDEF) { - zval *context_ptr = &context; - ctx->context = php_stream_context_from_zval(context_ptr, 1); - - if (ctx->context && - (header = php_stream_context_get_option(ctx->context, "http", "header")) != NULL && - Z_TYPE_P(header) == IS_STRING) { - /* TODO: should support header as an array, but this code path is untested */ - s = strstr(Z_STRVAL_P(header), "Authorization: Basic"); - if (s && (s == Z_STRVAL_P(header) || *(s-1) == '\n' || *(s-1) == '\r')) { - char *rest = strstr(s, "\r\n"); - if (rest) { - zval new_header; - - rest += 2; - ZVAL_NEW_STR(&new_header, zend_string_alloc(Z_STRLEN_P(header) - (rest - s), 0)); - memcpy(Z_STRVAL(new_header), Z_STRVAL_P(header), s - Z_STRVAL_P(header)); - memcpy(Z_STRVAL(new_header) + (s - Z_STRVAL_P(header)), rest, Z_STRLEN_P(header) - (rest - Z_STRVAL_P(header)) + 1); - ZVAL_COPY(&ctx->old_header, header); - php_stream_context_set_option(ctx->context, "http", "header", &new_header); - zval_ptr_dtor(&new_header); - } - } + if (l1 == l2 && memcmp(ctx->sdl->source, uri, l1) == 0) { + return; + } + /* another server. clear authentication credentals */ + php_libxml_switch_context(NULL, &context); + php_libxml_switch_context(&context, NULL); + if (Z_TYPE(context) == IS_UNDEF) { + return; + } + zval *context_ptr = &context; + ctx->context = php_stream_context_from_zval(context_ptr, 1); + + if (!ctx->context) { + return; + } + + if ((header = php_stream_context_get_option(ctx->context, "http", "header")) != NULL && + Z_TYPE_P(header) == IS_STRING + ) { + /* TODO: should support header as an array, but this code path is untested */ + s = strstr(Z_STRVAL_P(header), "Authorization: Basic"); + if (s && (s == Z_STRVAL_P(header) || *(s-1) == '\n' || *(s-1) == '\r')) { + char *rest = strstr(s, "\r\n"); + if (rest) { + zval new_header; + + rest += 2; + ZVAL_NEW_STR(&new_header, zend_string_alloc(Z_STRLEN_P(header) - (rest - s), 0)); + memcpy(Z_STRVAL(new_header), Z_STRVAL_P(header), s - Z_STRVAL_P(header)); + memcpy(Z_STRVAL(new_header) + (s - Z_STRVAL_P(header)), rest, Z_STRLEN_P(header) - (rest - Z_STRVAL_P(header)) + 1); + ZVAL_COPY(&ctx->old_header, header); + php_stream_context_set_option(ctx->context, "http", "header", &new_header); + zval_ptr_dtor(&new_header); } } }

« previous php.cvs (#142481) next »