1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-27 18:55:19 +03:00

Ensure more args aren't negative.

This commit is contained in:
Alasdair Kergon 2003-09-15 15:04:39 +00:00
parent d0afc2c8b7
commit fdd4f3c005
5 changed files with 44 additions and 3 deletions

View File

@ -148,12 +148,22 @@ static int _read_size_params(struct lvcreate_params *lp,
return 0;
}
if (arg_count(cmd, extents_ARG))
if (arg_count(cmd, extents_ARG)) {
if (arg_sign_value(cmd, extents_ARG, 0) == SIGN_MINUS) {
log_error("Negative number of extents is invalid");
return 0;
}
lp->extents = arg_uint_value(cmd, extents_ARG, 0);
}
/* Size returned in kilobyte units; held in sectors */
if (arg_count(cmd, size_ARG))
if (arg_count(cmd, size_ARG)) {
if (arg_sign_value(cmd, size_ARG, 0) == SIGN_MINUS) {
log_error("Negative size is invalid");
return 0;
}
lp->size = arg_uint64_value(cmd, size_ARG, UINT64_C(0)) * 2;
}
return 1;
}
@ -172,8 +182,13 @@ static int _read_stripe_params(struct lvcreate_params *lp,
log_print("Redundant stripes argument: default is 1");
}
if (arg_count(cmd, stripesize_ARG))
if (arg_count(cmd, stripesize_ARG)) {
if (arg_sign_value(cmd, stripesize_ARG, 0) == SIGN_MINUS) {
log_error("Negative stripesize is invalid");
return 0;
}
lp->stripe_size = 2 * arg_uint_value(cmd, stripesize_ARG, 0);
}
if (lp->stripes == 1 && lp->stripe_size) {
log_print("Ignoring stripesize argument with single stripe");
@ -222,6 +237,10 @@ static int _read_params(struct lvcreate_params *lp, struct cmd_context *cmd,
log_error("-s and -Z are incompatible");
return 0;
}
if (arg_sign_value(cmd, chunksize_ARG, 0) == SIGN_MINUS) {
log_error("Negative chunk size is invalid");
return 0;
}
lp->chunk_size = 2 * arg_uint_value(cmd, chunksize_ARG, 8);
log_verbose("Setting chunksize to %d sectors.", lp->chunk_size);
} else {

View File

@ -133,6 +133,10 @@ int lvresize(struct cmd_context *cmd, int argc, char **argv)
}
if (arg_count(cmd, stripesize_ARG)) {
if (arg_sign_value(cmd, stripesize_ARG, 0) == SIGN_MINUS) {
log_error("Stripesize may not be negative.");
goto error;
}
if (vg->fid->fmt->features & FMT_SEGMENTS)
ssize = 2 * arg_uint_value(cmd, stripesize_ARG, 0);
else

View File

@ -130,8 +130,16 @@ static void pvcreate_single(struct cmd_context *cmd, const char *pv_name,
if (!pvcreate_check(cmd, pv_name))
goto error;
if (arg_sign_value(cmd, physicalvolumesize_ARG, 0) == SIGN_MINUS) {
log_error("Physical volume size may not be negative");
goto error;
}
size = arg_uint64_value(cmd, physicalvolumesize_ARG, UINT64_C(0)) * 2;
if (arg_sign_value(cmd, metadatasize_ARG, 0) == SIGN_MINUS) {
log_error("Metadata size may not be negative");
goto error;
}
pvmetadatasize = arg_uint64_value(cmd, metadatasize_ARG, UINT64_C(0))
* 2;
if (!pvmetadatasize)

View File

@ -62,6 +62,11 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
}
if (cmd->fmt->features & FMT_MDAS) {
if (arg_sign_value(cmd, metadatasize_ARG, 0) == SIGN_MINUS) {
log_error("Metadata size may not be negative");
return EINVALID_CMD_LINE;
}
pvmetadatasize = arg_uint64_value(cmd, metadatasize_ARG,
UINT64_C(0)) * 2;
if (!pvmetadatasize)

View File

@ -49,6 +49,11 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
max_lv = arg_uint_value(cmd, maxlogicalvolumes_ARG, DEFAULT_LV);
max_pv = arg_uint_value(cmd, maxphysicalvolumes_ARG, DEFAULT_PV);
if (arg_sign_value(cmd, physicalextentsize_ARG, 0) == SIGN_MINUS) {
log_error("Physical extent size may not be negative");
return EINVALID_CMD_LINE;
}
/* Units of 512-byte sectors */
extent_size =
arg_uint_value(cmd, physicalextentsize_ARG, DEFAULT_EXTENT) * 2;