From: Vincent Hanquez Subject: [PATCH 1/8] don't ignore ctx_init errors if there is one. Date: Fri, 8 Jan 2010 11:17:54 +0000 Message-ID: <1262949481-25530-2-git-send-email-vincent.hanquez@eu.citrix.com> References: <1262949481-25530-1-git-send-email-vincent.hanquez@eu.citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------1.6.6" Return-path: In-Reply-To: <1262949481-25530-1-git-send-email-vincent.hanquez@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: Vincent Hanquez List-Id: xen-devel@lists.xenproject.org --------------1.6.6 Content-Type: text/plain; charset="UTF-8"; format=fixed Content-Transfer-Encoding: quoted-printable ctx_init can return error, and ignoring the errors, would lead to segfaul= t later. fix all call sites to check return values. Signed-off-by: Vincent Hanquez --- tools/libxl/xl.c | 61 +++++++++++++++++++++++++++++++++++++++++++-----= ----- 1 files changed, 49 insertions(+), 12 deletions(-) --------------1.6.6 Content-Type: text/x-patch; name="0001-don-t-ignore-ctx_init-errors-if-there-is-one.patch" Content-Disposition: attachment; filename="0001-don-t-ignore-ctx_init-errors-if-there-is-one.patch" Content-Transfer-Encoding: quoted-printable diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c index bc7378c..79d2f6c 100644 --- a/tools/libxl/xl.c +++ b/tools/libxl/xl.c @@ -762,7 +762,11 @@ static void create_domain(int debug, int daemonize, = const char *config_file, con start: domid =3D 0; =20 - libxl_ctx_init(&ctx, LIBXL_VERSION); + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { + fprintf(stderr, "cannot init xl context\n"); + return; + } + libxl_ctx_set_log(&ctx, log_callback, NULL); libxl_domain_make(&ctx, &info1, &domid); =20 @@ -974,7 +978,10 @@ void set_memory_target(char *p, char *mem) struct libxl_ctx ctx; uint32_t domid; =20 - libxl_ctx_init(&ctx, LIBXL_VERSION); + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { + fprintf(stderr, "cannot init xl context\n"); + return; + } libxl_ctx_set_log(&ctx, log_callback, NULL); =20 if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) { @@ -1016,7 +1023,10 @@ void console(char *p, int cons_num) struct libxl_ctx ctx; uint32_t domid; =20 - libxl_ctx_init(&ctx, LIBXL_VERSION); + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { + fprintf(stderr, "cannot init xl context\n"); + return; + } libxl_ctx_set_log(&ctx, log_callback, NULL); =20 if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) { @@ -1033,7 +1043,10 @@ void cd_insert(char *dom, char *virtdev, char *phy= s) libxl_device_disk disk; char *p; =20 - libxl_ctx_init(&ctx, LIBXL_VERSION); + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { + fprintf(stderr, "cannot init xl context\n"); + return; + } libxl_ctx_set_log(&ctx, log_callback, NULL); =20 if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) { @@ -1166,7 +1179,10 @@ void pcilist(char *dom) libxl_device_pci *pcidevs; int num, i; =20 - libxl_ctx_init(&ctx, LIBXL_VERSION); + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { + fprintf(stderr, "cannot init xl context\n"); + return; + } libxl_ctx_set_log(&ctx, log_callback, NULL); =20 if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) { @@ -1216,7 +1232,10 @@ void pcidetach(char *dom, char *bdf) libxl_device_pci pcidev; unsigned int domain, bus, dev, func; =20 - libxl_ctx_init(&ctx, LIBXL_VERSION); + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { + fprintf(stderr, "cannot init xl context\n"); + return; + } libxl_ctx_set_log(&ctx, log_callback, NULL); =20 if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) { @@ -1262,7 +1281,10 @@ void pciattach(char *dom, char *bdf, char *vs) libxl_device_pci pcidev; unsigned int domain, bus, dev, func; =20 - libxl_ctx_init(&ctx, LIBXL_VERSION); + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { + fprintf(stderr, "cannot init xl context\n"); + return; + } libxl_ctx_set_log(&ctx, log_callback, NULL); =20 if (domain_qualifier_to_domid(&ctx, dom, &domid) < 0) { @@ -1310,7 +1332,10 @@ void pause_domain(char *p) struct libxl_ctx ctx; uint32_t domid; =20 - libxl_ctx_init(&ctx, LIBXL_VERSION); + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { + fprintf(stderr, "cannot init xl context\n"); + return; + } libxl_ctx_set_log(&ctx, log_callback, NULL); =20 if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) { @@ -1325,7 +1350,10 @@ void unpause_domain(char *p) struct libxl_ctx ctx; uint32_t domid; =20 - libxl_ctx_init(&ctx, LIBXL_VERSION); + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { + fprintf(stderr, "cannot init xl context\n"); + return; + } libxl_ctx_set_log(&ctx, log_callback, NULL); =20 if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) { @@ -1340,7 +1368,10 @@ void destroy_domain(char *p) struct libxl_ctx ctx; uint32_t domid; =20 - libxl_ctx_init(&ctx, LIBXL_VERSION); + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { + fprintf(stderr, "cannot init xl context\n"); + return; + } libxl_ctx_set_log(&ctx, log_callback, NULL); =20 if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) { @@ -1356,7 +1387,10 @@ void list_domains(void) struct libxl_dominfo *info; int nb_domain, i; =20 - libxl_ctx_init(&ctx, LIBXL_VERSION); + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { + fprintf(stderr, "cannot init xl context\n"); + return; + } libxl_ctx_set_log(&ctx, log_callback, NULL); =20 info =3D libxl_domain_list(&ctx, &nb_domain); @@ -1383,7 +1417,10 @@ int save_domain(char *p, char *filename, int check= point) uint32_t domid; int fd; =20 - libxl_ctx_init(&ctx, LIBXL_VERSION); + if (libxl_ctx_init(&ctx, LIBXL_VERSION)) { + fprintf(stderr, "cannot init xl context\n"); + exit(2); + } libxl_ctx_set_log(&ctx, log_callback, NULL); =20 if (domain_qualifier_to_domid(&ctx, p, &domid) < 0) { --------------1.6.6 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --------------1.6.6--