bbc6a89
From 76188809d5ca40c5285b0ab202b5edea7be3f04d Mon Sep 17 00:00:00 2001
bbc6a89
From: =?UTF-8?q?Pali=20Roh=C3=A1r?= <pali.rohar@gmail.com>
bbc6a89
Date: Thu, 22 Jun 2017 14:33:17 +0200
6f1e3d5
Subject: [PATCH 052/198] udf: Fix reading label, lvd.ident is dstring
bbc6a89
bbc6a89
UDF dstring has stored length in the last byte of buffer. Therefore last
bbc6a89
byte is not part of recorded characters. And empty string in dstring is
bbc6a89
encoded as empty buffer, including first byte (compression id).
bbc6a89
---
bbc6a89
 grub-core/fs/udf.c | 21 ++++++++++++++++++++-
bbc6a89
 1 file changed, 20 insertions(+), 1 deletion(-)
bbc6a89
bbc6a89
diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c
bbc6a89
index 839bff889..258745633 100644
bbc6a89
--- a/grub-core/fs/udf.c
bbc6a89
+++ b/grub-core/fs/udf.c
bbc6a89
@@ -860,6 +860,25 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf)
bbc6a89
   return outbuf;
bbc6a89
 }
bbc6a89
 
bbc6a89
+static char *
bbc6a89
+read_dstring (const grub_uint8_t *raw, grub_size_t sz)
bbc6a89
+{
bbc6a89
+  grub_size_t len;
bbc6a89
+
bbc6a89
+  if (raw[0] == 0) {
bbc6a89
+      char *outbuf = grub_malloc (1);
bbc6a89
+      if (!outbuf)
bbc6a89
+	return NULL;
bbc6a89
+      outbuf[0] = 0;
bbc6a89
+      return outbuf;
bbc6a89
+    }
bbc6a89
+
bbc6a89
+  len = raw[sz - 1];
bbc6a89
+  if (len > sz - 1)
bbc6a89
+    len = sz - 1;
bbc6a89
+  return read_string (raw, len, NULL);
bbc6a89
+}
bbc6a89
+
bbc6a89
 static int
bbc6a89
 grub_udf_iterate_dir (grub_fshelp_node_t dir,
bbc6a89
 		      grub_fshelp_iterate_dir_hook_t hook, void *hook_data)
bbc6a89
@@ -1197,7 +1216,7 @@ grub_udf_label (grub_device_t device, char **label)
bbc6a89
 
bbc6a89
   if (data)
bbc6a89
     {
bbc6a89
-      *label = read_string (data->lvd.ident, sizeof (data->lvd.ident), 0);
bbc6a89
+      *label = read_dstring (data->lvd.ident, sizeof (data->lvd.ident));
bbc6a89
       grub_free (data);
bbc6a89
     }
bbc6a89
   else
bbc6a89
-- 
da63b36
2.14.3
bbc6a89