openbsd-ports/archivers/rzip/patches/patch-main_c
naddy 9ec6c1184e Import rzip 2.0; submitted by Lawrence Teo <lteo.openbsd1@mailnull.com>.
rzip is a compression program that is similar to gzip and bzip2.
The primary difference is that rzip is able to exploit long
distance redundancies in files, which enables rzip to produce
much better compression ratios (sometimes).
2005-03-30 00:02:08 +00:00

53 lines
1.6 KiB
Plaintext

$OpenBSD: patch-main_c,v 1.1.1.1 2005/03/30 00:02:08 naddy Exp $
--- main.c.orig Thu Feb 12 01:01:08 2004
+++ main.c Tue Mar 29 22:53:26 2005
@@ -50,7 +50,7 @@ static void write_magic(int fd_in, int f
uint32_t v;
memset(magic, 0, sizeof(magic));
- strcpy(magic, "RZIP");
+ strncpy(magic, "RZIP", 4);
magic[4] = RZIP_MAJOR_VERSION;
magic[5] = RZIP_MINOR_VERSION;
@@ -127,9 +127,13 @@ static void decompress_file(struct rzip_
{
int fd_in, fd_out = -1, fd_hist = -1;
off_t expected_size;
+ size_t n;
if (control->outname) {
control->outfile = strdup(control->outname);
+ if (control->outfile == NULL) {
+ fatal("Failed to allocate memory for output filename");
+ }
} else {
if (strlen(control->suffix) >= strlen(control->infile) ||
strcmp(control->suffix,
@@ -138,9 +142,12 @@ static void decompress_file(struct rzip_
fatal("%s: unknown suffix\n", control->infile);
}
- control->outfile = strndup(control->infile,
- strlen(control->infile) -
- strlen(control->suffix));
+ n = strlen(control->infile) - strlen(control->suffix) + 1;
+ control->outfile = malloc(n);
+ if (control->outfile == NULL) {
+ fatal("Failed to allocate memory for output filename");
+ }
+ strlcpy(control->outfile, control->infile, n);
}
fd_in = open(control->infile,O_RDONLY);
@@ -208,6 +215,9 @@ static void compress_file(struct rzip_co
if (control->outname) {
control->outfile = strdup(control->outname);
+ if (control->outfile == NULL) {
+ fatal("Failed to allocate memory for output filename");
+ }
} else {
asprintf(&control->outfile, "%s%s", control->infile, control->suffix);
}