[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH for-4.6 v2 1/6] 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 <andrew.cooper3@xxxxxxxxxx>
---
CC: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
CC: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
CC: Wei Liu <wei.liu2@xxxxxxxxxx>

v2: Make sure ->ao is always valid
---
 tools/libxl/libxl_convert_callout.c |    2 ++
 tools/libxl/libxl_internal.h        |    4 ++--
 tools/libxl/libxl_stream_read.c     |   11 ++++++++---
 tools/libxl/libxl_stream_write.c    |    5 +++++
 4 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/tools/libxl/libxl_convert_callout.c 
b/tools/libxl/libxl_convert_callout.c
index 65b4df9..5e5678b 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 911de2d..22d6a26 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2948,9 +2948,9 @@ _hidden void libxl__remus_devices_commit(libxl__egc *egc,
 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 fd3675c..c555542 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 9e9c998..be8f548 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;
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.