Skip to content

Commit c4c6946

Browse files
committed
CA-342553: don't try to read encryption key from raw parent
Signed-off-by: Mark Syms <mark.syms@citrix.com>
1 parent 04e38d1 commit c4c6946

2 files changed

Lines changed: 29 additions & 15 deletions

File tree

mockatests/vhd/test-vhd-util-snapshot.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
#include "libvhd.h"
3939
#include "vhd-wrappers.h"
4040

41-
#define ARGS_SIZE 9
41+
#define RAW_PRT_ARGS_SIZE 9
4242

43-
char* args[ARGS_SIZE] = {
43+
char* raw_prt_args[RAW_PRT_ARGS_SIZE] = {
4444
"--debug",
4545
"-n",
4646
"test1.vhdcache",
@@ -51,6 +51,18 @@ char* args[ARGS_SIZE] = {
5151
"-e",
5252
"-m"};
5353

54+
#define ARGS_SIZE 8
55+
56+
char* args[ARGS_SIZE] = {
57+
"--debug",
58+
"-n",
59+
"test1.vhdcache",
60+
"-p",
61+
"test2.vhdcache",
62+
"-S",
63+
"71680",
64+
"-e"};
65+
5466
/*
5567
* Tests to ensure errors are propagated by vhd-util-snapshot.
5668
*/
@@ -59,7 +71,7 @@ void test_vhd_util_snapshot_enospc_from_vhd_snapshot(void **state)
5971
will_return(__wrap_canonpath, "testing");
6072
will_return(__wrap_vhd_snapshot, ENOSPC);
6173
expect_any(__wrap_free, in);
62-
int res = vhd_util_snapshot(ARGS_SIZE, args);
74+
int res = vhd_util_snapshot(RAW_PRT_ARGS_SIZE, raw_prt_args);
6375
assert_int_equal(get_close_count(), 0);
6476
assert_int_equal(res, ENOSPC);
6577
}

vhd/lib/vhd-util-snapshot.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,21 +226,23 @@ vhd_util_snapshot(int argc, char **argv)
226226
if(err)
227227
goto out;
228228

229-
/* Set keyhash if it exists in parent */
230-
struct vhd_keyhash vhdhash;
231-
err = vhd_open(&vhd, backing, VHD_OPEN_RDONLY);
232-
if(err)
233-
goto out;
234-
err = vhd_get_keyhash(&vhd, &vhdhash);
235-
vhd_close(&vhd);
236-
if(err)
237-
goto out;
238-
if (vhdhash.cookie == 1){
239-
err = vhd_open(&vhd, name, VHD_OPEN_RDWR);
229+
if (!vhd_flag_test(flags, VHD_FLAG_CREAT_PARENT_RAW)) {
230+
/* Set keyhash if it exists in parent */
231+
struct vhd_keyhash vhdhash;
232+
err = vhd_open(&vhd, backing, VHD_OPEN_RDONLY);
240233
if(err)
241234
goto out;
242-
err = vhd_set_keyhash(&vhd, &vhdhash);
235+
err = vhd_get_keyhash(&vhd, &vhdhash);
243236
vhd_close(&vhd);
237+
if(err)
238+
goto out;
239+
if (vhdhash.cookie == 1){
240+
err = vhd_open(&vhd, name, VHD_OPEN_RDWR);
241+
if(err)
242+
goto out;
243+
err = vhd_set_keyhash(&vhd, &vhdhash);
244+
vhd_close(&vhd);
245+
}
244246
}
245247

246248
out:

0 commit comments

Comments
 (0)