Richard W.M. Jones
2011-Mar-07 16:13 UTC
[Libguestfs] [PATCH] Fix trace segfault for non-daemon functions (RHBZ#682756).
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora -------------- next part -------------->From 819975af019d4213721e40a2dc49ef5d2f9e9bc4 Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Mon, 7 Mar 2011 15:55:56 +0000 Subject: [PATCH] Fix trace segfault for non-daemon functions (RHBZ#682756). --- generator/generator_c.ml | 40 +++++++++++++++++++++++----------------- 1 files changed, 23 insertions(+), 17 deletions(-) diff --git a/generator/generator_c.ml b/generator/generator_c.ml index c4915ea..c4ceebf 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -887,22 +887,22 @@ check_state (guestfs_h *g, const char *caller) shortname style; pr "{\n"; pr " int trace_flag = g->trace;\n"; - (match ret with - | RErr | RInt _ | RBool _ -> - pr " int r;\n" - | RInt64 _ -> - pr " int64_t r;\n" - | RConstString _ | RConstOptString _ -> - pr " const char *r;\n" - | RString _ | RBufferOut _ -> - pr " char *r;\n" - | RStringList _ | RHashtable _ -> - pr " char **r;\n" - | RStruct (_, typ) -> - pr " struct guestfs_%s *r;\n" typ - | RStructList (_, typ) -> - pr " struct guestfs_%s_list *r;\n" typ - ); + let errcode + match ret with + | RErr | RInt _ | RBool _ -> + pr " int r;\n"; "-1" + | RInt64 _ -> + pr " int64_t r;\n"; "-1" + | RConstString _ | RConstOptString _ -> + pr " const char *r;\n"; "NULL" + | RString _ | RBufferOut _ -> + pr " char *r;\n"; "NULL" + | RStringList _ | RHashtable _ -> + pr " char **r;\n"; "NULL" + | RStruct (_, typ) -> + pr " struct guestfs_%s *r;\n" typ; "NULL" + | RStructList (_, typ) -> + pr " struct guestfs_%s_list *r;\n" typ; "NULL" in pr "\n"; check_null_strings shortname style; reject_unknown_optargs shortname style; @@ -910,7 +910,13 @@ check_state (guestfs_h *g, const char *caller) pr " r = guestfs__%s " shortname; generate_c_call_args ~handle:"g" style; pr ";\n"; - trace_return shortname style "r"; + pr "\n"; + pr " if (r != %s) {\n" errcode; + trace_return ~indent:4 shortname style "r"; + pr " } else {\n"; + trace_return_error ~indent:4 shortname style; + pr " }\n"; + pr "\n"; pr " return r;\n"; pr "}\n"; pr "\n" -- 1.7.4
Richard W.M. Jones
2011-Mar-07 16:46 UTC
[Libguestfs] [PATCH v2] Fix trace segfault for non-daemon functions (RHBZ#682756).
Previous patch broke RConstOptString. Try this updated version. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw -------------- next part -------------->From 7c721e4fd674c409b3eee60fe237d480afa1c5e2 Mon Sep 17 00:00:00 2001From: Richard W.M. Jones <rjones at redhat.com> Date: Mon, 7 Mar 2011 15:55:56 +0000 Subject: [PATCH] Fix trace segfault for non-daemon functions (RHBZ#682756). Previously we expanded the code for 'trace_return' unconditionally for all non-daemon functions. However this code was not prepared to handle all error conditions, and in fact would segfault if it tried to print RStringList or RHashtable where r == NULL. We need to make the code conditional on the return value, calling either 'trace_return' or 'trace_return_error' as appropriate. Note the difficult case for RConstOptString which returns NULL in non-error cases. --- generator/generator_c.ml | 47 +++++++++++++++++++++++++++++---------------- 1 files changed, 30 insertions(+), 17 deletions(-) diff --git a/generator/generator_c.ml b/generator/generator_c.ml index c4915ea..99cf327 100644 --- a/generator/generator_c.ml +++ b/generator/generator_c.ml @@ -887,22 +887,24 @@ check_state (guestfs_h *g, const char *caller) shortname style; pr "{\n"; pr " int trace_flag = g->trace;\n"; - (match ret with - | RErr | RInt _ | RBool _ -> - pr " int r;\n" - | RInt64 _ -> - pr " int64_t r;\n" - | RConstString _ | RConstOptString _ -> - pr " const char *r;\n" - | RString _ | RBufferOut _ -> - pr " char *r;\n" - | RStringList _ | RHashtable _ -> - pr " char **r;\n" - | RStruct (_, typ) -> - pr " struct guestfs_%s *r;\n" typ - | RStructList (_, typ) -> - pr " struct guestfs_%s_list *r;\n" typ - ); + let errcode + match ret with + | RErr | RInt _ | RBool _ -> + pr " int r;\n"; Some "-1" + | RInt64 _ -> + pr " int64_t r;\n"; Some "-1" + | RConstString _ -> + pr " const char *r;\n"; Some "NULL" + | RConstOptString _ -> + pr " const char *r;\n"; None + | RString _ | RBufferOut _ -> + pr " char *r;\n"; Some "NULL" + | RStringList _ | RHashtable _ -> + pr " char **r;\n"; Some "NULL" + | RStruct (_, typ) -> + pr " struct guestfs_%s *r;\n" typ; Some "NULL" + | RStructList (_, typ) -> + pr " struct guestfs_%s_list *r;\n" typ; Some "NULL" in pr "\n"; check_null_strings shortname style; reject_unknown_optargs shortname style; @@ -910,7 +912,18 @@ check_state (guestfs_h *g, const char *caller) pr " r = guestfs__%s " shortname; generate_c_call_args ~handle:"g" style; pr ";\n"; - trace_return shortname style "r"; + pr "\n"; + (match errcode with + | Some errcode -> + pr " if (r != %s) {\n" errcode; + trace_return ~indent:4 shortname style "r"; + pr " } else {\n"; + trace_return_error ~indent:4 shortname style; + pr " }\n"; + | None -> + trace_return shortname style "r"; + ); + pr "\n"; pr " return r;\n"; pr "}\n"; pr "\n" -- 1.7.4
Apparently Analagous Threads
- [PATCH] Improve errors from tar-in/tgz-in commands (RHBZ#591155 RHBZ#591250).
- [PATCH 0/13 v2] Prepare for adding write support to hivex (Windows registry) library
- [PATCH 0/4] Fix RHBZ#597112 (get-e2uuid command)
- [PATCH 0/7] Prepare for adding write support to hivex (windows registry) library
- [PATCH for discussion only] add_drive_ro adds readonly=on option if available.