-/* $OpenBSD: i386_installboot.c,v 1.11 2015/10/07 03:06:46 krw Exp $ */
+/* $OpenBSD: i386_installboot.c,v 1.12 2015/10/08 14:50:38 krw Exp $ */
/* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */
/*
}
bootldr = fileprefix(root, bootldr);
+ if (bootldr == NULL)
+ exit(1);
if (verbose)
fprintf(stderr, "%s %s to %s\n",
(nowrite ? "would copy" : "copying"), stage2, bootldr);
if (!nowrite)
- filecopy(stage2, bootldr);
+ if (filecopy(stage2, bootldr) == -1)
+ exit(1);
/* Get bootstrap parameters to patch into proto. */
if (getbootparams(bootldr, devfd, &dl) != 0)
goto umount;
}
src = fileprefix(root, "/usr/mdec/BOOTIA32.EFI");
+ if (src == NULL) {
+ rslt = -1;
+ goto umount;
+ }
srclen = strlen(src);
if (verbose)
fprintf(stderr, "%s %s to %s\n",
(nowrite ? "would copy" : "copying"), src, dst);
- if (!nowrite)
- filecopy(src, dst);
+ if (!nowrite) {
+ rslt = filecopy(src, dst);
+ if (rslt == -1)
+ goto umount;
+ }
src[srclen - strlen("/BOOTIA32.EFI")] = '\0';
dst[pathlen] = '\0';
if (verbose)
fprintf(stderr, "%s %s to %s\n",
(nowrite ? "would copy" : "copying"), src, dst);
- if (!nowrite)
- filecopy(src, dst);
+ if (!nowrite) {
+ rslt = filecopy(src, dst);
+ if (rslt == -1)
+ goto umount;
+ }
- free(src);
- src = NULL;
rslt = 0;
umount:
-/* $OpenBSD: installboot.c,v 1.6 2015/10/03 16:56:52 krw Exp $ */
+/* $OpenBSD: installboot.c,v 1.7 2015/10/08 14:50:38 krw Exp $ */
/*
* Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
/* Prefix stages with root, unless they were user supplied. */
if (verbose)
fprintf(stderr, "Using %s as root\n", root);
- if (argc <= 1 && stage1 != NULL)
+ if (argc <= 1 && stage1 != NULL) {
stage1 = fileprefix(root, stage1);
- if (argc <= 2 && stage2 != NULL)
+ if (stage1 == NULL)
+ exit(1);
+ }
+ if (argc <= 2 && stage2 != NULL) {
stage2 = fileprefix(root, stage2);
+ if (stage2 == NULL)
+ exit(1);
+ }
if ((devfd = opendev(dev, (nowrite ? O_RDONLY : O_RDWR), OPENDEV_PART,
&realdev)) < 0)
-/* $OpenBSD: installboot.h,v 1.4 2014/01/18 03:07:05 jsing Exp $ */
+/* $OpenBSD: installboot.h,v 1.5 2015/10/08 14:50:38 krw Exp $ */
/*
* Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
*
void bootstrap(int, char *, char *);
#endif
-void filecopy(const char *, const char *);
+int filecopy(const char *, const char *);
char *fileprefix(const char *, const char *);
void md_init(void);
-/* $OpenBSD: landisk_installboot.c,v 1.2 2015/10/05 04:30:35 miod Exp $ */
+/* $OpenBSD: landisk_installboot.c,v 1.3 2015/10/08 14:50:38 krw Exp $ */
/*
* Copyright (c) 2013 Joel Sing <jsing@openbsd.org>
sync();
bootldr = fileprefix(root, bootldr);
+ if (bootldr == NULL)
+ exit(1);
if (!nowrite)
- filecopy(stage2, bootldr);
+ if (filecopy(stage2, bootldr) == -1)
+ exit(1);
/* Write bootblock into the superblock. */
bootstrap(devfd, dev, stage1);
-/* $OpenBSD: sparc64_installboot.c,v 1.3 2015/01/16 00:05:12 deraadt Exp $ */
+/* $OpenBSD: sparc64_installboot.c,v 1.4 2015/10/08 14:50:38 krw Exp $ */
/*
* Copyright (c) 2012, 2013 Joel Sing <jsing@openbsd.org>
sync();
bootldr = fileprefix(root, bootldr);
+ if (bootldr == NULL)
+ exit(1);
if (!nowrite)
- filecopy(stage2, bootldr);
+ if (filecopy(stage2, bootldr) == -1)
+ exit(1);
/* Write bootblock into the superblock. */
if (lseek(devfd, DEV_BSIZE, SEEK_SET) != DEV_BSIZE)
-/* $OpenBSD: util.c,v 1.6 2015/10/07 03:06:46 krw Exp $ */
+/* $OpenBSD: util.c,v 1.7 2015/10/08 14:50:38 krw Exp $ */
/*
* Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
#define BUFSIZE 512
-void
+int
filecopy(const char *srcfile, const char *dstfile)
{
struct stat sb;
ssize_t sz, n;
- int sfd, dfd;
+ int sfd, dfd, rslt = -1;
char *buf;
- if ((buf = malloc(BUFSIZE)) == NULL)
- err(1, "malloc");
+ if ((buf = malloc(BUFSIZE)) == NULL) {
+ warn("malloc");
+ return (-1);
+ }
sfd = open(srcfile, O_RDONLY);
- if (sfd == -1)
- err(1, "open %s", srcfile);
- if (fstat(sfd, &sb) == -1)
- err(1, "fstat");
+ if (sfd == -1) {
+ warn("open %s", srcfile);
+ return (-1);
+ }
+ if (fstat(sfd, &sb) == -1) {
+ warn("fstat");
+ return (-1);
+ }
sz = sb.st_size;
dfd = open(dstfile, O_WRONLY|O_CREAT);
- if (dfd == -1)
- err(1, "open %s", dstfile);
+ if (dfd == -1) {
+ warn("open %s", dstfile);
+ return (-1);
+ }
if (fchown(dfd, 0, 0) == -1)
- if (errno != EINVAL)
- err(1, "chown");
- if (fchmod(dfd, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1)
- err(1, "chmod");
+ if (errno != EINVAL) {
+ warn("chown");
+ return (-1);
+ }
+ if (fchmod(dfd, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) == -1) {
+ warn("chmod");
+ return (-1);
+ }
while (sz > 0) {
n = MINIMUM(sz, BUFSIZE);
- if ((n = read(sfd, buf, n)) == -1)
- err(1, "read");
+ if ((n = read(sfd, buf, n)) == -1) {
+ warn("read");
+ return (-1);
+ }
sz -= n;
- if (write(dfd, buf, n) != n)
- err(1, "write");
+ if (write(dfd, buf, n) != n) {
+ warn("write");
+ return (-1);
+ }
}
ftruncate(dfd, sb.st_size);
close(dfd);
close(sfd);
free(buf);
+
+ return (0);
}
char *
char *r, *s;
int n;
- if ((s = malloc(PATH_MAX)) == NULL)
- err(1, "malloc");
+ if ((s = malloc(PATH_MAX)) == NULL) {
+ warn("malloc");
+ return (NULL);
+ }
n = snprintf(s, PATH_MAX, "%s/%s", base, path);
- if (n < 1 || n >= PATH_MAX)
- err(1, "snprintf");
- if ((r = realpath(s, NULL)) == NULL)
- err(1, "realpath");
+ if (n < 1 || n >= PATH_MAX) {
+ free(s);
+ warn("snprintf");
+ return (NULL);
+ }
+ if ((r = realpath(s, NULL)) == NULL) {
+ free(s);
+ warn("realpath");
+ return (NULL);
+ }
free(s);
- return r;
+ return (r);
}
/*