mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0044-options-Fix-segfault-when-multiple-key-parameters-gi.patch

498672
From a7fe83c678520aca2289eab2af6d8aebdf225bb7 Mon Sep 17 00:00:00 2001
10436e
From: "Richard W.M. Jones" <rjones@redhat.com>
10436e
Date: Tue, 12 Nov 2019 18:15:44 +0000
10436e
Subject: [PATCH] options: Fix segfault when multiple --key parameters given.
10436e
10436e
Easily reproducible using:
10436e
10436e
  $ guestfish --key dev1:key:key1 --key dev2:key:key2
10436e
10436e
causing this stack trace (or others depending on where the memory
10436e
corruption was caught):
10436e
10436e
  Program received signal SIGABRT, Aborted.
10436e
  0x00007ffff7905625 in raise () from /lib64/libc.so.6
10436e
  (gdb) bt
10436e
  #0  0x00007ffff7905625 in raise () from /lib64/libc.so.6
10436e
  #1  0x00007ffff78ee8d9 in abort () from /lib64/libc.so.6
10436e
  #2  0x00007ffff79494af in __libc_message () from /lib64/libc.so.6
10436e
  #3  0x00007ffff7950a6c in malloc_printerr () from /lib64/libc.so.6
10436e
  #4  0x00007ffff79528d0 in _int_free () from /lib64/libc.so.6
10436e
  #5  0x00005555555bdd6e in free_key_store ()
10436e
  #6  0x0000555555589027 in main ()
10436e
  (gdb) quit
10436e
10436e
(cherry picked from commit 8c42f772614b44a8cb974afa904ec9f518431ab2
10436e
in libguestfs-common)
10436e
---
10436e
 common/options/keys.c | 3 ++-
10436e
 1 file changed, 2 insertions(+), 1 deletion(-)
10436e
10436e
diff --git a/common/options/keys.c b/common/options/keys.c
10436e
index 7f689866b..f783066ff 100644
10436e
--- a/common/options/keys.c
10436e
+++ b/common/options/keys.c
10436e
@@ -216,7 +216,8 @@ key_store_import_key (struct key_store *ks, const struct key_store_key *key)
10436e
   }
10436e
   assert (ks != NULL);
10436e
 
10436e
-  new_keys = realloc (ks->keys, sizeof (*ks->keys) + 1);
10436e
+  new_keys = realloc (ks->keys,
10436e
+                      (ks->nr_keys + 1) * sizeof (struct key_store_key));
10436e
   if (!new_keys)
10436e
     error (EXIT_FAILURE, errno, "realloc");
10436e
 
10436e
-- 
498672
2.18.4
10436e