Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asterisk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Voice
asterisk
Commits
e0b5d74e
Commit
e0b5d74e
authored
6 years ago
by
Joshua Colp
Committed by
Gerrit Code Review
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge "test_res_pjsip_scheduler: Fix possible write after free in scheduler_policy." into 13
parents
6dba9ca6
8e7a8e87
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_res_pjsip_scheduler.c
+34
-5
34 additions, 5 deletions
tests/test_res_pjsip_scheduler.c
with
34 additions
and
5 deletions
tests/test_res_pjsip_scheduler.c
+
34
−
5
View file @
e0b5d74e
...
@@ -55,6 +55,7 @@ struct test_data {
...
@@ -55,6 +55,7 @@ struct test_data {
int
interval
;
int
interval
;
int
sleep
;
int
sleep
;
int
done
;
int
done
;
int
no_clear_done
;
struct
ast_test
*
test
;
struct
ast_test
*
test
;
};
};
...
@@ -65,7 +66,9 @@ static int task_1(void *data)
...
@@ -65,7 +66,9 @@ static int task_1(void *data)
{
{
struct
test_data
*
test
=
data
;
struct
test_data
*
test
=
data
;
test
->
done
=
0
;
if
(
!
test
->
no_clear_done
)
{
test
->
done
=
0
;
}
test
->
task_start
=
ast_tvnow
();
test
->
task_start
=
ast_tvnow
();
test
->
tid
=
pthread_self
();
test
->
tid
=
pthread_self
();
test
->
is_servant
=
ast_sip_thread_is_servant
();
test
->
is_servant
=
ast_sip_thread_is_servant
();
...
@@ -73,7 +76,7 @@ static int task_1(void *data)
...
@@ -73,7 +76,7 @@ static int task_1(void *data)
test
->
task_end
=
ast_tvnow
();
test
->
task_end
=
ast_tvnow
();
ast_mutex_lock
(
&
test
->
lock
);
ast_mutex_lock
(
&
test
->
lock
);
test
->
done
=
1
;
test
->
done
++
;
ast_mutex_unlock
(
&
test
->
lock
);
ast_mutex_unlock
(
&
test
->
lock
);
ast_cond_signal
(
&
test
->
cond
);
ast_cond_signal
(
&
test
->
cond
);
...
@@ -347,11 +350,12 @@ AST_TEST_DEFINE(scheduler_policy)
...
@@ -347,11 +350,12 @@ AST_TEST_DEFINE(scheduler_policy)
test_data1
->
test_start
=
ast_tvnow
();
test_data1
->
test_start
=
ast_tvnow
();
test_data1
->
interval
=
1000
;
test_data1
->
interval
=
1000
;
test_data1
->
sleep
=
500
;
test_data1
->
sleep
=
500
;
test_data1
->
no_clear_done
=
1
;
ast_mutex_init
(
&
test_data1
->
lock
);
ast_mutex_init
(
&
test_data1
->
lock
);
ast_cond_init
(
&
test_data1
->
cond
,
NULL
);
ast_cond_init
(
&
test_data1
->
cond
,
NULL
);
ast_test_status_update
(
test
,
"This test will take about %3.1f seconds
\n
"
,
ast_test_status_update
(
test
,
"This test will take about %3.1f seconds
\n
"
,
((
test_data1
->
interval
*
3
)
+
test_data1
->
sleep
)
/
1000
.
0
);
((
test_data1
->
interval
*
4
)
+
test_data1
->
sleep
)
/
1000
.
0
);
task
=
ast_sip_schedule_task
(
NULL
,
test_data1
->
interval
,
task_1
,
"test_1"
,
test_data1
,
task
=
ast_sip_schedule_task
(
NULL
,
test_data1
->
interval
,
task_1
,
"test_1"
,
test_data1
,
AST_SIP_SCHED_TASK_DATA_NO_CLEANUP
|
AST_SIP_SCHED_TASK_PERIODIC
);
AST_SIP_SCHED_TASK_DATA_NO_CLEANUP
|
AST_SIP_SCHED_TASK_PERIODIC
);
...
@@ -370,8 +374,33 @@ AST_TEST_DEFINE(scheduler_policy)
...
@@ -370,8 +374,33 @@ AST_TEST_DEFINE(scheduler_policy)
ast_test_validate
(
test
,
when
>
test_data1
->
interval
*
3
*
0
.
9
&&
when
<
test_data1
->
interval
*
3
*
1
.
1
);
ast_test_validate
(
test
,
when
>
test_data1
->
interval
*
3
*
0
.
9
&&
when
<
test_data1
->
interval
*
3
*
1
.
1
);
ast_sip_sched_task_cancel
(
task
);
ast_sip_sched_task_cancel
(
task
);
ao2_ref
(
task
,
-
1
);
task
=
NULL
;
/* Wait a full interval in case a 4th call to test_1 happened before the cancel */
usleep
(
M2U
(
test_data1
->
interval
));
ast_mutex_lock
(
&
test_data1
->
lock
);
if
(
test_data1
->
done
)
{
int
done
=
test_data1
->
done
;
test_data1
->
done
=
0
;
ast_mutex_unlock
(
&
test_data1
->
lock
);
ast_test_validate
(
test
,
done
==
1
);
/* Wait two full intervals to be certain no further calls to test_1. */
usleep
(
M2U
(
test_data1
->
interval
*
2
));
ast_mutex_lock
(
&
test_data1
->
lock
);
if
(
test_data1
->
done
!=
0
)
{
ast_mutex_unlock
(
&
test_data1
->
lock
);
/* The cancelation failed so we need to prevent cleanup of
* test_data1 to prevent a crash from write-after-free. */
test_data1
=
NULL
;
ast_test_status_update
(
test
,
"Failed to cancel task"
);
return
AST_TEST_FAIL
;
}
}
ast_mutex_unlock
(
&
test_data1
->
lock
);
return
AST_TEST_PASS
;
return
AST_TEST_PASS
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment