Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/svhlabel getrawpartition(3) may fail, so call it only o...
details: https://anonhg.NetBSD.org/src/rev/0b7c69fa9787
branches: trunk
changeset: 784714:0b7c69fa9787
user: apb <apb%NetBSD.org@localhost>
date: Thu Feb 07 10:44:45 2013 +0000
description:
getrawpartition(3) may fail, so call it only once and test for failure.
Coverity CID 274527.
diffstat:
sbin/svhlabel/svhlabel.c | 17 +++++++++++------
1 files changed, 11 insertions(+), 6 deletions(-)
diffs (66 lines):
diff -r faa8aac9a740 -r 0b7c69fa9787 sbin/svhlabel/svhlabel.c
--- a/sbin/svhlabel/svhlabel.c Thu Feb 07 02:10:18 2013 +0000
+++ b/sbin/svhlabel/svhlabel.c Thu Feb 07 10:44:45 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: svhlabel.c,v 1.6 2011/08/27 18:55:58 joerg Exp $ */
+/* $NetBSD: svhlabel.c,v 1.7 2013/02/07 10:44:45 apb Exp $ */
/*
* Copyright (C) 2007 Stephen M. Rumble.
@@ -34,7 +34,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: svhlabel.c,v 1.6 2011/08/27 18:55:58 joerg Exp $");
+__RCSID("$NetBSD: svhlabel.c,v 1.7 2013/02/07 10:44:45 apb Exp $");
#endif /* not lint */
#include <stdio.h>
@@ -67,6 +67,7 @@
static struct sgi_boot_block *convert_sgi_boot_block(unsigned char *);
struct disklabel label;
+static int rawpart;
static void
getlabel(int sd)
@@ -80,8 +81,8 @@
* Some ports seem to not set the number of partitions
* correctly, albeit they seem to set the raw partition ok!
*/
- if (label.d_npartitions <= getrawpartition())
- label.d_npartitions = getrawpartition() + 1;
+ if (label.d_npartitions <= rawpart)
+ label.d_npartitions = rawpart + 1;
}
static void
@@ -164,7 +165,7 @@
if (j >= label.d_npartitions)
break;
- if (j == getrawpartition()) {
+ if (j == rawpart) {
if (++j >= label.d_npartitions)
break;
}
@@ -186,7 +187,7 @@
label.d_secpercyl = 1;
label.d_ncylinders = label.d_secperunit;
- i = getrawpartition();
+ i = rawpart;
if (label.d_partitions[i].p_fstype != FS_UNUSED ||
label.d_partitions[i].p_offset != 0 ||
label.d_partitions[i].p_size != label.d_secperunit) {
@@ -322,6 +323,10 @@
if (argc != 1)
usage();
+ rawpart = getrawpartition();
+ if (rawpart < 0)
+ err(EXIT_FAILURE, "getrawpartition");
+
if ((sd = opendisk(argv[0], write_it ? O_RDWR : O_RDONLY, name,
(size_t)MAXPATHLEN, 1)) < 0) {
perror(argv[0]);
Home |
Main Index |
Thread Index |
Old Index