linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -v2] quota: fix generic/244 on 32-bit platforms
@ 2016-07-04 14:09 Theodore Ts'o
  0 siblings, 0 replies; only message in thread
From: Theodore Ts'o @ 2016-07-04 14:09 UTC (permalink / raw)
  To: fstests; +Cc: sandeen, Ext4 Developers List, Theodore Ts'o

The test program src/test-nextquota.c relies on atoi() to convert a
string to an *unsigned* int.  If the string represents an integer
which is greater than INT_MAX, it is undefined how atoi(3) works, and
it turns out that:

       uint id = atoi("2147483649");

results in id == 2147483649 on x86_64, and id == 2147483647 on a
32-bit x86 platform.

So use strtoul(3) instead, which is portable and technically correct.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
---

v2: cast to uint instead of int

 src/test-nextquota.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/test-nextquota.c b/src/test-nextquota.c
index a2bbad9..3baa296 100644
--- a/src/test-nextquota.c
+++ b/src/test-nextquota.c
@@ -74,6 +74,7 @@ int main(int argc, char *argv[])
 	int verbose = 0;
 	uint id = 0, idflag = 0;
 	char *device = NULL;
+	char *tmp;
 	struct nextdqblk dqb;
 	struct fs_disk_quota xqb;
 
@@ -92,7 +93,11 @@ int main(int argc, char *argv[])
 			typeflag++;
 			break;
 		case 'i':
-			id = atoi(optarg);
+			id = (uint) strtoul(optarg, &tmp, 0);
+			if (*tmp) {
+				fprintf(stderr, "Bad id: %s\n", optarg);
+				exit(1);
+			}
 			idflag++;
 			break;
 		case 'd':
-- 
2.5.0

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-07-04 14:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-04 14:09 [PATCH -v2] quota: fix generic/244 on 32-bit platforms Theodore Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).