Skip to content

Segmentation fault in mb_strimwidth() #9248

Closed

Description

@garas

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

Activity

  1. cmb69 commented on Aug 5, 2022

    @cmb69
    Member

    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)
  2. alexdowad commented on Aug 5, 2022

    @alexdowad
    Contributor

    Thanks for the great catch! Much appreciated!

  3. alexdowad commented on Aug 5, 2022

    @alexdowad
    Contributor

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

  4. added a commit that references this issue on Aug 8, 2022
    98598f2
  5. cmb69 commented on Aug 8, 2022

    @cmb69
    Member

    I just submitted PR #9273. :)

  6. alexdowad commented on Aug 8, 2022

    @alexdowad
    Contributor

    Thanks very much!

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions