From: Andrew Cooper Date: Tue, 4 Aug 2015 17:16:31 +0000 (+0100) Subject: tools/libxl: Make libxl__conversion_helper_abort() safe to use X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~2652 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2b8ba04cd150250d23ff0a396851b7ec9a500f07;p=xen.git tools/libxl: Make libxl__conversion_helper_abort() safe to use Previously, in the case of an error causing a call to libxl__conversion_helper_abort() on a stream without legacy conversion, libxl would fall over a NULL pointer because chs->ao was not set up. Arrange for all ->ao's to be set up at _init() time, by having each _init() function assert that their caller has done the right thing. While doing so, introduce a previously-missing save_helper_init() in stream_read_init(). Signed-off-by: Andrew Cooper Acked-by: Ian Campbell --- diff --git a/tools/libxl/libxl_convert_callout.c b/tools/libxl/libxl_convert_callout.c index 65b4df9d36..5e5678b896 100644 --- a/tools/libxl/libxl_convert_callout.c +++ b/tools/libxl/libxl_convert_callout.c @@ -34,6 +34,8 @@ static void helper_done(libxl__egc *egc, void libxl__conversion_helper_init(libxl__conversion_helper_state *chs) { + assert(chs->ao); + chs->v2_carefd = NULL; chs->rc = 0; libxl__ao_abortable_init(&chs->abrt); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 29e04291b5..0253b49f7e 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2945,9 +2945,9 @@ _hidden int libxl__netbuffer_enabled(libxl__gc *gc); typedef struct libxl__conversion_helper_state libxl__conversion_helper_state; struct libxl__conversion_helper_state { - /* public */ + /* Public - Must be filled by caller unless noted. */ libxl__ao *ao; - int legacy_fd; + int legacy_fd; /* fd to read the legacy stream from. */ bool hvm; /* pv or hvm domain? */ libxl__carefd *v2_carefd; /* Filled by successful call to * libxl__convert_legacy_stream(). Caller diff --git a/tools/libxl/libxl_stream_read.c b/tools/libxl/libxl_stream_read.c index fd3675cc59..c555542ac9 100644 --- a/tools/libxl/libxl_stream_read.c +++ b/tools/libxl/libxl_stream_read.c @@ -173,12 +173,18 @@ static void free_record(libxl__sr_record_buf *rec) void libxl__stream_read_init(libxl__stream_read_state *stream) { + assert(stream->ao); + + stream->shs.ao = stream->ao; + libxl__save_helper_init(&stream->shs); + + stream->chs.ao = stream->ao; + libxl__conversion_helper_init(&stream->chs); + stream->rc = 0; stream->running = false; stream->in_checkpoint = false; stream->sync_teardown = false; - libxl__save_helper_init(&stream->shs); - libxl__conversion_helper_init(&stream->chs); FILLZERO(stream->dc); FILLZERO(stream->hdr); LIBXL_STAILQ_INIT(&stream->record_queue); @@ -205,7 +211,6 @@ void libxl__stream_read_start(libxl__egc *egc, /* Convert the legacy stream. */ libxl__conversion_helper_state *chs = &stream->chs; - chs->ao = stream->ao; chs->legacy_fd = stream->fd; chs->hvm = (stream->dcs->guest_config->b_info.type == LIBXL_DOMAIN_TYPE_HVM); diff --git a/tools/libxl/libxl_stream_write.c b/tools/libxl/libxl_stream_write.c index 9e9c9986f1..be8f54806a 100644 --- a/tools/libxl/libxl_stream_write.c +++ b/tools/libxl/libxl_stream_write.c @@ -155,6 +155,11 @@ static void write_done(libxl__egc *egc, void libxl__stream_write_init(libxl__stream_write_state *stream) { + assert(stream->ao); + + stream->shs.ao = stream->ao; + libxl__save_helper_init(&stream->shs); + stream->rc = 0; stream->running = false; stream->in_checkpoint = false;