summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsdinstall/distextract
diff options
context:
space:
mode:
authornwhitehorn <nwhitehorn@FreeBSD.org>2011-02-21 14:28:31 +0000
committernwhitehorn <nwhitehorn@FreeBSD.org>2011-02-21 14:28:31 +0000
commita1c161cbf32776ad3d61e0ec7393fcad1a1576cc (patch)
treeaf1e2b17c12da1d9fef22bb41e6655bf712d6eb2 /usr.sbin/bsdinstall/distextract
parentfe0aa13fc979b4c564a62ba3b1a45bdcdc9ec7c8 (diff)
downloadFreeBSD-src-a1c161cbf32776ad3d61e0ec7393fcad1a1576cc.zip
FreeBSD-src-a1c161cbf32776ad3d61e0ec7393fcad1a1576cc.tar.gz
Add some error checking on the return values of chdir() and calloc(). The
first might actually happen, so it displays the error message in a prettier way. Found by: Coverity Prevent(tm) CID: 9121, 9122, 9123, 9124
Diffstat (limited to 'usr.sbin/bsdinstall/distextract')
-rw-r--r--usr.sbin/bsdinstall/distextract/distextract.c34
1 files changed, 23 insertions, 11 deletions
diff --git a/usr.sbin/bsdinstall/distextract/distextract.c b/usr.sbin/bsdinstall/distextract/distextract.c
index efd9a1b..c2c4884 100644
--- a/usr.sbin/bsdinstall/distextract/distextract.c
+++ b/usr.sbin/bsdinstall/distextract/distextract.c
@@ -46,12 +46,31 @@ main(void)
ndists++; /* Last one */
dists = calloc(ndists, sizeof(const char *));
+ if (dists == NULL) {
+ fprintf(stderr, "Out of memory!\n");
+ return (1);
+ }
+
for (i = 0; i < ndists; i++)
dists[i] = strsep(&diststring, " \t");
- chdir(getenv("BSDINSTALL_CHROOT"));
+ init_dialog(stdin, stdout);
+ dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer");
+ dlg_put_backtitle();
+
+ if (chdir(getenv("BSDINSTALL_CHROOT")) != 0) {
+ char error[512];
+ sprintf(error, "Could could change to directory %s: %s\n",
+ getenv("BSDINSTALL_DISTDIR"), strerror(errno));
+ dialog_msgbox("Error", error, 0, 0, TRUE);
+ end_dialog();
+ return (1);
+ }
+
retval = extract_files(ndists, dists);
+ end_dialog();
+
free(diststring);
free(dists);
@@ -84,9 +103,6 @@ extract_files(int nfiles, const char **files)
items[i*2 + 1] = "Pending";
}
- init_dialog(stdin, stdout);
- dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer");
- dlg_put_backtitle();
dialog_msgbox("",
"Checking distribution archives.\nPlease wait...", 0, 0, FALSE);
@@ -105,7 +121,7 @@ extract_files(int nfiles, const char **files)
items[i*2 + 1] = "Failed";
dialog_msgbox("Extract Error", errormsg, 0, 0,
TRUE);
- goto exit;
+ return (err);
}
archive_files[i] = 0;
while (archive_read_next_header(archive, &entry) == ARCHIVE_OK)
@@ -162,15 +178,11 @@ extract_files(int nfiles, const char **files)
items[i*2 + 1] = "Failed";
dialog_msgbox("Extract Error", errormsg, 0, 0,
TRUE);
- goto exit;
+ return (err);
}
archive_read_free(archive);
}
- err = 0;
-exit:
- end_dialog();
-
- return (err);
+ return (0);
}
OpenPOWER on IntegriCloud