summaryrefslogtreecommitdiff
path: root/sbin/newfs_ext2fs/newfs_ext2fs.c
diff options
context:
space:
mode:
authorTobias Stoeckmann <tobias@cvs.openbsd.org>2015-12-06 11:56:48 +0000
committerTobias Stoeckmann <tobias@cvs.openbsd.org>2015-12-06 11:56:48 +0000
commite33812ae9ddd39e9387b8268ca681862956458ac (patch)
tree4acc80c03b6a8d6e321fcf9a93c214c9bd15a255 /sbin/newfs_ext2fs/newfs_ext2fs.c
parentb095fb7e1edec6a0c0c876105f8dadceb13cf36e (diff)
Avoid out of boundary access on illegal command line arguments.
ok deraadt, mmcc, tedu
Diffstat (limited to 'sbin/newfs_ext2fs/newfs_ext2fs.c')
-rw-r--r--sbin/newfs_ext2fs/newfs_ext2fs.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/sbin/newfs_ext2fs/newfs_ext2fs.c b/sbin/newfs_ext2fs/newfs_ext2fs.c
index 079774e14ad..e217c386f43 100644
--- a/sbin/newfs_ext2fs/newfs_ext2fs.c
+++ b/sbin/newfs_ext2fs/newfs_ext2fs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: newfs_ext2fs.c,v 1.21 2015/11/28 06:12:09 deraadt Exp $ */
+/* $OpenBSD: newfs_ext2fs.c,v 1.22 2015/12/06 11:56:47 tobias Exp $ */
/* $NetBSD: newfs_ext2fs.c,v 1.8 2009/03/02 10:38:13 tsutsui Exp $ */
/*
@@ -529,9 +529,11 @@ getpartition(int fsi, const char *special, char *argv[], struct disklabel **dl)
errx(EXIT_FAILURE, "%s: block device", special);
if (!S_ISCHR(st.st_mode))
warnx("%s: not a character-special device", special);
- cp = strchr(argv[0], '\0') - 1;
- if (cp == NULL || ((*cp < 'a' || *cp > ('a' + getmaxpartitions() - 1))
- && !isdigit((unsigned char)*cp)))
+ if (*argv[0] == '\0')
+ errx(EXIT_FAILURE, "empty partition name supplied");
+ cp = argv[0] + strlen(argv[0]) - 1;
+ if ((*cp < 'a' || *cp > ('a' + getmaxpartitions() - 1))
+ && !isdigit((unsigned char)*cp))
errx(EXIT_FAILURE, "%s: can't figure out file system partition", argv[0]);
lp = getdisklabel(special, fsi);
if (isdigit((unsigned char)*cp))