mirror of
https://git.code.sf.net/p/linux-ima/ima-evm-utils
synced 2025-04-28 14:43:37 +02:00
perform uuid format checking and error handling
Signed-off-by: Dmitry Kasatkin <d.kasatkin@samsung.com>
This commit is contained in:
parent
b3a5fcbca2
commit
2406322914
28
src/evmctl.c
28
src/evmctl.c
@ -636,10 +636,16 @@ static int hex_to_bin(char ch)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pack_uuid(const char *uuid_str, char *to)
|
static int pack_uuid(const char *uuid_str, char *uuid)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
char *to = uuid;
|
||||||
|
|
||||||
for (i = 0; i < 16; ++i) {
|
for (i = 0; i < 16; ++i) {
|
||||||
|
if (!uuid_str[0] || !uuid_str[1]) {
|
||||||
|
log_err("wrong UUID format\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
*to++ = (hex_to_bin(*uuid_str) << 4) |
|
*to++ = (hex_to_bin(*uuid_str) << 4) |
|
||||||
(hex_to_bin(*(uuid_str + 1)));
|
(hex_to_bin(*(uuid_str + 1)));
|
||||||
uuid_str += 2;
|
uuid_str += 2;
|
||||||
@ -648,10 +654,17 @@ static void pack_uuid(const char *uuid_str, char *to)
|
|||||||
case 5:
|
case 5:
|
||||||
case 7:
|
case 7:
|
||||||
case 9:
|
case 9:
|
||||||
|
if (*uuid_str != '-') {
|
||||||
|
log_err("wrong UUID format\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
uuid_str++;
|
uuid_str++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log_info("uuid: ");
|
||||||
|
log_dump(uuid, 16);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_uuid(struct stat *st, char *uuid)
|
static int get_uuid(struct stat *st, char *uuid)
|
||||||
@ -662,10 +675,8 @@ static int get_uuid(struct stat *st, char *uuid)
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
if (uuid_str[0] != '-') {
|
if (uuid_str[0] != '-')
|
||||||
pack_uuid(uuid_str, uuid);
|
return pack_uuid(uuid_str, uuid);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
dev = st->st_dev;
|
dev = st->st_dev;
|
||||||
major = (dev & 0xfff00) >> 8;
|
major = (dev & 0xfff00) >> 8;
|
||||||
@ -687,12 +698,7 @@ static int get_uuid(struct stat *st, char *uuid)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pack_uuid(_uuid, uuid);
|
return pack_uuid(_uuid, uuid);
|
||||||
|
|
||||||
log_info("uuid: ");
|
|
||||||
log_dump(uuid, 16);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int calc_evm_hash(const char *file, unsigned char *hash)
|
static int calc_evm_hash(const char *file, unsigned char *hash)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user