Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/gpt Check device parameter to avoid segfaults. Agument ...
details: https://anonhg.NetBSD.org/src/rev/c966e119ea78
branches: trunk
changeset: 321505:c966e119ea78
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Mon Mar 19 09:06:20 2018 +0000
description:
Check device parameter to avoid segfaults. Agument synopsis for -l option.
diffstat:
sbin/gpt/gpt.8 | 11 ++++++++++-
sbin/gpt/gpt.h | 1 +
sbin/gpt/main.c | 7 +++++--
sbin/gpt/set.c | 10 +++++-----
sbin/gpt/type.c | 10 +++++-----
sbin/gpt/unset.c | 11 ++++++-----
6 files changed, 32 insertions(+), 18 deletions(-)
diffs (201 lines):
diff -r 9eb25d4dae54 -r c966e119ea78 sbin/gpt/gpt.8
--- a/sbin/gpt/gpt.8 Mon Mar 19 08:57:57 2018 +0000
+++ b/sbin/gpt/gpt.8 Mon Mar 19 09:06:20 2018 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.57 2018/01/15 12:20:47 sborrill Exp $
+.\" $NetBSD: gpt.8,v 1.58 2018/03/19 09:06:20 mlelstv Exp $
.\"
.\" Copyright (c) 2002 Marcel Moolenaar
.\" All rights reserved.
@@ -41,6 +41,15 @@
.Ar command
.Op Ar command_options
.Ar device
+.Nm
+.Ar set
+.Fl l
+.Nm
+.Ar unset
+.Fl l
+.Nm
+.Ar type
+.Fl l
.Sh DESCRIPTION
The
.Nm
diff -r 9eb25d4dae54 -r c966e119ea78 sbin/gpt/gpt.h
--- a/sbin/gpt/gpt.h Mon Mar 19 08:57:57 2018 +0000
+++ b/sbin/gpt/gpt.h Mon Mar 19 09:06:20 2018 +0000
@@ -81,6 +81,7 @@
#define GPT_NOSYNC 0x08
#define GPT_FILE 0x10
#define GPT_TIMESTAMP 0x20
+#define GPT_OPTDEV 0x8000
void* gpt_read(gpt_t, off_t, size_t);
off_t gpt_last(gpt_t);
diff -r 9eb25d4dae54 -r c966e119ea78 sbin/gpt/main.c
--- a/sbin/gpt/main.c Mon Mar 19 08:57:57 2018 +0000
+++ b/sbin/gpt/main.c Mon Mar 19 09:06:20 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.10 2017/02/16 22:40:19 christos Exp $ */
+/* $NetBSD: main.c,v 1.11 2018/03/19 09:06:20 mlelstv Exp $ */
/*-
* Copyright (c) 2002 Marcel Moolenaar
@@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#ifdef __RCSID
-__RCSID("$NetBSD: main.c,v 1.10 2017/02/16 22:40:19 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.11 2018/03/19 09:06:20 mlelstv Exp $");
#endif
#include <stdio.h>
@@ -241,6 +241,9 @@
if (gpt == NULL)
return EXIT_FAILURE;
} else {
+ if ((cmdsw[i]->flags & GPT_OPTDEV) == 0)
+ errx(EXIT_FAILURE,
+ "Command %s needs a device parameter", cmd);
argc++;
gpt = NULL;
}
diff -r 9eb25d4dae54 -r c966e119ea78 sbin/gpt/set.c
--- a/sbin/gpt/set.c Mon Mar 19 08:57:57 2018 +0000
+++ b/sbin/gpt/set.c Mon Mar 19 09:06:20 2018 +0000
@@ -33,7 +33,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: set.c,v 1.13 2015/12/29 16:45:04 christos Exp $");
+__RCSID("$NetBSD: set.c,v 1.14 2018/03/19 09:06:20 mlelstv Exp $");
#endif
#include <sys/types.h>
@@ -60,7 +60,7 @@
"set",
cmd_set,
sethelp, __arraycount(sethelp),
- 0,
+ GPT_OPTDEV,
};
#define usage() gpt_usage(NULL, &c_set)
@@ -75,11 +75,11 @@
while ((ch = getopt(argc, argv, "a:i:l")) != -1) {
switch(ch) {
case 'a':
- if (gpt_attr_get(gpt, &attributes) == -1)
+ if (gpt == NULL || gpt_attr_get(gpt, &attributes) == -1)
return usage();
break;
case 'i':
- if (gpt_uint_get(gpt, &entry) == -1)
+ if (gpt == NULL || gpt_uint_get(gpt, &entry) == -1)
return usage();
break;
case 'l':
@@ -90,7 +90,7 @@
}
}
- if (argc != optind)
+ if (gpt == NULL || argc != optind)
return usage();
return gpt_attr_update(gpt, entry, attributes, 0);
diff -r 9eb25d4dae54 -r c966e119ea78 sbin/gpt/type.c
--- a/sbin/gpt/type.c Mon Mar 19 08:57:57 2018 +0000
+++ b/sbin/gpt/type.c Mon Mar 19 09:06:20 2018 +0000
@@ -33,7 +33,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/remove.c,v 1.10 2006/10/04 18:20:25 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: type.c,v 1.13 2015/12/06 00:39:26 christos Exp $");
+__RCSID("$NetBSD: type.c,v 1.14 2018/03/19 09:06:20 mlelstv Exp $");
#endif
#include <sys/types.h>
@@ -61,7 +61,7 @@
"type",
cmd_type,
typehelp, __arraycount(typehelp),
- 0,
+ GPT_OPTDEV,
};
#define usage() gpt_usage(NULL, &c_type)
@@ -91,17 +91,17 @@
gpt_uuid_help("\t");
return 0;
case 'T':
- if (gpt_uuid_get(gpt, &newtype) == -1)
+ if (gpt == NULL || gpt_uuid_get(gpt, &newtype) == -1)
return -1;
break;
default:
- if (gpt_add_find(gpt, &find, ch) == -1)
+ if (gpt == NULL || gpt_add_find(gpt, &find, ch) == -1)
return usage();
break;
}
}
- if (gpt_uuid_is_nil(newtype) || argc != optind)
+ if (gpt == NULL || gpt_uuid_is_nil(newtype) || argc != optind)
return usage();
return gpt_change_ent(gpt, &find, change, &newtype);
diff -r 9eb25d4dae54 -r c966e119ea78 sbin/gpt/unset.c
--- a/sbin/gpt/unset.c Mon Mar 19 08:57:57 2018 +0000
+++ b/sbin/gpt/unset.c Mon Mar 19 09:06:20 2018 +0000
@@ -33,7 +33,7 @@
__FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $");
#endif
#ifdef __RCSID
-__RCSID("$NetBSD: unset.c,v 1.13 2015/12/29 16:45:04 christos Exp $");
+__RCSID("$NetBSD: unset.c,v 1.14 2018/03/19 09:06:20 mlelstv Exp $");
#endif
#include <sys/types.h>
@@ -53,13 +53,14 @@
static const char *unsethelp[] = {
"-a attribute -i index",
+ "-l",
};
struct gpt_cmd c_unset = {
"unset",
cmd_unset,
unsethelp, __arraycount(unsethelp),
- 0,
+ GPT_OPTDEV,
};
#define usage() gpt_usage(NULL, &c_unset)
@@ -74,11 +75,11 @@
while ((ch = getopt(argc, argv, "a:i:l")) != -1) {
switch(ch) {
case 'a':
- if (gpt_attr_get(gpt, &attributes) == -1)
+ if (gpt == NULL || gpt_attr_get(gpt, &attributes) == -1)
return usage();
break;
case 'i':
- if (gpt_uint_get(gpt, &entry) == -1)
+ if (gpt == NULL || gpt_uint_get(gpt, &entry) == -1)
return usage();
break;
case 'l':
@@ -89,7 +90,7 @@
}
}
- if (argc != optind)
+ if (gpt == NULL || argc != optind)
return usage();
return gpt_attr_update(gpt, entry, 0, attributes);
Home |
Main Index |
Thread Index |
Old Index