For --block-size, check for strtoul() reporting an overflow.
For --inode-number, check for strtoull() reporting an overflow.
Also, move the check for 32-bit inode numbers into a more logical place
(the place where we check the encryption format-specific limitations).
Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Daeho Jeong <daeho43@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
#include <linux/types.h>
#include <stdarg.h>
#include <stdbool.h>
#include <linux/types.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-static u32 parse_inode_number(const char *arg)
-{
- char *tmp;
- unsigned long long num = strtoull(arg, &tmp, 10);
-
- if (num <= 0 || *tmp)
- die("Invalid inode number: %s", arg);
- if ((u32)num != num)
- die("Inode number %s is too large; must be 32-bit", arg);
- return num;
-}
-
struct key_and_iv_params {
u8 master_key[MAX_KEY_SIZE];
int master_key_size;
struct key_and_iv_params {
u8 master_key[MAX_KEY_SIZE];
int master_key_size;
bool file_nonce_specified;
bool iv_ino_lblk_64;
bool iv_ino_lblk_32;
bool file_nonce_specified;
bool iv_ino_lblk_64;
bool iv_ino_lblk_32;
u8 fs_uuid[UUID_SIZE];
bool fs_uuid_specified;
};
u8 fs_uuid[UUID_SIZE];
bool fs_uuid_specified;
};
die("%s requires --inode-number", opt);
if (params->mode_num == 0)
die("%s requires --mode-num", opt);
die("%s requires --inode-number", opt);
if (params->mode_num == 0)
die("%s requires --mode-num", opt);
+ if (params->inode_number > UINT32_MAX)
+ die("%s can't use --inode-number > UINT32_MAX", opt);
while ((c = getopt_long(argc, argv, "", longopts, NULL)) != -1) {
switch (c) {
case OPT_BLOCK_SIZE:
while ((c = getopt_long(argc, argv, "", longopts, NULL)) != -1) {
switch (c) {
case OPT_BLOCK_SIZE:
block_size = strtoul(optarg, &tmp, 10);
block_size = strtoul(optarg, &tmp, 10);
- if (block_size <= 0 || *tmp)
+ if (block_size <= 0 || *tmp || errno)
die("Invalid block size: %s", optarg);
break;
case OPT_DECRYPT:
die("Invalid block size: %s", optarg);
break;
case OPT_DECRYPT:
usage(stdout);
return 0;
case OPT_INODE_NUMBER:
usage(stdout);
return 0;
case OPT_INODE_NUMBER:
- params.inode_number = parse_inode_number(optarg);
+ errno = 0;
+ params.inode_number = strtoull(optarg, &tmp, 10);
+ if (params.inode_number <= 0 || *tmp || errno)
+ die("Invalid inode number: %s", optarg);
break;
case OPT_IV_INO_LBLK_32:
params.iv_ino_lblk_32 = true;
break;
case OPT_IV_INO_LBLK_32:
params.iv_ino_lblk_32 = true;