Page MenuHomeFreeBSD

D7358.id19594.diff
No OneTemporary

D7358.id19594.diff

Index: usr.bin/bsdiff/bspatch/bspatch.c
===================================================================
--- usr.bin/bsdiff/bspatch/bspatch.c
+++ usr.bin/bsdiff/bspatch/bspatch.c
@@ -33,8 +33,19 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
#include <unistd.h>
+#if defined(__FreeBSD__)
+#if __FreeBSD_version >= 1100014
+#include <sys/capsicum.h>
+#define HAVE_CAPSICUM
+#elif __FreeBSD_version >= 1000000
+#include <sys/capability.h>
+#define HAVE_CAPSICUM
+#endif
+#endif
+
#ifndef O_BINARY
#define O_BINARY 0
#endif
@@ -70,6 +81,7 @@
{
FILE *f, *cpf, *dpf, *epf;
BZFILE *cpfbz2, *dpfbz2, *epfbz2;
+ cap_rights_t rights_ro, rights_wr;
int cbz2err, dbz2err, ebz2err;
int newfd, oldfd;
ssize_t oldsize, newsize;
@@ -87,6 +99,53 @@
/* Open patch file */
if ((f = fopen(argv[3], "rb")) == NULL)
err(1, "fopen(%s)", argv[3]);
+ /* Open patch file for control block */
+ if ((cpf = fopen(argv[3], "rb")) == NULL)
+ err(1, "fopen(%s)", argv[3]);
+ /* open patch file for diff block */
+ if ((dpf = fopen(argv[3], "rb")) == NULL)
+ err(1, "fopen(%s)", argv[3]);
+ /* open patch file for extra block */
+ if ((epf = fopen(argv[3], "rb")) == NULL)
+ err(1, "fopen(%s)", argv[3]);
+ /* open oldfile */
+ if ((oldfd = open(argv[1], O_RDONLY | O_BINARY, 0)) < 0)
+ err(1,"open(%s)", argv[1]);
+ /* open newfile */
+ if ((newfd = open(argv[2], O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0666)) < 0)
+ err(1,"open(%s)", argv[2]);
+
+#ifdef HAVE_CAPSICUM
+ if (cap_enter() < 0) {
+ /* Failed to engauge Capsicum */
+#else
+ {
+#endif
+ if (chroot("/var/empty") < 0) {
+ /* Skip the security sandbox if run as non-root */
+ if (errno == EPERM) {
+ warn("No security sandbox availabile");
+ } else {
+ err(1, "failed to enter security sandbox");
+ }
+ }
+ }
+
+ cap_rights_init(&rights_ro, CAP_READ, CAP_FSTAT, CAP_SEEK);
+ cap_rights_init(&rights_wr, CAP_WRITE);
+
+ if (cap_rights_limit(fileno(f), &rights_ro) < 0)
+ err(1, "cap_rights_limit() failed on patch");
+ if (cap_rights_limit(fileno(cpf), &rights_ro) < 0)
+ err(1, "cap_rights_limit() failed on patch");
+ if (cap_rights_limit(fileno(dpf), &rights_ro) < 0)
+ err(1, "cap_rights_limit() failed on patch");
+ if (cap_rights_limit(fileno(epf), &rights_ro) < 0)
+ err(1, "cap_rights_limit() failed on patch");
+ if (cap_rights_limit(oldfd, &rights_ro) < 0)
+ err(1, "cap_rights_limit() failed on input");
+ if (cap_rights_limit(newfd, &rights_wr) < 0)
+ err(1, "cap_rights_limit() failed on output");
/*
File format:
@@ -123,29 +182,22 @@
/* Close patch file and re-open it via libbzip2 at the right places */
if (fclose(f))
err(1, "fclose(%s)", argv[3]);
- if ((cpf = fopen(argv[3], "rb")) == NULL)
- err(1, "fopen(%s)", argv[3]);
if (fseeko(cpf, 32, SEEK_SET))
err(1, "fseeko(%s, %lld)", argv[3],
(long long)32);
if ((cpfbz2 = BZ2_bzReadOpen(&cbz2err, cpf, 0, 0, NULL, 0)) == NULL)
errx(1, "BZ2_bzReadOpen, bz2err = %d", cbz2err);
- if ((dpf = fopen(argv[3], "rb")) == NULL)
- err(1, "fopen(%s)", argv[3]);
if (fseeko(dpf, 32 + bzctrllen, SEEK_SET))
err(1, "fseeko(%s, %lld)", argv[3],
(long long)(32 + bzctrllen));
if ((dpfbz2 = BZ2_bzReadOpen(&dbz2err, dpf, 0, 0, NULL, 0)) == NULL)
errx(1, "BZ2_bzReadOpen, bz2err = %d", dbz2err);
- if ((epf = fopen(argv[3], "rb")) == NULL)
- err(1, "fopen(%s)", argv[3]);
if (fseeko(epf, 32 + bzctrllen + bzdatalen, SEEK_SET))
err(1, "fseeko(%s, %lld)", argv[3],
(long long)(32 + bzctrllen + bzdatalen));
if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL)
errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err);
- oldfd = open(argv[1], O_RDONLY | O_BINARY, 0);
if (oldfd < 0)
err(1, "%s", argv[1]);
if ((oldsize = lseek(oldfd, 0, SEEK_END)) == -1 ||
@@ -215,7 +267,6 @@
err(1, "fclose(%s)", argv[3]);
/* Write the new file */
- newfd = open(argv[2], O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0666);
if (newfd < 0)
err(1, "%s", argv[2]);
if (write(newfd, new, newsize) != newsize || close(newfd) == -1)

File Metadata

Mime Type
text/plain
Expires
Wed, Apr 22, 9:58 AM (19 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31969789
Default Alt Text
D7358.id19594.diff (3 KB)

Event Timeline