Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault in mb_strimwidth() #9248

Closed
garas opened this issue Aug 4, 2022 · 5 comments
Closed

Segmentation fault in mb_strimwidth() #9248

garas opened this issue Aug 4, 2022 · 5 comments

Comments

@garas
Copy link
garas commented Aug 4, 2022

Description

The following code:

<?php
echo mb_strimwidth('The quick brown fox', 0, 8);

Process crashed with SIGSEGV.

But I expected this output instead:

The quic

PHP Version

git.master | released 2022-08-04 (3v4l.org)

Operating System

No response

@cmb69
Copy link
Member
cmb69 commented Aug 5, 2022

Indeed, we need to initialize trimmarker:

 ext/mbstring/mbstring.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index b9cfe628b4..24712c8817 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -2502,7 +2502,7 @@ static zend_string* mb_trim_string(zend_string *input, zend_string *marker, cons
 /* Trim the string to terminal width; optional, add a 'trim marker' if it was truncated */
 PHP_FUNCTION(mb_strimwidth)
 {
-	zend_string *str, *trimmarker, *encoding = NULL;
+	zend_string *str, *trimmarker = zend_empty_string, *encoding = NULL;
 	zend_long from, width;
 
 	ZEND_PARSE_PARAMETERS_START(3, 5)

@alexdowad
Copy link
Contributor

Thanks for the great catch! Much appreciated!

@alexdowad
Copy link
Contributor

@cmb69, do you want to commit this fix, or should I include it in my next PR?

cmb69 added a commit to cmb69/php-src that referenced this issue Aug 8, 2022
We need to initialize the optional argument `trimmarker` with its
default value.
@cmb69 cmb69 linked a pull request Aug 8, 2022 that will close this issue
@cmb69
Copy link
Member
cmb69 commented Aug 8, 2022

I just submitted PR #9273. :)

@cmb69 cmb69 closed this as completed in d013d94 Aug 8, 2022
@alexdowad
Copy link
Contributor

Thanks very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants