Skip to content

Double free in create_wall_timer if an invalid period is passed #1177

Closed

Description

@brawner

In create_wall_timer() in create_timer.hpp, if a bad period duration is passed (either < 0 or > nanoseconds::max()) then rcl will throw an error. During the destructor of WallTimer, it will call cancel, which results in a double free. I haven't found exactly where.

This issue is to track the several PRs I think will be necessary to resolve the cascade of errors present.

Activity

  1. added
    bug
    on Jun 16, 2020
  2. self-assigned this
    on Jun 16, 2020
  3. brawner commented on Jun 16, 2020

    @brawner
    ContributorAuthor

    Add PR to check arguments in create_wall_timer: #1178

  4. brawner commented on Jun 16, 2020

    @brawner
    ContributorAuthor

    For reference, this is the error message:

    [20.871s] 8: [ RUN      ] TestCreateTimer.call_wall_timer_with_bad_arguments
    [20.874s] 8: [ERROR] [1592350214.053122631] [rclcpp]: Couldn't initialize rcl timer handle: timer period must be non-negative, at /home/brawner/workspace/ros2_master/src/ros2/rcl/rcl/src/rcl/timer.c:139
    [20.874s] 8: 
    [20.874s] 8: terminate called after throwing an instance of 'std::runtime_error'
    [20.874s] 8:   what():  Couldn't cancel timer: timer is invalid, at /home/brawner/workspace/ros2_master/src/ros2/rcl/rcl/src/rcl/timer.c:379
    [20.938s] 8: -- run_test.py: return code -6
    
  5. fujitatomoya commented on Jun 17, 2020

    @fujitatomoya
    Collaborator

    @brawner

    During the destructor of WallTimer, it will call cancel, which results in a double free.

    i do not think of doube free case either, but exception in destructor.

    checking argument is also better, but we could change like only issue cancel on initialized rcl_timer_t successfully, i think that would be less exception.

  6. brawner commented on Jun 17, 2020

    @brawner
    ContributorAuthor

    Agreed @fujitatomoya. This was the intended second PR to followup and resolve the issue. It throws an exception in the constructor if rcl_timer_init fails.

    #1179

  7. brawner commented on Jun 29, 2020

    @brawner
    ContributorAuthor

    I believe this has been adequately addressed by #1178 and #1179.

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

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions