]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/xen.git/commitdiff
tools/libxl: Make libxl__conversion_helper_abort() safe to use
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 4 Aug 2015 17:16:31 +0000 (18:16 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Wed, 5 Aug 2015 09:40:35 +0000 (10:40 +0100)
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 <andrew.cooper3@citrix.com>
Acked-by: Ian Campbell <Ian.Campbell@citrix.com>
tools/libxl/libxl_convert_callout.c
tools/libxl/libxl_internal.h
tools/libxl/libxl_stream_read.c
tools/libxl/libxl_stream_write.c

index 65b4df9d364b38f39cfe77f529681f51a730afda..5e5678b896b63e958d91b0bd9752bff57c3d9cf0 100644 (file)
@@ -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);
index 29e04291b52095e8e9f6aee641e564cade41ac85..0253b49f7e527fb3165e577d45d19f3799cf56cc 100644 (file)
@@ -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
index fd3675cc591c277822ddfda38934758031497f24..c555542ac99d981b1f708c0727e8226b60177367 100644 (file)
@@ -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);
index 9e9c9986f1bcc8e165546ba3eff9525dff31718e..be8f54806aabcd3666f2359260afb68cb58c72c8 100644 (file)
@@ -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;