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