Module Name:    src
Committed By:   bouyer
Date:           Mon Apr  9 12:54:00 UTC 2018

Modified Files:
        src/sbin/gpt [netbsd-8]: gpt.8 gpt.h main.c set.c type.c unset.c

Log Message:
Pull up following revision(s) (requested by mlelstv in ticket #710):
        sbin/gpt/main.c: revision 1.11
        sbin/gpt/gpt.h: revision 1.37
        sbin/gpt/set.c: revision 1.14
        sbin/gpt/type.c: revision 1.14
        sbin/gpt/unset.c: revision 1.14
        sbin/gpt/gpt.8: revision 1.58
Check device parameter to avoid segfaults. Augment synopsis for -l option.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.52.4.1 src/sbin/gpt/gpt.8
cvs rdiff -u -r1.35.4.1 -r1.35.4.2 src/sbin/gpt/gpt.h
cvs rdiff -u -r1.10 -r1.10.4.1 src/sbin/gpt/main.c
cvs rdiff -u -r1.13 -r1.13.8.1 src/sbin/gpt/set.c src/sbin/gpt/type.c \
    src/sbin/gpt/unset.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sbin/gpt/gpt.8
diff -u src/sbin/gpt/gpt.8:1.52 src/sbin/gpt/gpt.8:1.52.4.1
--- src/sbin/gpt/gpt.8:1.52	Thu Feb 16 03:32:17 2017
+++ src/sbin/gpt/gpt.8	Mon Apr  9 12:54:00 2018
@@ -1,4 +1,4 @@
-.\" $NetBSD: gpt.8,v 1.52 2017/02/16 03:32:17 christos Exp $
+.\" $NetBSD: gpt.8,v 1.52.4.1 2018/04/09 12:54:00 bouyer 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

Index: src/sbin/gpt/gpt.h
diff -u src/sbin/gpt/gpt.h:1.35.4.1 src/sbin/gpt/gpt.h:1.35.4.2
--- src/sbin/gpt/gpt.h:1.35.4.1	Mon Feb 12 04:05:07 2018
+++ src/sbin/gpt/gpt.h	Mon Apr  9 12:54:00 2018
@@ -81,6 +81,7 @@ gpt_t	gpt_open(const char *, int, int, o
 #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);

Index: src/sbin/gpt/main.c
diff -u src/sbin/gpt/main.c:1.10 src/sbin/gpt/main.c:1.10.4.1
--- src/sbin/gpt/main.c:1.10	Thu Feb 16 22:40:19 2017
+++ src/sbin/gpt/main.c	Mon Apr  9 12:54:00 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: main.c,v 1.10 2017/02/16 22:40:19 christos Exp $	*/
+/*	$NetBSD: main.c,v 1.10.4.1 2018/04/09 12:54:00 bouyer 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.10.4.1 2018/04/09 12:54:00 bouyer Exp $");
 #endif
 
 #include <stdio.h>
@@ -241,6 +241,9 @@ main(int argc, char *argv[])
 		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;
 	}

Index: src/sbin/gpt/set.c
diff -u src/sbin/gpt/set.c:1.13 src/sbin/gpt/set.c:1.13.8.1
--- src/sbin/gpt/set.c:1.13	Tue Dec 29 16:45:04 2015
+++ src/sbin/gpt/set.c	Mon Apr  9 12:54:00 2018
@@ -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.13.8.1 2018/04/09 12:54:00 bouyer Exp $");
 #endif
 
 #include <sys/types.h>
@@ -60,7 +60,7 @@ struct gpt_cmd c_set = {
 	"set",
 	cmd_set,
 	sethelp, __arraycount(sethelp),
-	0,
+	GPT_OPTDEV,
 };
 
 #define usage() gpt_usage(NULL, &c_set)
@@ -75,11 +75,11 @@ cmd_set(gpt_t gpt, int argc, char *argv[
 	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 @@ cmd_set(gpt_t gpt, int argc, char *argv[
 		}
 	}
 
-	if (argc != optind)
+	if (gpt == NULL || argc != optind)
 		return usage();
 
 	return gpt_attr_update(gpt, entry, attributes, 0);
Index: src/sbin/gpt/type.c
diff -u src/sbin/gpt/type.c:1.13 src/sbin/gpt/type.c:1.13.8.1
--- src/sbin/gpt/type.c:1.13	Sun Dec  6 00:39:26 2015
+++ src/sbin/gpt/type.c	Mon Apr  9 12:54:00 2018
@@ -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.13.8.1 2018/04/09 12:54:00 bouyer Exp $");
 #endif
 
 #include <sys/types.h>
@@ -61,7 +61,7 @@ struct gpt_cmd c_type = {
 	"type",
 	cmd_type,
 	typehelp, __arraycount(typehelp),
-	0,
+	GPT_OPTDEV,
 };
 
 #define usage() gpt_usage(NULL, &c_type)
@@ -91,17 +91,17 @@ cmd_type(gpt_t gpt, int argc, char *argv
 			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);
Index: src/sbin/gpt/unset.c
diff -u src/sbin/gpt/unset.c:1.13 src/sbin/gpt/unset.c:1.13.8.1
--- src/sbin/gpt/unset.c:1.13	Tue Dec 29 16:45:04 2015
+++ src/sbin/gpt/unset.c	Mon Apr  9 12:54:00 2018
@@ -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.13.8.1 2018/04/09 12:54:00 bouyer Exp $");
 #endif
 
 #include <sys/types.h>
@@ -53,13 +53,14 @@ static int cmd_unset(gpt_t, int, char *[
 
 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 @@ cmd_unset(gpt_t gpt, int argc, char *arg
 	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 @@ cmd_unset(gpt_t gpt, int argc, char *arg
 		}
 	}
 
-	if (argc != optind)
+	if (gpt == NULL || argc != optind)
 		return usage();
 
 	return gpt_attr_update(gpt, entry, 0, attributes);

Reply via email to