Skip to content

Commit 6573846

Browse files
authored
Merge pull request #1208 from jun0/hrpEC-UAF-debug
Detect use-after-free of hrpExecutionContext
2 parents 008c2c7 + 73574d3 commit 6573846

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

ec/hrpEC/hrpEC-common.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ namespace RTC
1111
{
1212
hrpExecutionContext::~hrpExecutionContext()
1313
{
14+
if (m_thread_pending)
15+
abort ();
1416
}
1517
int hrpExecutionContext::svc(void)
18+
{
19+
int ret = svc_wrapped ();
20+
m_thread_pending = false;
21+
return ret;
22+
}
23+
int hrpExecutionContext::svc_wrapped(void)
1624
{
1725
if (open_iob() == FALSE){
1826
std::cerr << "open_iob: failed to open" << std::endl;
@@ -191,6 +199,12 @@ namespace RTC
191199
throw OpenHRP::ExecutionProfileService::ExecutionProfileServiceException("no such component");
192200
}
193201

202+
void hrpExecutionContext::activate ()
203+
{
204+
m_thread_pending = true;
205+
PeriodicExecutionContext::activate ();
206+
}
207+
194208
void hrpExecutionContext::resetProfile()
195209
{
196210
m_profile.max_period = m_profile.avg_period = 0;

ec/hrpEC/hrpEC.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ namespace RTC
3333
#else
3434
: RTC_exp::PeriodicExecutionContext(),
3535
#endif
36-
m_priority(49)
36+
m_priority(49),
37+
m_thread_pending (false)
3738
{
3839
resetProfile();
3940
rtclog.setName("hrpEC");

ec/hrpEC/hrpEC.h

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace RTC
3535
#ifdef OPENRTM_VERSION_TRUNK
3636
virtual void tick(){}
3737
#endif
38+
void activate ();
3839

3940
OpenHRP::ExecutionProfileService::Profile *getProfile();
4041
OpenHRP::ExecutionProfileService::ComponentProfile getComponentProfile(RTC::LightweightRTObject_ptr obj);
@@ -64,10 +65,13 @@ namespace RTC
6465
}
6566
fprintf(stderr, "[ms]\n");
6667
};
68+
int svc_wrapped (void);
69+
6770
OpenHRP::ExecutionProfileService::Profile m_profile;
6871
struct timeval m_tv;
6972
int m_priority;
7073
std::vector<std::string> rtc_names;
74+
volatile bool m_thread_pending;
7175
};
7276
};
7377

0 commit comments

Comments
 (0)