mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

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

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