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

Fix some UB in signal handling #18

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Commits on Aug 25, 2019

  1. microcom: initialize the struct sigaction before use

    sigaction(2) reads the sa_mask and sa_flags struct members as well, but
    we didn't initialize them so far. We probably didn't run into problems,
    because we allocate it when the stack is fresh and full of zeroes.
    
    Fix this by explicitly zeroing the struct and emptying the signal set.
    
    Signed-off-by: Ahmad Fatoum <[email protected]>
    a3f committed Aug 25, 2019
    Configuration menu
    Copy the full SHA
    6e1b57e View commit details
    Browse the repository at this point in the history
  2. Don't call async-signal-unsafe free in signal handler

    We use malloc elsewhere in the code with signals unmasked, but use free
    in a signal handler. This could result in a dead lock when terminating
    microcom by signal.
    
    The duplication of exit(0) call is ok, as the call site in the signal
    handler will be replaced in a follow-up commit.
    
    Signed-off-by: Ahmad Fatoum <[email protected]>
    a3f committed Aug 25, 2019
    Configuration menu
    Copy the full SHA
    2898704 View commit details
    Browse the repository at this point in the history
  3. microcom: make microcom_exit async-signal-safer

    Both printf and exit aren't async signal safe, replace them with write
    and _Exit respectively.
    
    The access to ios and ios->exit and callees is still illegal, but at
    least we don't run risk reentering stdio and causing a deadlock anymore.
    
    As exit flushes stdio buffers as well, we now risk losing unflushed
    stdio output. This is acceptable as we aren't buffering the serial
    port output and the program is being terminated abnormally anyway.
    
    Signed-off-by: Ahmad Fatoum <[email protected]>
    a3f committed Aug 25, 2019
    Configuration menu
    Copy the full SHA
    6b025f4 View commit details
    Browse the repository at this point in the history