Skip to content
  • Alexander Nozdrin's avatar
    38f8eaca
    Patch for Bug#13431226 (VOID SP_RCONTEXT::POP_HANDLERS(INT): · 38f8eaca
    Alexander Nozdrin authored
    ASSERTION `M_HANDLERS.ELEMENTS() >= COUNT').
    
    Background:
    
      - Handlers are resolved using parsing contexts (original information
        about BEGIN..END blocks), in order to activate the resolved handler,
        handler instruction pointer is needed (instruction pointer of the first
        instruction in the handler). That instruction pointer is calculated
        during the execution (part of the runtime information).
    
      - Handler instruction pointers are stored in the sp_rcontext::m_handlers
        stack. It is a stack of potentially visible handlers during
        SP-instruction execution. That stack consists of entries, containing
        handler activation IP (instruction pointer). A new entry is pushed to
        the stack by the hpush instruction when the "DECLARE HANDLER" statement
        is processed. Entries are popped from the stack by the hpop instruction
        at the end of BEGIN..END block.
    
      - Apart from sp_rcontext::m_handlers there is a stack of already
        activated handlers (sp_rcontext::m_handler_call_stack), which keeps the
        continue instruction pointer for CONTINUE-handlers (next instruction to
        be executed after CONTINUE-handler is finished).
    
    The problem: it was implicitly assumed that after handler execution, the
    control flow can go only to the parent scope (one scope up). It could lead
    to a server crash built in the debug mode while executing a stored program
    with complex handler structure.
    
    This patch extends the SP-execution logic so that it is possible to jump
    from the end of the handler up a few scopes. Basically, the patch
    changes the way entries are removed from sp_rcontext::m_handlers and
    sp_rcontext::m_handler_call_stack.
    
    The main ideas of the patch are:
    
      - introduce level index of sp_pcontext instance
        (level of the BEGIN..END block). The topmost scope has 0 level.
    
      - store a pointer to the handler parsing context in sp_handler.
    
      - remove entries from sp_rcontext::m_handlers and
        sp_rcontext::m_handler_call_stack based on the level information:
        remove all the entries which correspond to child scopes.
    
    The patch also changes the hpop instruction -- it does not require
    number of handlers to pop anymore.
    38f8eaca
    Patch for Bug#13431226 (VOID SP_RCONTEXT::POP_HANDLERS(INT):
    Alexander Nozdrin authored
    ASSERTION `M_HANDLERS.ELEMENTS() >= COUNT').
    
    Background:
    
      - Handlers are resolved using parsing contexts (original information
        about BEGIN..END blocks), in order to activate the resolved handler,
        handler instruction pointer is needed (instruction pointer of the first
        instruction in the handler). That instruction pointer is calculated
        during the execution (part of the runtime information).
    
      - Handler instruction pointers are stored in the sp_rcontext::m_handlers
        stack. It is a stack of potentially visible handlers during
        SP-instruction execution. That stack consists of entries, containing
        handler activation IP (instruction pointer). A new entry is pushed to
        the stack by the hpush instruction when the "DECLARE HANDLER" statement
        is processed. Entries are popped from the stack by the hpop instruction
        at the end of BEGIN..END block.
    
      - Apart from sp_rcontext::m_handlers there is a stack of already
        activated handlers (sp_rcontext::m_handler_call_stack), which keeps the
        continue instruction pointer for CONTINUE-handlers (next instruction to
        be executed after CONTINUE-handler is finished).
    
    The problem: it was implicitly assumed that after handler execution, the
    control flow can go only to the parent scope (one scope up). It could lead
    to a server crash built in the debug mode while executing a stored program
    with complex handler structure.
    
    This patch extends the SP-execution logic so that it is possible to jump
    from the end of the handler up a few scopes. Basically, the patch
    changes the way entries are removed from sp_rcontext::m_handlers and
    sp_rcontext::m_handler_call_stack.
    
    The main ideas of the patch are:
    
      - introduce level index of sp_pcontext instance
        (level of the BEGIN..END block). The topmost scope has 0 level.
    
      - store a pointer to the handler parsing context in sp_handler.
    
      - remove entries from sp_rcontext::m_handlers and
        sp_rcontext::m_handler_call_stack based on the level information:
        remove all the entries which correspond to child scopes.
    
    The patch also changes the hpop instruction -- it does not require
    number of handlers to pop anymore.
Loading