File tree Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Expand file tree Collapse file tree 3 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -129,6 +129,10 @@ PHP NEWS
129129 . Fixed bug GH-16293 (Failed assertion when throwing in assert() callback with
130130 bail enabled). (ilutov)
131131
132+ - SysVMsg:
133+ . Fixed bug GH-16592 (msg_send() crashes when a type does not properly
134+ serialized). (David Carlier / cmb)
135+
132136- SysVShm:
133137 . Fixed bug GH-16591 (Assertion error in shm_put_var). (nielsdos, cmb)
134138
Original file line number Diff line number Diff line change @@ -371,11 +371,19 @@ PHP_FUNCTION(msg_send)
371371 php_var_serialize (& msg_var , message , & var_hash );
372372 PHP_VAR_SERIALIZE_DESTROY (var_hash );
373373
374+ if (UNEXPECTED (EG (exception ))) {
375+ smart_str_free (& msg_var );
376+ RETURN_THROWS ();
377+ }
378+
379+
380+ zend_string * str = smart_str_extract (& msg_var );
381+ message_len = ZSTR_LEN (str );
374382 /* NB: php_msgbuf is 1 char bigger than a long, so there is no need to
375383 * allocate the extra byte. */
376- messagebuffer = safe_emalloc (ZSTR_LEN ( msg_var . s ) , 1 , sizeof (struct php_msgbuf ));
377- memcpy (messagebuffer -> mtext , ZSTR_VAL (msg_var . s ), ZSTR_LEN ( msg_var . s ) + 1 );
378- message_len = ZSTR_LEN ( msg_var . s );
384+ messagebuffer = safe_emalloc (message_len , 1 , sizeof (struct php_msgbuf ));
385+ memcpy (messagebuffer -> mtext , ZSTR_VAL (str ), message_len + 1 );
386+ zend_string_release_ex ( str , false );
379387 smart_str_free (& msg_var );
380388 } else {
381389 char * p ;
Original file line number Diff line number Diff line change 1+ --TEST--
2+ msg_send() segfault when the type does not serialize as expected
3+ --EXTENSIONS--
4+ sysvmsg
5+ --FILE--
6+ <?php
7+ class Test {
8+ function __serialize () {}
9+ }
10+
11+ $ q = msg_get_queue (1 );
12+ try {
13+ msg_send ($ q , 1 , new Test , true );
14+ } catch (\TypeError $ e ) {
15+ echo $ e ->getMessage ();
16+ }
17+ ?>
18+ --EXPECT--
19+ Test::__serialize() must return an array
You can’t perform that action at this time.
0 commit comments