Sat Jul 25 10:37:22 2015 UTC ()
Handle getfsspecname errors.


(mlelstv)
diff -r1.112 -r1.113 src/sbin/newfs/newfs.c
diff -r1.38 -r1.39 src/usr.sbin/installboot/installboot.c

cvs diff -r1.112 -r1.113 src/sbin/newfs/newfs.c (expand / switch to unified diff)

--- src/sbin/newfs/newfs.c 2014/10/25 16:47:23 1.112
+++ src/sbin/newfs/newfs.c 2015/07/25 10:37:22 1.113
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: newfs.c,v 1.112 2014/10/25 16:47:23 mlelstv Exp $ */ 1/* $NetBSD: newfs.c,v 1.113 2015/07/25 10:37:22 mlelstv Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1983, 1989, 1993, 1994 4 * Copyright (c) 1983, 1989, 1993, 1994
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -68,27 +68,27 @@ @@ -68,27 +68,27 @@
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#include <sys/cdefs.h> 71#include <sys/cdefs.h>
72#ifndef lint 72#ifndef lint
73__COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1993, 1994\ 73__COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1993, 1994\
74 The Regents of the University of California. All rights reserved."); 74 The Regents of the University of California. All rights reserved.");
75#endif /* not lint */ 75#endif /* not lint */
76 76
77#ifndef lint 77#ifndef lint
78#if 0 78#if 0
79static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95"; 79static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95";
80#else 80#else
81__RCSID("$NetBSD: newfs.c,v 1.112 2014/10/25 16:47:23 mlelstv Exp $"); 81__RCSID("$NetBSD: newfs.c,v 1.113 2015/07/25 10:37:22 mlelstv Exp $");
82#endif 82#endif
83#endif /* not lint */ 83#endif /* not lint */
84 84
85/* 85/*
86 * newfs: friendly front end to mkfs 86 * newfs: friendly front end to mkfs
87 */ 87 */
88#include <sys/param.h> 88#include <sys/param.h>
89#include <sys/ioctl.h> 89#include <sys/ioctl.h>
90#include <sys/disklabel.h> 90#include <sys/disklabel.h>
91#include <sys/disk.h> 91#include <sys/disk.h>
92#include <sys/file.h> 92#include <sys/file.h>
93#include <sys/mount.h> 93#include <sys/mount.h>
94#include <sys/sysctl.h> 94#include <sys/sysctl.h>
@@ -483,29 +483,31 @@ main(int argc, char *argv[]) @@ -483,29 +483,31 @@ main(int argc, char *argv[])
483 fl = O_RDWR | O_CREAT; 483 fl = O_RDWR | O_CREAT;
484 else 484 else
485 fl = O_RDWR; 485 fl = O_RDWR;
486 } 486 }
487 fsi = open(special, fl, 0777); 487 fsi = open(special, fl, 0777);
488 if (fsi == -1) 488 if (fsi == -1)
489 err(1, "can't open file %s", special); 489 err(1, "can't open file %s", special);
490 if (fstat(fsi, &sb) == -1) 490 if (fstat(fsi, &sb) == -1)
491 err(1, "can't fstat opened %s", special); 491 err(1, "can't fstat opened %s", special);
492 if (!Nflag) 492 if (!Nflag)
493 fso = fsi; 493 fso = fsi;
494 } 494 }
495 } else { /* !Fflag && !mfs */ 495 } else { /* !Fflag && !mfs */
496 special = getfsspecname(specname, sizeof(specname), special); 496 raw = getfsspecname(specname, sizeof(specname), special);
497 raw = getdiskrawname(rawname, sizeof(rawname), special); 497 if (raw == NULL)
498 if (raw != NULL) 498 err(1, "%s: %s", special, specname);
 499 special = getdiskrawname(rawname, sizeof(rawname), raw);
 500 if (special == NULL)
499 special = raw; 501 special = raw;
500 502
501 fsi = opendisk(special, O_RDONLY, device, sizeof(device), 0); 503 fsi = opendisk(special, O_RDONLY, device, sizeof(device), 0);
502 special = device; 504 special = device;
503 if (fsi < 0 || fstat(fsi, &sb) == -1) 505 if (fsi < 0 || fstat(fsi, &sb) == -1)
504 err(1, "%s: open for read", special); 506 err(1, "%s: open for read", special);
505 if (S_ISBLK(sb.st_mode)) { 507 if (S_ISBLK(sb.st_mode)) {
506 errx(1, "%s is a block device. use raw device", 508 errx(1, "%s is a block device. use raw device",
507 special); 509 special);
508 } 510 }
509 511
510 if (!Nflag) { 512 if (!Nflag) {
511 fso = open(special, O_WRONLY, 0); 513 fso = open(special, O_WRONLY, 0);

cvs diff -r1.38 -r1.39 src/usr.sbin/installboot/installboot.c (expand / switch to unified diff)

--- src/usr.sbin/installboot/installboot.c 2015/06/05 07:44:39 1.38
+++ src/usr.sbin/installboot/installboot.c 2015/07/25 10:37:22 1.39
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: installboot.c,v 1.38 2015/06/05 07:44:39 mlelstv Exp $ */ 1/* $NetBSD: installboot.c,v 1.39 2015/07/25 10:37:22 mlelstv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Luke Mewburn of Wasabi Systems. 8 * by Luke Mewburn of Wasabi Systems.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#if HAVE_NBTOOL_CONFIG_H 32#if HAVE_NBTOOL_CONFIG_H
33#include "nbtool_config.h" 33#include "nbtool_config.h"
34#endif 34#endif
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37#if !defined(__lint) 37#if !defined(__lint)
38__RCSID("$NetBSD: installboot.c,v 1.38 2015/06/05 07:44:39 mlelstv Exp $"); 38__RCSID("$NetBSD: installboot.c,v 1.39 2015/07/25 10:37:22 mlelstv Exp $");
39#endif /* !__lint */ 39#endif /* !__lint */
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#include <sys/ioctl.h> 42#include <sys/ioctl.h>
43#include <sys/utsname.h> 43#include <sys/utsname.h>
44 44
45#include <assert.h> 45#include <assert.h>
46#include <err.h> 46#include <err.h>
47#include <fcntl.h> 47#include <fcntl.h>
48#include <limits.h> 48#include <limits.h>
49#include <stdio.h> 49#include <stdio.h>
50#include <stdlib.h> 50#include <stdlib.h>
51#include <stddef.h> 51#include <stddef.h>
@@ -230,26 +230,28 @@ main(int argc, char *argv[]) @@ -230,26 +230,28 @@ main(int argc, char *argv[])
230 } 230 }
231 if (params->flags & IB_CLEAR && 231 if (params->flags & IB_CLEAR &&
232 params->flags & (IB_STAGE1START | IB_STAGE2START | IB_APPEND)) { 232 params->flags & (IB_STAGE1START | IB_STAGE2START | IB_APPEND)) {
233 warnx("Can't use `-b bno', `-B bno' or `-o append' with `-c'"); 233 warnx("Can't use `-b bno', `-B bno' or `-o append' with `-c'");
234 exit(1); 234 exit(1);
235 } 235 }
236 236
237 if (argc >= 3) { 237 if (argc >= 3) {
238 params->stage2 = argv[2]; 238 params->stage2 = argv[2];
239 } 239 }
240 240
241#if !HAVE_NBTOOL_CONFIG_H 241#if !HAVE_NBTOOL_CONFIG_H
242 special = getfsspecname(specname, sizeof(specname), argv[0]); 242 special = getfsspecname(specname, sizeof(specname), argv[0]);
 243 if (special == NULL)
 244 err(1, "%s: %s", argv[0], specname);
243 raw = getdiskrawname(rawname, sizeof(rawname), special); 245 raw = getdiskrawname(rawname, sizeof(rawname), special);
244 if (raw != NULL) 246 if (raw != NULL)
245 special = raw; 247 special = raw;
246 params->filesystem = special; 248 params->filesystem = special;
247#else 249#else
248 params->filesystem = argv[0]; 250 params->filesystem = argv[0];
249#endif 251#endif
250 252
251 if (params->flags & IB_NOWRITE) { 253 if (params->flags & IB_NOWRITE) {
252 op = "only"; 254 op = "only";
253 mode = O_RDONLY; 255 mode = O_RDONLY;
254 } else { 256 } else {
255 op = "write"; 257 op = "write";