File 0004-cryptodisk-strip-parenthesis-from-backing-device-nam.patch of Package grub2.4793

From c93d3e694713b8230fa2cf88414fabe005b56782 Mon Sep 17 00:00:00 2001
From: Andrei Borzenkov <arvidjaar@gmail.com>
Date: Sun, 13 Sep 2015 20:12:31 +0300
Subject: [PATCH] cryptodisk: strip parenthesis from backing device name

Otherwise subsequent disk open fails.

Reported-By: Klemens Nanni <contact@autoboot.org>
---
 grub-core/disk/cryptodisk.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
index 82a3dcb..85d68e3 100644
--- a/grub-core/disk/cryptodisk.c
+++ b/grub-core/disk/cryptodisk.c
@@ -964,33 +964,43 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args)
       grub_disk_t disk;
       grub_cryptodisk_t dev;
       char *diskname;
-      char *disklast;
+      char *disklast = NULL;
+      grub_size_t len;
 
       search_uuid = NULL;
       check_boot = state[2].set;
       diskname = args[0];
-      if (diskname[0] == '(' && *(disklast = &diskname[grub_strlen (diskname) - 1]) == ')')
+      len = grub_strlen (diskname);
+      if (len && diskname[0] == '(' && diskname[len - 1] == ')')
 	{
+	  disklast = &diskname[len - 1];
 	  *disklast = '\0';
-	  disk = grub_disk_open (diskname + 1);
-	  *disklast = ')';
+	  diskname++;
 	}
-      else
-	disk = grub_disk_open (diskname);
+
+      disk = grub_disk_open (diskname);
       if (!disk)
-	return grub_errno;
+	{
+	  if (disklast)
+	    *disklast = ')';
+	  return grub_errno;
+	}
 
       dev = grub_cryptodisk_get_by_source_disk (disk);
       if (dev)
 	{
 	  grub_dprintf ("cryptodisk", "already mounted as crypto%lu\n", dev->id);
 	  grub_disk_close (disk);
+	  if (disklast)
+	    *disklast = ')';
 	  return GRUB_ERR_NONE;
 	}
 
-      err = grub_cryptodisk_scan_device_real (args[0], disk);
+      err = grub_cryptodisk_scan_device_real (diskname, disk);
 
       grub_disk_close (disk);
+      if (disklast)
+	*disklast = ')';
 
       return err;
     }
-- 
2.6.6