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

[BUG] [CRASH] Segmentation fault when calling Phalcon\Validation\Message\Group::offsetSet() with a non-object #741

Closed
ghost opened this issue Jun 29, 2013 · 3 comments

Comments

@ghost
Copy link

ghost commented Jun 29, 2013

<?php
$group = new Phalcon\Validation\Message\Group;
try {
        $group[0] = 'Invalid';
}
catch (Exception $e) {
        echo "Exception caught!\n";
}

Expected result:
Exception caught!

Actual result:
Segmentation fault (core dumped)

Backtrace:

Program received signal SIGSEGV, Segmentation fault.
phalcon_memory_alloc (var=var@entry=0x7fffffffa1e8) at /cphalcon/ext/kernel/memory.c:309
309             active_memory->pointer++;
(gdb) bt full
#0  phalcon_memory_alloc (var=var@entry=0x7fffffffa1e8) at /cphalcon/ext/kernel/memory.c:309
        active_memory = 0x0
#1  0x00007ffff3567861 in phalcon_throw_exception_string (ce=0x10be970, message=message@entry=0x7ffff36c48cf "The message must be an object", message_len=message_len@entry=29, restore_stack=restore_stack@entry=1)
    at /cphalcon/ext/kernel/exception.c:55
        object = 0x7ffff7fc2700
        msg = <optimized out>
#2  0x00007ffff369b6f7 in zim_Phalcon_Validation_Message_Group_offsetSet (ht=<optimized out>, return_value=0x7ffff7fc26d0, return_value_ptr=<optimized out>, this_ptr=0x7ffff7fc0e30, return_value_used=<optimized out>)
    at /cphalcon/ext/validation/message/group.c:133
        index = 0x7ffff7fc2aa0
        message = 0x7ffff7fc0e00
#3  0x00000000006a9e4d in zend_call_function ()
No symbol table info available.
#4  0x00000000006ce1d5 in zend_call_method ()
No symbol table info available.
#5  0x00000000006d8534 in ?? ()
No symbol table info available.
#6  0x0000000000736090 in ?? ()
No symbol table info available.
#7  0x0000000000755e45 in ?? ()
No symbol table info available.
#8  0x0000000000718857 in execute ()
No symbol table info available.
#9  0x00000000006b86cc in zend_execute_scripts ()
No symbol table info available.
#10 0x0000000000658373 in php_execute_script ()
No symbol table info available.
#11 0x0000000000761583 in ?? ()
No symbol table info available.
#12 0x000000000042c750 in ?? ()
No symbol table info available.
#13 0x00007ffff5b3cea5 in __libc_start_main (main=0x42c280, argc=2, ubp_av=0x7fffffffdea8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffde98) at libc-start.c:260
        result = <optimized out>
        unwind_buf = {cancel_jmp_buf = {{jmp_buf = {0, -1858359330526826106, 4376508, 140737488346784, 0, 0, 1858359331671142790, 1858336757809967494}, mask_was_saved = 0}}, priv = {pad = {0x0, 0x0, 0x7ffff7de9930 <_dl_init+160>, 
              0x0}, data = {prev = 0x0, cleanup = 0x0, canceltype = -136406736}}}
        not_first_call = <optimized out>
#14 0x000000000042c7e5 in _start ()
No symbol table info available.
@ghost
Copy link
Author

ghost commented Jun 29, 2013

Looks like PHALCON_MM_GROW() is missing.

The proposed fix:

--- a/ext/validation/message/group.c
+++ b/ext/validation/message/group.c
@@ -127,14 +127,16 @@ PHP_METHOD(Phalcon_Validation_Message_Group, offsetSet){

        zval *index, *message;

-       phalcon_fetch_params(0, 2, 0, &index, &message);
+       PHALCON_MM_GROW();

-       if (Z_TYPE_P(message) != IS_OBJECT) {
-               PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The message must be an object");
+       phalcon_fetch_params(1, 2, 0, &index, &message);
+       
+       if (Z_TYPE_P(message) != IS_OBJECT || !instanceof_function(phalcon_validation_message_ce, Z_OBJCE_P(message) TSRMLS_CC)) {
+               PHALCON_THROW_EXCEPTION_STR(phalcon_validation_exception_ce, "The message must be an instance of Phalcon\\Validation\\Message class");
                return;
        }
        phalcon_update_property_array(this_ptr, SL("_messages"), index, message TSRMLS_CC);
-       
+       PHALCON_MM_RESTORE();
 }

 /**

@ghost
Copy link
Author

ghost commented Jun 29, 2013

Same happens with messageAppend()

@phalcon
Copy link
Collaborator

phalcon commented Jun 29, 2013

I added the fix in kernel/exception, that would fix all the cases, thank you

@phalcon phalcon closed this as completed Jun 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants