1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-11 09:18:25 +03:00

Diagnose invalid PE values given on the pvmove command line (64-bit systems).

* tools/toollib.c (xstrtouint32): New function.
(_parse_pes): Use xstrtouint32; don't cast strtoul's unsigned
long to uint32_t.  Detect overflow.


Author: Jim Meyering <jim@meyering.net>
This commit is contained in:
Jim Meyering 2007-09-11 20:12:54 +00:00
parent 4ef1633969
commit d3380f41de
2 changed files with 15 additions and 4 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.29 - Version 2.02.29 -
================================== ==================================
Diagnose invalid PE values given on the pvmove command line (64-bit systems).
Include strerror string in dev_open_flags' stat failure message. Include strerror string in dev_open_flags' stat failure message.
Move guts of pvresize into library. Move guts of pvresize into library.
Avoid error when --corelog is provided without --mirrorlog. (2.02.28) Avoid error when --corelog is provided without --mirrorlog. (2.02.28)

View File

@ -911,6 +911,18 @@ static int _add_pe_range(struct dm_pool *mem, const char *pvname,
return 1; return 1;
} }
static int xstrtouint32(const char *s, char **p, int base, uint32_t *result)
{
unsigned long ul;
errno = 0;
ul = strtoul(s, p, base);
if (errno || *p == s || (uint32_t) ul != ul)
return -1;
*result = ul;
return 0;
}
static int _parse_pes(struct dm_pool *mem, char *c, struct list *pe_ranges, static int _parse_pes(struct dm_pool *mem, char *c, struct list *pe_ranges,
const char *pvname, uint32_t size) const char *pvname, uint32_t size)
{ {
@ -942,8 +954,7 @@ static int _parse_pes(struct dm_pool *mem, char *c, struct list *pe_ranges,
/* Start extent given? */ /* Start extent given? */
if (isdigit(*c)) { if (isdigit(*c)) {
start = (uint32_t) strtoul(c, &endptr, 10); if (xstrtouint32(c, &endptr, 10, &start))
if (endptr == c)
goto error; goto error;
c = endptr; c = endptr;
/* Just one number given? */ /* Just one number given? */
@ -954,8 +965,7 @@ static int _parse_pes(struct dm_pool *mem, char *c, struct list *pe_ranges,
if (*c == '-') { if (*c == '-') {
c++; c++;
if (isdigit(*c)) { if (isdigit(*c)) {
end = (uint32_t) strtoul(c, &endptr, 10); if (xstrtouint32(c, &endptr, 10, &end))
if (endptr == c)
goto error; goto error;
c = endptr; c = endptr;
} }