diff options
author | nwhitehorn <nwhitehorn@FreeBSD.org> | 2011-02-21 14:28:31 +0000 |
---|---|---|
committer | nwhitehorn <nwhitehorn@FreeBSD.org> | 2011-02-21 14:28:31 +0000 |
commit | a1c161cbf32776ad3d61e0ec7393fcad1a1576cc (patch) | |
tree | af1e2b17c12da1d9fef22bb41e6655bf712d6eb2 /usr.sbin/bsdinstall/distfetch | |
parent | fe0aa13fc979b4c564a62ba3b1a45bdcdc9ec7c8 (diff) | |
download | FreeBSD-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/distfetch')
-rw-r--r-- | usr.sbin/bsdinstall/distfetch/distfetch.c | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/usr.sbin/bsdinstall/distfetch/distfetch.c b/usr.sbin/bsdinstall/distfetch/distfetch.c index 2e1d1b3..0ced75c 100644 --- a/usr.sbin/bsdinstall/distfetch/distfetch.c +++ b/usr.sbin/bsdinstall/distfetch/distfetch.c @@ -46,15 +46,34 @@ main(void) ndists++; /* Last one */ urls = calloc(ndists, sizeof(const char *)); + if (urls == NULL) { + fprintf(stderr, "Out of memory!\n"); + return (1); + } + + init_dialog(stdin, stdout); + dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer"); + dlg_put_backtitle(); + for (i = 0; i < ndists; i++) { urls[i] = malloc(PATH_MAX); sprintf(urls[i], "%s/%s", getenv("BSDINSTALL_DISTSITE"), strsep(&diststring, " \t")); } - chdir(getenv("BSDINSTALL_DISTDIR")); + if (chdir(getenv("BSDINSTALL_DISTDIR")) != 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); + } + nfetched = fetch_files(ndists, urls); + end_dialog(); + free(diststring); for (i = 0; i < ndists; i++) free(urls[i]); @@ -81,6 +100,11 @@ fetch_files(int nfiles, char **urls) /* Make the transfer list for dialog */ items = calloc(sizeof(char *), nfiles * 2); + if (items == NULL) { + fprintf(stderr, "Out of memory!\n"); + return (-1); + } + for (i = 0; i < nfiles; i++) { items[i*2] = strrchr(urls[i], '/'); if (items[i*2] != NULL) @@ -90,10 +114,6 @@ fetch_files(int nfiles, char **urls) items[i*2 + 1] = "Pending"; } - init_dialog(stdin, stdout); - dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer"); - dlg_put_backtitle(); - dialog_msgbox("", "Connecting to server.\nPlease wait...", 0, 0, FALSE); /* Try to stat all the files */ @@ -180,8 +200,8 @@ fetch_files(int nfiles, char **urls) fclose(fetch_out); fclose(file_out); } - end_dialog(); free(items); return (nsuccess); } + |