test-lm-gap.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */
  2. /*
  3. * Copyright (c) 2026 Red Hat, Inc.
  4. * Author: Sergio Correia <scorreia@redhat.com>
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 2.1 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include "test.h"
  20. #include "crc32c.h"
  21. #include <error.h>
  22. #include <errno.h>
  23. #include <fcntl.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <sys/stat.h>
  27. static const luksmeta_uuid_t UUID0 = {
  28. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
  29. 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11
  30. };
  31. static const luksmeta_uuid_t UUID1 = {
  32. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
  33. 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22
  34. };
  35. static const luksmeta_uuid_t UUID2 = {
  36. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33,
  37. 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33, 0x33
  38. };
  39. /* On-disk header layout; integer fields are stored in big-endian order. */
  40. typedef struct __attribute__((packed)) {
  41. luksmeta_uuid_t uuid;
  42. uint32_t offset;
  43. uint32_t length;
  44. uint32_t crc32c;
  45. uint32_t reserved;
  46. } test_slot_t;
  47. typedef struct __attribute__((packed)) {
  48. uint8_t magic[8];
  49. uint32_t version;
  50. uint32_t crc32c;
  51. test_slot_t slots[8];
  52. } test_header_t;
  53. /* Reset the filename template so mkstemp() in test_format() works on
  54. * each call. The existing tests only call test_format() once, but we
  55. * call it for every scenario. */
  56. static void
  57. reset_filename(void)
  58. {
  59. strcpy(filename, "/tmp/luksmetaXXXXXX");
  60. }
  61. /* Read a region of the image file into a freshly allocated buffer. */
  62. static uint8_t *
  63. read_image(size_t off, size_t len)
  64. {
  65. uint8_t *buf = NULL;
  66. int fd;
  67. buf = malloc(len);
  68. if (!buf)
  69. error(EXIT_FAILURE, errno, "%s:%d", __FILE__, __LINE__);
  70. fd = open(filename, O_RDONLY);
  71. if (fd < 0)
  72. error(EXIT_FAILURE, errno, "%s:%d", __FILE__, __LINE__);
  73. if (lseek(fd, off, SEEK_SET) == -1) {
  74. free(buf);
  75. close(fd);
  76. error(EXIT_FAILURE, errno, "%s:%d", __FILE__, __LINE__);
  77. }
  78. if (read(fd, buf, len) != (ssize_t) len) {
  79. free(buf);
  80. close(fd);
  81. error(EXIT_FAILURE, errno, "%s:%d", __FILE__, __LINE__);
  82. }
  83. close(fd);
  84. return buf;
  85. }
  86. /*
  87. * Bug 1 regression: occupied slot 0 shifts the hard limit, allowing a
  88. * save to write past the gap into the encrypted payload area.
  89. */
  90. static void
  91. test_bug1(void)
  92. {
  93. struct crypt_device *cd = NULL;
  94. luksmeta_uuid_t uuid = {};
  95. uint32_t offset = 0;
  96. uint32_t length = 0;
  97. uint8_t *before = NULL;
  98. uint8_t *after = NULL;
  99. uint8_t small[16];
  100. uint8_t *big = NULL;
  101. size_t capacity;
  102. int r;
  103. reset_filename();
  104. crypt_free(test_format());
  105. cd = test_init();
  106. test_hole(cd, &offset, &length);
  107. assert(length % 4096 == 0);
  108. assert(length >= 12288);
  109. /* Usable data area: gap minus the header page. */
  110. capacity = length - ALIGN(1, true);
  111. /* Fill small data with a known pattern. */
  112. memset(small, 'S', sizeof(small));
  113. /* Save a small entry in slot 0. */
  114. r = luksmeta_save(cd, 0, UUID0, small, sizeof(small));
  115. assert(r == 0);
  116. /* Seed the payload boundary so we can detect overwrites. */
  117. {
  118. int fd = open(filename, O_RDWR);
  119. uint8_t sentinel[4096];
  120. assert(fd >= 0);
  121. memset(sentinel, 'P', sizeof(sentinel));
  122. assert(lseek(fd, offset + length, SEEK_SET) != -1);
  123. assert(write(fd, sentinel, sizeof(sentinel)) == sizeof(sentinel));
  124. close(fd);
  125. }
  126. /* Snapshot the image before the rejected save. */
  127. before = read_image(offset, length + 4096);
  128. /* Attempt to save capacity bytes — must fail, slot 0 already occupies
  129. * space in the gap. */
  130. big = calloc(1, capacity);
  131. assert(big != NULL);
  132. memset(big, 'B', capacity);
  133. r = luksmeta_save(cd, 1, UUID1, big, capacity);
  134. assert(r == -ENOSPC);
  135. free(big);
  136. /* Image must be unchanged. */
  137. after = read_image(offset, length + 4096);
  138. assert(memcmp(before, after, length + 4096) == 0);
  139. free(before);
  140. free(after);
  141. /* Original entry still loads correctly. */
  142. {
  143. uint8_t out[sizeof(small)] = {};
  144. r = luksmeta_load(cd, 0, uuid, out, sizeof(out));
  145. assert(r == (int) sizeof(small));
  146. assert(memcmp(uuid, UUID0, sizeof(UUID0)) == 0);
  147. assert(memcmp(out, small, sizeof(small)) == 0);
  148. }
  149. /* Destination slot is still empty. */
  150. r = luksmeta_load(cd, 1, uuid, NULL, 0);
  151. assert(r == -ENODATA);
  152. crypt_free(cd);
  153. unlink(filename);
  154. }
  155. /*
  156. * Control: same sizes as Bug 1 but with the small entry in slot 1
  157. * instead of slot 0. Verifies the rejection is not slot-0-specific.
  158. */
  159. static void
  160. test_control(void)
  161. {
  162. struct crypt_device *cd = NULL;
  163. luksmeta_uuid_t uuid = {};
  164. uint32_t offset = 0;
  165. uint32_t length = 0;
  166. uint8_t *before = NULL;
  167. uint8_t *after = NULL;
  168. uint8_t small[16];
  169. uint8_t *big = NULL;
  170. size_t capacity;
  171. int r;
  172. reset_filename();
  173. crypt_free(test_format());
  174. cd = test_init();
  175. test_hole(cd, &offset, &length);
  176. capacity = length - ALIGN(1, true);
  177. memset(small, 'S', sizeof(small));
  178. /* Save a small entry in slot 1 (not slot 0). */
  179. r = luksmeta_save(cd, 1, UUID1, small, sizeof(small));
  180. assert(r == 1);
  181. /* Seed payload boundary. */
  182. {
  183. int fd = open(filename, O_RDWR);
  184. uint8_t sentinel[4096];
  185. assert(fd >= 0);
  186. memset(sentinel, 'P', sizeof(sentinel));
  187. assert(lseek(fd, offset + length, SEEK_SET) != -1);
  188. assert(write(fd, sentinel, sizeof(sentinel)) == sizeof(sentinel));
  189. close(fd);
  190. }
  191. before = read_image(offset, length + 4096);
  192. big = calloc(1, capacity);
  193. assert(big != NULL);
  194. memset(big, 'B', capacity);
  195. r = luksmeta_save(cd, 2, UUID2, big, capacity);
  196. assert(r == -ENOSPC);
  197. free(big);
  198. after = read_image(offset, length + 4096);
  199. assert(memcmp(before, after, length + 4096) == 0);
  200. free(before);
  201. free(after);
  202. /* Original entry still loads. */
  203. {
  204. uint8_t out[sizeof(small)] = {};
  205. r = luksmeta_load(cd, 1, uuid, out, sizeof(out));
  206. assert(r == (int) sizeof(small));
  207. assert(memcmp(uuid, UUID1, sizeof(UUID1)) == 0);
  208. assert(memcmp(out, small, sizeof(small)) == 0);
  209. }
  210. r = luksmeta_load(cd, 2, uuid, NULL, 0);
  211. assert(r == -ENODATA);
  212. crypt_free(cd);
  213. unlink(filename);
  214. }
  215. /*
  216. * Bug 2 regression: a new small entry whose candidate position falls
  217. * entirely inside an existing entry longer than two pages. The allocator
  218. * must skip the existing range and place the new entry after it.
  219. */
  220. static void
  221. test_bug2(void)
  222. {
  223. struct crypt_device *cd = NULL;
  224. luksmeta_uuid_t uuid = {};
  225. uint32_t offset = 0;
  226. uint32_t length = 0;
  227. uint8_t big[9000];
  228. uint8_t small[100];
  229. int r;
  230. reset_filename();
  231. crypt_free(test_format());
  232. cd = test_init();
  233. test_hole(cd, &offset, &length);
  234. /* Need room for the header page + 9000 bytes (3 aligned pages) +
  235. * the second entry (1 aligned page) = 5 pages minimum. */
  236. assert(length >= 24576);
  237. memset(big, 'A', sizeof(big));
  238. memset(small, 'X', sizeof(small));
  239. /* Slot 1: 9000 bytes, occupies gap-relative [4096, 13096). */
  240. r = luksmeta_save(cd, 1, UUID1, big, sizeof(big));
  241. assert(r == 1);
  242. /* Slot 2: 100 bytes. Must skip the existing range and succeed. */
  243. r = luksmeta_save(cd, 2, UUID2, small, sizeof(small));
  244. assert(r == 2);
  245. /* Both entries load with their original data. */
  246. {
  247. uint8_t out_big[sizeof(big)] = {};
  248. r = luksmeta_load(cd, 1, uuid, out_big, sizeof(out_big));
  249. assert(r == (int) sizeof(big));
  250. assert(memcmp(uuid, UUID1, sizeof(UUID1)) == 0);
  251. assert(memcmp(out_big, big, sizeof(big)) == 0);
  252. }
  253. {
  254. uint8_t out_small[sizeof(small)] = {};
  255. r = luksmeta_load(cd, 2, uuid, out_small, sizeof(out_small));
  256. assert(r == (int) sizeof(small));
  257. assert(memcmp(uuid, UUID2, sizeof(UUID2)) == 0);
  258. assert(memcmp(out_small, small, sizeof(small)) == 0);
  259. }
  260. crypt_free(cd);
  261. unlink(filename);
  262. }
  263. /*
  264. * Zero-length metadata: a zero-length entry coexists with a normal entry.
  265. */
  266. static void
  267. test_zero_length(void)
  268. {
  269. struct crypt_device *cd = NULL;
  270. luksmeta_uuid_t uuid = {};
  271. uint8_t dummy = 0;
  272. uint8_t normal[64];
  273. int r;
  274. reset_filename();
  275. crypt_free(test_format());
  276. cd = test_init();
  277. /* Save a zero-length entry. Use a non-NULL buffer to avoid UB. */
  278. r = luksmeta_save(cd, 0, UUID0, &dummy, 0);
  279. assert(r == 0);
  280. /* It loads back with length 0 and the correct UUID. */
  281. r = luksmeta_load(cd, 0, uuid, NULL, 0);
  282. assert(r == 0);
  283. assert(memcmp(uuid, UUID0, sizeof(UUID0)) == 0);
  284. /* Save a normal entry in the next slot. */
  285. memset(normal, 'N', sizeof(normal));
  286. r = luksmeta_save(cd, 1, UUID1, normal, sizeof(normal));
  287. assert(r == 1);
  288. /* Both coexist: zero-length still loads. */
  289. memset(uuid, 0, sizeof(uuid));
  290. r = luksmeta_load(cd, 0, uuid, NULL, 0);
  291. assert(r == 0);
  292. assert(memcmp(uuid, UUID0, sizeof(UUID0)) == 0);
  293. /* Normal entry loads with full contents. */
  294. {
  295. uint8_t out[sizeof(normal)] = {};
  296. r = luksmeta_load(cd, 1, uuid, out, sizeof(out));
  297. assert(r == (int) sizeof(normal));
  298. assert(memcmp(uuid, UUID1, sizeof(UUID1)) == 0);
  299. assert(memcmp(out, normal, sizeof(normal)) == 0);
  300. }
  301. crypt_free(cd);
  302. unlink(filename);
  303. }
  304. /*
  305. * Exact-fit boundary: fill the entire usable data area.
  306. */
  307. static void
  308. test_exact_fit(void)
  309. {
  310. struct crypt_device *cd = NULL;
  311. luksmeta_uuid_t uuid = {};
  312. uint32_t offset = 0;
  313. uint32_t length = 0;
  314. size_t capacity;
  315. uint8_t *data = NULL;
  316. int r;
  317. reset_filename();
  318. crypt_free(test_format());
  319. cd = test_init();
  320. test_hole(cd, &offset, &length);
  321. assert(length % 4096 == 0);
  322. capacity = length - ALIGN(1, true);
  323. data = malloc(capacity);
  324. assert(data != NULL);
  325. memset(data, 'F', capacity);
  326. /* Save exactly capacity bytes — should succeed. */
  327. r = luksmeta_save(cd, 0, UUID0, data, capacity);
  328. assert(r == 0);
  329. /* Verify full readback. */
  330. {
  331. uint8_t *out = malloc(capacity);
  332. assert(out != NULL);
  333. r = luksmeta_load(cd, 0, uuid, out, capacity);
  334. assert(r == (int) capacity);
  335. assert(memcmp(uuid, UUID0, sizeof(UUID0)) == 0);
  336. assert(memcmp(out, data, capacity) == 0);
  337. free(out);
  338. }
  339. free(data);
  340. crypt_free(cd);
  341. unlink(filename);
  342. }
  343. /*
  344. * One byte over capacity: must be rejected without changing the image.
  345. */
  346. static void
  347. test_over_capacity(void)
  348. {
  349. struct crypt_device *cd = NULL;
  350. luksmeta_uuid_t uuid = {};
  351. uint32_t offset = 0;
  352. uint32_t length = 0;
  353. size_t capacity;
  354. uint8_t *data = NULL;
  355. uint8_t *before = NULL;
  356. uint8_t *after = NULL;
  357. int r;
  358. reset_filename();
  359. crypt_free(test_format());
  360. cd = test_init();
  361. test_hole(cd, &offset, &length);
  362. assert(length % 4096 == 0);
  363. capacity = length - ALIGN(1, true);
  364. data = calloc(1, capacity + 1);
  365. assert(data != NULL);
  366. memset(data, 'O', capacity + 1);
  367. before = read_image(offset, length);
  368. r = luksmeta_save(cd, 0, UUID0, data, capacity + 1);
  369. assert(r == -ENOSPC);
  370. free(data);
  371. after = read_image(offset, length);
  372. assert(memcmp(before, after, length) == 0);
  373. free(before);
  374. free(after);
  375. /* Slot remains empty. */
  376. r = luksmeta_load(cd, 0, uuid, NULL, 0);
  377. assert(r == -ENODATA);
  378. crypt_free(cd);
  379. unlink(filename);
  380. }
  381. /*
  382. * Adjacent allocation: second entry starts at the first's endpoint.
  383. */
  384. static void
  385. test_adjacent(void)
  386. {
  387. struct crypt_device *cd = NULL;
  388. luksmeta_uuid_t uuid = {};
  389. uint32_t offset = 0;
  390. uint32_t length = 0;
  391. uint8_t data0[4096];
  392. uint8_t data1[64];
  393. int r;
  394. reset_filename();
  395. crypt_free(test_format());
  396. cd = test_init();
  397. test_hole(cd, &offset, &length);
  398. memset(data0, 'A', sizeof(data0));
  399. memset(data1, 'B', sizeof(data1));
  400. /* First entry: exactly one aligned page. */
  401. r = luksmeta_save(cd, 0, UUID0, data0, sizeof(data0));
  402. assert(r == 0);
  403. /* Second entry: should start immediately after. */
  404. r = luksmeta_save(cd, 1, UUID1, data1, sizeof(data1));
  405. assert(r == 1);
  406. /* Both load correctly. */
  407. {
  408. uint8_t out[sizeof(data0)] = {};
  409. r = luksmeta_load(cd, 0, uuid, out, sizeof(out));
  410. assert(r == (int) sizeof(data0));
  411. assert(memcmp(uuid, UUID0, sizeof(UUID0)) == 0);
  412. assert(memcmp(out, data0, sizeof(data0)) == 0);
  413. }
  414. {
  415. uint8_t out[sizeof(data1)] = {};
  416. r = luksmeta_load(cd, 1, uuid, out, sizeof(out));
  417. assert(r == (int) sizeof(data1));
  418. assert(memcmp(uuid, UUID1, sizeof(UUID1)) == 0);
  419. assert(memcmp(out, data1, sizeof(data1)) == 0);
  420. }
  421. crypt_free(cd);
  422. unlink(filename);
  423. }
  424. /*
  425. * Space reuse: wipe an earlier entry, save a replacement into the freed
  426. * hole, and verify both the replacement and the untouched later entry.
  427. */
  428. static void
  429. test_reuse(void)
  430. {
  431. struct crypt_device *cd = NULL;
  432. luksmeta_uuid_t uuid = {};
  433. uint8_t data0[64];
  434. uint8_t data1[64];
  435. uint8_t data_new[64];
  436. int r;
  437. reset_filename();
  438. crypt_free(test_format());
  439. cd = test_init();
  440. memset(data0, 'A', sizeof(data0));
  441. memset(data1, 'B', sizeof(data1));
  442. memset(data_new, 'C', sizeof(data_new));
  443. /* Two entries. */
  444. r = luksmeta_save(cd, 0, UUID0, data0, sizeof(data0));
  445. assert(r == 0);
  446. r = luksmeta_save(cd, 1, UUID1, data1, sizeof(data1));
  447. assert(r == 1);
  448. /* Wipe the first. */
  449. assert(luksmeta_wipe(cd, 0, UUID0) == 0);
  450. /* Save a replacement into the freed slot. */
  451. r = luksmeta_save(cd, 0, UUID2, data_new, sizeof(data_new));
  452. assert(r == 0);
  453. /* Replacement loads correctly. */
  454. {
  455. uint8_t out[sizeof(data_new)] = {};
  456. r = luksmeta_load(cd, 0, uuid, out, sizeof(out));
  457. assert(r == (int) sizeof(data_new));
  458. assert(memcmp(uuid, UUID2, sizeof(UUID2)) == 0);
  459. assert(memcmp(out, data_new, sizeof(data_new)) == 0);
  460. }
  461. /* Later entry is untouched. */
  462. {
  463. uint8_t out[sizeof(data1)] = {};
  464. r = luksmeta_load(cd, 1, uuid, out, sizeof(out));
  465. assert(r == (int) sizeof(data1));
  466. assert(memcmp(uuid, UUID1, sizeof(UUID1)) == 0);
  467. assert(memcmp(out, data1, sizeof(data1)) == 0);
  468. }
  469. crypt_free(cd);
  470. unlink(filename);
  471. }
  472. /* Rewrite a header with a valid checksum after changing a slot range. */
  473. static void
  474. rewrite_header(uint32_t offset, test_header_t header)
  475. {
  476. int fd = open(filename, O_RDWR);
  477. assert(fd >= 0);
  478. header.crc32c = 0;
  479. header.crc32c = htobe32(crc32c(0, &header, sizeof(header)));
  480. assert(lseek(fd, offset, SEEK_SET) != -1);
  481. assert(write(fd, &header, sizeof(header)) == sizeof(header));
  482. assert(close(fd) == 0);
  483. }
  484. /* A checksum-valid occupied slot must not direct I/O outside the gap. */
  485. static void
  486. test_invalid_range(int scenario)
  487. {
  488. struct crypt_device *cd = NULL;
  489. luksmeta_uuid_t uuid = {};
  490. test_header_t header;
  491. struct stat before_stat, after_stat;
  492. uint32_t offset = 0;
  493. uint32_t length = 0;
  494. uint32_t slot_offset;
  495. uint8_t data[16];
  496. uint8_t sentinel[4096];
  497. uint8_t *before, *after;
  498. int fd;
  499. reset_filename();
  500. crypt_free(test_format());
  501. cd = test_init();
  502. test_hole(cd, &offset, &length);
  503. assert(length >= 12288);
  504. assert(sizeof(data) <= length - ALIGN(sizeof(header), true));
  505. memset(data, 'D', sizeof(data));
  506. assert(luksmeta_save(cd, 0, UUID0, data, sizeof(data)) == 0);
  507. fd = open(filename, O_RDWR);
  508. assert(fd >= 0);
  509. assert(lseek(fd, offset, SEEK_SET) != -1);
  510. assert(read(fd, &header, sizeof(header)) == sizeof(header));
  511. memset(sentinel, 'P', sizeof(sentinel));
  512. assert(lseek(fd, (off_t) offset + length, SEEK_SET) != -1);
  513. assert(write(fd, sentinel, sizeof(sentinel)) == sizeof(sentinel));
  514. assert(close(fd) == 0);
  515. /* Prove the mutation/checksum helper produces an accepted header. */
  516. header.slots[0].offset = htobe32(length - sizeof(data));
  517. rewrite_header(offset, header);
  518. assert(luksmeta_test(cd) == 0);
  519. assert(luksmeta_load(cd, 0, uuid, NULL, 0) == sizeof(data));
  520. /* Inside-but-crossing, at the boundary, and a wrapping endpoint. */
  521. slot_offset = scenario == 0 ? length - 1 :
  522. scenario == 1 ? length : UINT32_MAX - 7;
  523. assert(slot_offset > sizeof(header));
  524. assert((uint64_t) slot_offset + sizeof(data) > length);
  525. if (scenario == 2)
  526. assert((uint64_t) slot_offset + sizeof(data) > UINT32_MAX);
  527. header.slots[0].offset = htobe32(slot_offset);
  528. rewrite_header(offset, header);
  529. assert(stat(filename, &before_stat) == 0);
  530. before = read_image(0, before_stat.st_size);
  531. /* Validation must reject the header even without seeking to slot data. */
  532. assert(luksmeta_test(cd) == -EINVAL);
  533. assert(luksmeta_load(cd, 0, uuid, NULL, 0) == -EINVAL);
  534. assert(luksmeta_load(cd, 0, uuid, data, sizeof(data)) == -EINVAL);
  535. assert(luksmeta_save(cd, 1, UUID1, data, sizeof(data)) == -EINVAL);
  536. assert(luksmeta_wipe(cd, 0, UUID0) == -EINVAL);
  537. assert(stat(filename, &after_stat) == 0);
  538. assert(after_stat.st_size == before_stat.st_size);
  539. after = read_image(0, after_stat.st_size);
  540. assert(memcmp(before, after, before_stat.st_size) == 0);
  541. free(before);
  542. free(after);
  543. crypt_free(cd);
  544. unlink(filename);
  545. }
  546. int
  547. main(int argc, char *argv[])
  548. {
  549. test_invalid_range(0);
  550. test_invalid_range(1);
  551. test_invalid_range(2);
  552. test_bug1();
  553. test_control();
  554. test_bug2();
  555. test_zero_length();
  556. test_exact_fit();
  557. test_over_capacity();
  558. test_adjacent();
  559. test_reuse();
  560. return 0;
  561. }