All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: fstests@vger.kernel.org
Cc: Ext4 Developers List <linux-ext4@vger.kernel.org>,
	Theodore Ts'o <tytso@mit.edu>, Eric Sandeen <sandeen@redhat.com>
Subject: [PATCH] quota: fix generic/244 on 32-bit platforms
Date: Sun,  3 Jul 2016 20:11:56 -0400	[thread overview]
Message-ID: <1467591116-16880-1-git-send-email-tytso@mit.edu> (raw)

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>
Cc: Eric Sandeen <sandeen@redhat.com>
---
 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..6eec1f9 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 = (int) strtoul(optarg, &tmp, 0);
+			if (*tmp) {
+				fprintf(stderr, "Bad id: %s\n", optarg);
+				exit(1);
+			}
 			idflag++;
 			break;
 		case 'd':
-- 
2.5.0


             reply	other threads:[~2016-07-04  0:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-04  0:11 Theodore Ts'o [this message]
2016-07-04  5:26 ` [PATCH] quota: fix generic/244 on 32-bit platforms Eric Sandeen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1467591116-16880-1-git-send-email-tytso@mit.edu \
    --to=tytso@mit.edu \
    --cc=fstests@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=sandeen@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.