Blame SOURCES/0003-hivexml-Tidy-up-error-handling-and-printing.patch

c1e277
From 2cffe999c938a0bc67c3c6162ea4fc896af2dd22 Mon Sep 17 00:00:00 2001
c1e277
From: "Richard W.M. Jones" <rjones@redhat.com>
c1e277
Date: Mon, 22 Sep 2014 15:10:36 +0100
c1e277
Subject: [PATCH 03/12] hivexml: Tidy up error handling and printing.
c1e277
c1e277
(cherry picked from commit 914d9b9a91babf0227989bc7ea00cf5e41ed7da4)
c1e277
---
c1e277
 xml/hivexml.c | 28 +++++++++++++---------------
c1e277
 1 file changed, 13 insertions(+), 15 deletions(-)
c1e277
c1e277
diff --git a/xml/hivexml.c b/xml/hivexml.c
c1e277
index a4bc7eb..b496bb6 100644
c1e277
--- a/xml/hivexml.c
c1e277
+++ b/xml/hivexml.c
c1e277
@@ -116,7 +116,7 @@ main (int argc, char *argv[])
c1e277
 
c1e277
   hive_h *h = hivex_open (argv[optind], open_flags);
c1e277
   if (h == NULL) {
c1e277
-    perror (argv[optind]);
c1e277
+    fprintf (stderr, "hivex_open: %s: %m\n", argv[optind]);
c1e277
     exit (EXIT_FAILURE);
c1e277
   }
c1e277
 
c1e277
@@ -148,12 +148,12 @@ main (int argc, char *argv[])
c1e277
   }
c1e277
 
c1e277
   if (hivex_visit (h, &visitor, sizeof visitor, writer, visit_flags) == -1) {
c1e277
-    perror (argv[optind]);
c1e277
+    fprintf (stderr, "hivex_visit: %s: %m\n", argv[optind]);
c1e277
     exit (EXIT_FAILURE);
c1e277
   }
c1e277
 
c1e277
   if (hivex_close (h) == -1) {
c1e277
-    perror (argv[optind]);
c1e277
+    fprintf (stderr, "hivex_close: %s: %m\n", argv[optind]);
c1e277
     exit (EXIT_FAILURE);
c1e277
   }
c1e277
 
c1e277
@@ -217,12 +217,9 @@ node_byte_runs (hive_h *h, void *writer_v, hive_node_h node)
c1e277
 {
c1e277
   xmlTextWriterPtr writer = (xmlTextWriterPtr) writer_v;
c1e277
   char buf[1+BYTE_RUN_BUF_LEN];
c1e277
-  errno = 0;
c1e277
   size_t node_struct_length = hivex_node_struct_length (h, node);
c1e277
-  if (errno) {
c1e277
-    if (errno == EINVAL) {
c1e277
-      fprintf (stderr, "node_byte_runs: Invoked on what does not seem to be a node (%zu).\n", node);
c1e277
-    }
c1e277
+  if (node_struct_length == 0) {
c1e277
+    fprintf (stderr, "node_byte_runs: hivex_node_struct_length: %m\n");
c1e277
     return -1;
c1e277
   }
c1e277
   /* A node has one byte run. */
c1e277
@@ -301,17 +298,18 @@ value_byte_runs (hive_h *h, void *writer_v, hive_value_h value) {
c1e277
   xmlTextWriterPtr writer = (xmlTextWriterPtr) writer_v;
c1e277
   char buf[1+BYTE_RUN_BUF_LEN];
c1e277
   size_t value_data_cell_length;
c1e277
-  errno = 0;
c1e277
   size_t value_data_structure_length = hivex_value_struct_length (h, value);
c1e277
-  if (errno != 0) {
c1e277
-    if (errno == EINVAL) {
c1e277
-      fprintf (stderr, "value_byte_runs: Invoked on what does not seem to be a value (%zu).\n", value);
c1e277
-    }
c1e277
+  if (value_data_structure_length == 0) {
c1e277
+    fprintf (stderr, "value_byte_runs: hivex_value_struct_length: %m\n");
c1e277
     return -1;
c1e277
   }
c1e277
-  hive_value_h value_data_cell_offset = hivex_value_data_cell_offset (h, value, &value_data_cell_length);
c1e277
-  if (errno != 0)
c1e277
+  errno = 0;
c1e277
+  hive_value_h value_data_cell_offset =
c1e277
+    hivex_value_data_cell_offset (h, value, &value_data_cell_length);
c1e277
+  if (value_data_cell_offset == 0 && errno != 0) {
c1e277
+    fprintf (stderr, "value_byte_runs: hivex_value_data_cell_offset: %m\n");
c1e277
     return -1;
c1e277
+  }
c1e277
 
c1e277
   XML_CHECK (xmlTextWriterStartElement, (writer, BAD_CAST "byte_runs"));
c1e277
   memset (buf, 0, 1+BYTE_RUN_BUF_LEN);
c1e277
-- 
c1e277
1.8.3.1
c1e277