| To: | xfs-oss <xfs@xxxxxxxxxxx> |
|---|---|
| Subject: | [PATCH] xfs_io: don't assign cvtnum() return to unsigned var |
| From: | Eric Sandeen <sandeen@xxxxxxxxxxx> |
| Date: | Wed, 02 Dec 2009 12:19:54 -0600 |
| User-agent: | Thunderbird 2.0.0.23 (Macintosh/20090812) |
cvtnum() returns -1LL for unparseable values, but if we
assign to a signed var, we can't test it:
xfs_io> mincore 0 xxx
range (0:0) is beyond mapping (0:1048576)
Use a temporary signed var so we can detect the error:
xfs_io> mincore 0 xxx
non-numeric length argument -- xxx
and also test whether it may overflow a size_t.
Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxxx>
---
diff --git a/io/mincore.c b/io/mincore.c
index f863f84..d534540 100644
--- a/io/mincore.c
+++ b/io/mincore.c
@@ -30,7 +30,7 @@ mincore_f(
int argc,
char **argv)
{
- off64_t offset;
+ off64_t offset, llength;
size_t length;
size_t blocksize, sectsize;
void *start;
@@ -49,12 +49,17 @@ mincore_f(
argv[1]);
return 0;
}
- length = cvtnum(blocksize, sectsize, argv[2]);
- if (length < 0) {
+ llength = cvtnum(blocksize, sectsize, argv[2]);
+ if (llength < 0) {
printf(_("non-numeric length argument -- %s\n"),
argv[2]);
return 0;
- }
+ } else if (llength > (size_t)llength) {
+ printf(_("length argument too large -- %lld\n"),
+ llength);
+ return 0;
+ } else
+ length = (size_t)llength;
} else {
return command_usage(&mincore_cmd);
}
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | [PATCH] xfs_io: enable missing functions, Eric Sandeen |
|---|---|
| Next by Date: | [PATCH V2] xfs_io: don't assign cvtnum() return to unsigned var, Eric Sandeen |
| Previous by Thread: | [PATCH] xfs_io: enable missing functions, Eric Sandeen |
| Next by Thread: | [PATCH V2] xfs_io: don't assign cvtnum() return to unsigned var, Eric Sandeen |
| Indexes: | [Date] [Thread] [Top] [All Lists] |