monitor: fix double-free of request error
PATCH 1/1 monitor: fix double-free of request error
qmp_error_response() will free the given error. Fix double-free in later qmp_request_free().
--- monitor.c | 1 + 1 file changed, 1 insertion(+)
monitor.c +1 -0
@@ -4186,6 +4186,7 @@ static void monitor_qmp_bh_dispatcher(void *data) }else {assert (req_obj->err); rsp =qmp_error_response (req_obj->err); + req_obj->err =NULL ;monitor_qmp_respond (req_obj->mon, rsp,NULL );qobject_unref (rsp); }
Signature · 1 line
2.18.0.rc1
Quoted 4 lines · Marc-André Lureau
qmp_error_response()will free the given error. Fix double-free in laterqmp_request_free().Signed-off-by Marc-André Lureau <[email protected]>
And not related to current patch...
Quoted 9 lines
--- monitor.c | 1 + 1 file changed, 1 insertion(+)monitor.c +0
-0
monitor.c static void monitor_qmp_bh_dispatcher(void *data) · line 4190
Quoted 5 lines
monitor.c +1
-0@@ -4186,6 +4186,7 @@ static void monitor_qmp_bh_dispatcher(void *data) }else {assert (req_obj->err); rsp =qmp_error_response (req_obj->err); + req_obj->err =NULL ;monitor_qmp_respond (req_obj->mon, rsp,NULL );
... here not sure whether we should just pass in req_obj->id instead of NULL, or maybe we can do some more assertions like:
monitor.c +2 -0
@@ -4215,10 +4215,12 @@ static void monitor_qmp_bh_dispatcher(void *data) mon = req_obj->mon;if (req_obj->req) { +assert (!req_obj->err);trace_monitor_qmp_cmd_in_band (qobject_get_try_str (req_obj->id) ?:"" );monitor_qmp_dispatch (mon, req_obj->req, req_obj->id); }else {assert (req_obj->err); +assert (!req_obj->id); rsp =qmp_error_response (req_obj->err);monitor_qmp_respond (mon, rsp,NULL );qobject_unref (rsp);
Thanks,
Signature · 1 line
Peter Xu
Quoted 33 lines · Peter Xu
Quoted 4 lines · Marc-André Lureau
qmp_error_response()will free the given error. Fix double-free in laterqmp_request_free().Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Peter Xu <[email protected]>And not related to current patch...
Quoted 9 lines
--- monitor.c | 1 + 1 file changed, 1 insertion(+)monitor.c +0
-0monitor.c static void monitor_qmp_bh_dispatcher(void *data) · line 4190
Quoted 5 lines
monitor.c +1
-0@@ -4186,6 +4186,7 @@ static void monitor_qmp_bh_dispatcher(void *data) }else {assert (req_obj->err); rsp =qmp_error_response (req_obj->err); + req_obj->err =NULL ;monitor_qmp_respond (req_obj->mon, rsp,NULL );... here not sure whether we should just pass in
req_obj->idinstead of NULL, or maybe we can do some more assertions like:monitor.c +0
-0
monitor.c static void monitor_qmp_bh_dispatcher(void *data) · line 4218
Quoted 4 lines
monitor.c +1
-0@@ -4215,10 +4215,12 @@ static void monitor_qmp_bh_dispatcher(void *data) mon = req_obj->mon;if (req_obj->req) { +assert (!req_obj->err);
Makes sense.
monitor.c static void monitor_qmp_bh_dispatcher(void *data) · line 4223
Quoted 5 lines
monitor.c +1
-0trace_monitor_qmp_cmd_in_band (qobject_get_try_str (req_obj->id) ?:"" );monitor_qmp_dispatch (mon, req_obj->req, req_obj->id); }else {assert (req_obj->err); +assert (!req_obj->id);
I'd simply pass req_obj->id to monitor_qmp_respond(). Yes, it'll always be null, but the code would do the right thing if that should ever change.
Quoted 5 lines
monitor.c +0
-0rsp =qmp_error_response (req_obj->err);monitor_qmp_respond (mon, rsp,NULL );qobject_unref (rsp);Thanks,
Perhaps even reorder to put the error case first:
if (req_obj->err) {
assert(!req_obj->req);
rsp = qmp_error_response(req_obj->err);
req_obj->err = NULL;
monitor_qmp_respond(req_obj->mon, rsp, req_obj->id);
qobject_unref(rsp);
} else if (req_obj->req) {
trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: "");
monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id);
}Matter of taste.
Quoted 48 lines · Markus Armbruster
Quoted 33 lines · Peter Xu
Quoted 4 lines · Marc-André Lureau
qmp_error_response()will free the given error. Fix double-free in laterqmp_request_free().Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Peter Xu <[email protected]>And not related to current patch...
Quoted 9 lines
--- monitor.c | 1 + 1 file changed, 1 insertion(+)monitor.c +0
-0monitor.c static void monitor_qmp_bh_dispatcher(void *data) · line 4190
Quoted 5 lines
monitor.c +1
-0@@ -4186,6 +4186,7 @@ static void monitor_qmp_bh_dispatcher(void *data) }else {assert (req_obj->err); rsp =qmp_error_response (req_obj->err); + req_obj->err =NULL ;monitor_qmp_respond (req_obj->mon, rsp,NULL );... here not sure whether we should just pass in
req_obj->idinstead of NULL, or maybe we can do some more assertions like:monitor.c +0
-0monitor.c static void monitor_qmp_bh_dispatcher(void *data) · line 4218
Quoted 4 lines
monitor.c +1
-0@@ -4215,10 +4215,12 @@ static void monitor_qmp_bh_dispatcher(void *data) mon = req_obj->mon;if (req_obj->req) { +assert (!req_obj->err);Makes sense.
monitor.c static void monitor_qmp_bh_dispatcher(void *data) · line 4223
Quoted 5 lines
monitor.c +1
-0trace_monitor_qmp_cmd_in_band (qobject_get_try_str (req_obj->id) ?:"" );monitor_qmp_dispatch (mon, req_obj->req, req_obj->id); }else {assert (req_obj->err); +assert (!req_obj->id);
Quoted 3 lines
I'd simply pass
req_obj->idtomonitor_qmp_respond(). Yes, it'll always be null, but the code would do the right thing if that should ever change.
Agreed.
Quoted 20 lines
Quoted 6 lines
monitor.c +0
-0rsp =qmp_error_response (req_obj->err);monitor_qmp_respond (mon, rsp,NULL );qobject_unref (rsp);Thanks,
Perhaps even reorder to put the error case first:
if (req_obj->err) { assert(!req_obj->req); rsp = qmp_error_response(req_obj->err); req_obj->err = NULL; monitor_qmp_respond(req_obj->mon, rsp, req_obj->id); qobject_unref(rsp); } else if (req_obj->req) { trace_monitor_qmp_cmd_in_band(qobject_get_try_str(req_obj->id) ?: ""); monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id); }
Quoted 1 line
Matter of taste.
Looks good to me. Thanks,
Signature · 1 line
Peter Xu
Quoted 4 lines · Marc-André Lureau
qmp_error_response()will free the given error. Fix double-free in laterqmp_request_free().Signed-off-by Marc-André Lureau <[email protected]>
Broken in commit 1cc37471525 by yours truly. I'll add that to the commit message when I apply.