mirror of
https://git.FreeBSD.org/src.git
synced 2025-01-18 15:30:21 +00:00
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
This commit is contained in:
parent
071e1365c2
commit
57bda1b639
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=218915
@ -46,12 +46,31 @@ main(void)
|
|||||||
ndists++; /* Last one */
|
ndists++; /* Last one */
|
||||||
|
|
||||||
dists = calloc(ndists, sizeof(const char *));
|
dists = calloc(ndists, sizeof(const char *));
|
||||||
|
if (dists == NULL) {
|
||||||
|
fprintf(stderr, "Out of memory!\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < ndists; i++)
|
for (i = 0; i < ndists; i++)
|
||||||
dists[i] = strsep(&diststring, " \t");
|
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);
|
retval = extract_files(ndists, dists);
|
||||||
|
|
||||||
|
end_dialog();
|
||||||
|
|
||||||
free(diststring);
|
free(diststring);
|
||||||
free(dists);
|
free(dists);
|
||||||
|
|
||||||
@ -84,9 +103,6 @@ extract_files(int nfiles, const char **files)
|
|||||||
items[i*2 + 1] = "Pending";
|
items[i*2 + 1] = "Pending";
|
||||||
}
|
}
|
||||||
|
|
||||||
init_dialog(stdin, stdout);
|
|
||||||
dialog_vars.backtitle = __DECONST(char *, "FreeBSD Installer");
|
|
||||||
dlg_put_backtitle();
|
|
||||||
dialog_msgbox("",
|
dialog_msgbox("",
|
||||||
"Checking distribution archives.\nPlease wait...", 0, 0, FALSE);
|
"Checking distribution archives.\nPlease wait...", 0, 0, FALSE);
|
||||||
|
|
||||||
@ -105,7 +121,7 @@ extract_files(int nfiles, const char **files)
|
|||||||
items[i*2 + 1] = "Failed";
|
items[i*2 + 1] = "Failed";
|
||||||
dialog_msgbox("Extract Error", errormsg, 0, 0,
|
dialog_msgbox("Extract Error", errormsg, 0, 0,
|
||||||
TRUE);
|
TRUE);
|
||||||
goto exit;
|
return (err);
|
||||||
}
|
}
|
||||||
archive_files[i] = 0;
|
archive_files[i] = 0;
|
||||||
while (archive_read_next_header(archive, &entry) == ARCHIVE_OK)
|
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";
|
items[i*2 + 1] = "Failed";
|
||||||
dialog_msgbox("Extract Error", errormsg, 0, 0,
|
dialog_msgbox("Extract Error", errormsg, 0, 0,
|
||||||
TRUE);
|
TRUE);
|
||||||
goto exit;
|
return (err);
|
||||||
}
|
}
|
||||||
|
|
||||||
archive_read_free(archive);
|
archive_read_free(archive);
|
||||||
}
|
}
|
||||||
|
|
||||||
err = 0;
|
return (0);
|
||||||
exit:
|
|
||||||
end_dialog();
|
|
||||||
|
|
||||||
return (err);
|
|
||||||
}
|
}
|
||||||
|
@ -46,15 +46,34 @@ main(void)
|
|||||||
ndists++; /* Last one */
|
ndists++; /* Last one */
|
||||||
|
|
||||||
urls = calloc(ndists, sizeof(const char *));
|
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++) {
|
for (i = 0; i < ndists; i++) {
|
||||||
urls[i] = malloc(PATH_MAX);
|
urls[i] = malloc(PATH_MAX);
|
||||||
sprintf(urls[i], "%s/%s", getenv("BSDINSTALL_DISTSITE"),
|
sprintf(urls[i], "%s/%s", getenv("BSDINSTALL_DISTSITE"),
|
||||||
strsep(&diststring, " \t"));
|
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);
|
nfetched = fetch_files(ndists, urls);
|
||||||
|
|
||||||
|
end_dialog();
|
||||||
|
|
||||||
free(diststring);
|
free(diststring);
|
||||||
for (i = 0; i < ndists; i++)
|
for (i = 0; i < ndists; i++)
|
||||||
free(urls[i]);
|
free(urls[i]);
|
||||||
@ -81,6 +100,11 @@ fetch_files(int nfiles, char **urls)
|
|||||||
|
|
||||||
/* Make the transfer list for dialog */
|
/* Make the transfer list for dialog */
|
||||||
items = calloc(sizeof(char *), nfiles * 2);
|
items = calloc(sizeof(char *), nfiles * 2);
|
||||||
|
if (items == NULL) {
|
||||||
|
fprintf(stderr, "Out of memory!\n");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < nfiles; i++) {
|
for (i = 0; i < nfiles; i++) {
|
||||||
items[i*2] = strrchr(urls[i], '/');
|
items[i*2] = strrchr(urls[i], '/');
|
||||||
if (items[i*2] != NULL)
|
if (items[i*2] != NULL)
|
||||||
@ -90,10 +114,6 @@ fetch_files(int nfiles, char **urls)
|
|||||||
items[i*2 + 1] = "Pending";
|
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);
|
dialog_msgbox("", "Connecting to server.\nPlease wait...", 0, 0, FALSE);
|
||||||
|
|
||||||
/* Try to stat all the files */
|
/* Try to stat all the files */
|
||||||
@ -180,8 +200,8 @@ fetch_files(int nfiles, char **urls)
|
|||||||
fclose(fetch_out);
|
fclose(fetch_out);
|
||||||
fclose(file_out);
|
fclose(file_out);
|
||||||
}
|
}
|
||||||
end_dialog();
|
|
||||||
|
|
||||||
free(items);
|
free(items);
|
||||||
return (nsuccess);
|
return (nsuccess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user