Check device parameter to avoid segfaults. Agument synopsis for -l option.

This commit is contained in:
mlelstv 2018-03-19 09:06:20 +00:00
parent 0a54329285
commit a23ee50408
6 changed files with 32 additions and 18 deletions

View File

@ -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

View File

@ -81,6 +81,7 @@ gpt_t gpt_open(const char *, int, int, off_t, u_int, time_t);
#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);

View File

@ -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 @@ 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;
}

View File

@ -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 @@ 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);

View File

@ -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 @@ 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);

View File

@ -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 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 *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':
@ -89,7 +90,7 @@ cmd_unset(gpt_t gpt, int argc, char *argv[])
}
}
if (argc != optind)
if (gpt == NULL || argc != optind)
return usage();
return gpt_attr_update(gpt, entry, 0, attributes);