Module Name: src
Committed By: apb
Date: Thu Feb 7 10:44:46 UTC 2013
Modified Files:
src/sbin/svhlabel: svhlabel.c
Log Message:
getrawpartition(3) may fail, so call it only once and test for failure.
Coverity CID 274527.
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sbin/svhlabel/svhlabel.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/svhlabel/svhlabel.c
diff -u src/sbin/svhlabel/svhlabel.c:1.6 src/sbin/svhlabel/svhlabel.c:1.7
--- src/sbin/svhlabel/svhlabel.c:1.6 Sat Aug 27 18:55:58 2011
+++ src/sbin/svhlabel/svhlabel.c Thu Feb 7 10:44:45 2013
@@ -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 int is_efs(int, uint32_t);
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 @@ getlabel(int sd)
* 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 @@ getparts(int sd, int verbose)
if (j >= label.d_npartitions)
break;
- if (j == getrawpartition()) {
+ if (j == rawpart) {
if (++j >= label.d_npartitions)
break;
}
@@ -186,7 +187,7 @@ getparts(int sd, int verbose)
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 @@ main(int argc, char **argv)
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]);