Skip to content

Commit

Permalink
fix(skipcpio): calculate and use CPIO_MAGIC_LEN
Browse files Browse the repository at this point in the history
Signed-off-by: Shreenidhi Shedi <sshedi@vmware.com>
  • Loading branch information
sshedi authored and johannbg committed Aug 27, 2021
1 parent f6d16b6 commit 3fb8723
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/skipcpio/skipcpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <string.h>

#define CPIO_MAGIC "070701"
#define CPIO_MAGIC_LEN (sizeof(CPIO_MAGIC) - 1)

#define CPIO_END "TRAILER!!!"
#define CPIO_ENDLEN (sizeof(CPIO_END) - 1)
Expand All @@ -41,7 +42,7 @@
__func__, ##__VA_ARGS__)

struct cpio_header {
char c_magic[6];
char c_magic[CPIO_MAGIC_LEN];
char c_ino[8];
char c_mode[8];
char c_uid[8];
Expand Down Expand Up @@ -103,7 +104,7 @@ int main(int argc, char **argv)
}

/* check, if this is a cpio archive */
if (memcmp(buf.cpio.h.c_magic, CPIO_MAGIC, 6)) {
if (memcmp(buf.cpio.h.c_magic, CPIO_MAGIC, CPIO_MAGIC_LEN)) {
goto cat_rest;
}

Expand Down Expand Up @@ -138,7 +139,7 @@ int main(int argc, char **argv)
goto end;
}

if (memcmp(buf.cpio.h.c_magic, CPIO_MAGIC, 6)) {
if (memcmp(buf.cpio.h.c_magic, CPIO_MAGIC, CPIO_MAGIC_LEN)) {
pr_err("Corrupt CPIO archive!\n");
goto end;
}
Expand Down

0 comments on commit 3fb8723

Please sign in to comment.