summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVolodymyr Brynza <v.brynza@samsung.com>2017-03-06 09:48:55 +0200
committerVolodymyr Brynza <v.brynza@samsung.com>2017-03-06 09:48:55 +0200
commitdd5a724640447790e39898e0ef59f2484b082b39 (patch)
tree4b65a0ffade9147a8c3a5c4fdca362c8091fe07e /src
parent6034dbea9f0688b07c36e652b6e71c72e07f47a4 (diff)
downloadmurphy-dd5a724640447790e39898e0ef59f2484b082b39.tar.gz
murphy-dd5a724640447790e39898e0ef59f2484b082b39.tar.bz2
murphy-dd5a724640447790e39898e0ef59f2484b082b39.zip
Add NULL check to prevent crashes in super_*_cb
Change-Id: Ib0a1dfe6b11290bf18657cba5f3dbffe880516b3 Signed-off-by: Volodymyr Brynza <v.brynza@samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/common/mainloop.c66
1 files changed, 53 insertions, 13 deletions
diff --git a/src/common/mainloop.c b/src/common/mainloop.c
index 58264c1..6519c9d 100644
--- a/src/common/mainloop.c
+++ b/src/common/mainloop.c
@@ -1236,36 +1236,74 @@ void mrp_del_subloop(mrp_subloop_t *sl)
static void super_io_cb(void *super_data, void *id, int fd,
mrp_io_event_t events, void *user_data)
{
- mrp_mainloop_t *ml = (mrp_mainloop_t *)user_data;
- mrp_superloop_ops_t *ops = ml->super_ops;
+ mrp_mainloop_t *ml = NULL;
+ mrp_superloop_ops_t *ops = NULL;
+
+ ml = (mrp_mainloop_t *)user_data;
+ if (ml == NULL) {
+ mrp_log_error("Passed NULL mainloop handle to callback");
+ return;
+ }
+
+ ops = ml->super_ops;
+ if (ops == NULL) {
+ mrp_log_error("Mainloop operation are NULL");
+ return;
+ }
MRP_UNUSED(super_data);
MRP_UNUSED(id);
MRP_UNUSED(fd);
MRP_UNUSED(events);
- ops->mod_defer(ml->super_data, ml->work, TRUE);
+ if (ops->mod_defer)
+ ops->mod_defer(ml->super_data, ml->work, TRUE);
}
static void super_timer_cb(void *super_data, void *id, void *user_data)
{
- mrp_mainloop_t *ml = (mrp_mainloop_t *)user_data;
- mrp_superloop_ops_t *ops = ml->super_ops;
+ mrp_mainloop_t *ml = NULL;
+ mrp_superloop_ops_t *ops = NULL;
+
+ ml = (mrp_mainloop_t *)user_data;
+ if (ml == NULL) {
+ mrp_log_error("Passed NULL mainloop handle to callback");
+ return;
+ }
+
+ ops = ml->super_ops;
+ if (ops == NULL) {
+ mrp_log_error("Mainloop operation are NULL");
+ return;
+ }
MRP_UNUSED(super_data);
MRP_UNUSED(id);
- ops->mod_defer(ml->super_data, ml->work, TRUE);
+ if (ops->mod_defer)
+ ops->mod_defer(ml->super_data, ml->work, TRUE);
}
static void super_work_cb(void *super_data, void *id, void *user_data)
{
- mrp_mainloop_t *ml = (mrp_mainloop_t *)user_data;
- mrp_superloop_ops_t *ops = ml->super_ops;
+ mrp_mainloop_t *ml = NULL;
+ mrp_superloop_ops_t *ops = NULL;
unsigned int timeout;
+ ml = (mrp_mainloop_t *)user_data;
+ if (ml == NULL) {
+ mrp_log_error("Passed NULL mainloop handle to callback");
+ return;
+ }
+
+ ops = ml->super_ops;
+ if (ops == NULL) {
+ mrp_log_error("Mainloop operation are NULL");
+ return;
+ }
+
MRP_UNUSED(super_data);
MRP_UNUSED(id);
@@ -1292,21 +1330,23 @@ static void super_work_cb(void *super_data, void *id, void *user_data)
*/
timeout = mrp_list_empty(&ml->deferred) ? ml->poll_timeout : 0;
- ops->mod_timer(ml->super_data, ml->timer, timeout);
- ops->mod_defer(ml->super_data, ml->work, FALSE);
+ if (ops->mod_timer && ops->mod_defer) {
+ ops->mod_timer(ml->super_data, ml->timer, timeout);
+ ops->mod_defer(ml->super_data, ml->work, FALSE);
+ }
}
else {
- if (ml->iow != NULL) {
+ if (ops->del_io != NULL && ml->iow != NULL) {
ops->del_io(ml->super_data, ml->iow);
ml->iow = NULL;
}
- if (ml->work != NULL) {
+ if (ops->del_defer != NULL && ml->work != NULL) {
ops->del_defer(ml->super_data, ml->work);
ml->work = NULL;
}
- if (ml->timer != NULL) {
+ if (ops->del_timer != NULL && ml->timer != NULL) {
ops->del_timer(ml->super_data, ml->timer);
ml->timer = NULL;
}