pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/pkg_install-renovation]: pkgsrc/pkgtools/pkg_install/files Most memor...
details: https://anonhg.NetBSD.org/pkgsrc/rev/f8aacb929b59
branches: pkg_install-renovation
changeset: 541576:f8aacb929b59
user: joerg <joerg%pkgsrc.org@localhost>
date: Sat Aug 02 20:33:50 2008 +0000
description:
Most memory allocation failures were fatal already and the majority of
the rest lacked an explicit check. Add the usual x* wrappers around
malloc and friends that explicitly terminate on error and use them in
all but Dewey.
diffstat:
pkgtools/pkg_install/files/add/perform.c | 87 ++++----------
pkgtools/pkg_install/files/admin/audit.c | 11 +-
pkgtools/pkg_install/files/admin/check.c | 7 +-
pkgtools/pkg_install/files/admin/main.c | 9 +-
pkgtools/pkg_install/files/create/build.c | 7 +-
pkgtools/pkg_install/files/create/perform.c | 11 +-
pkgtools/pkg_install/files/create/pl.c | 34 ++---
pkgtools/pkg_install/files/create/util.c | 15 +-
pkgtools/pkg_install/files/delete/main.c | 12 +-
pkgtools/pkg_install/files/info/main.c | 10 +-
pkgtools/pkg_install/files/info/perform.c | 27 +---
pkgtools/pkg_install/files/lib/Makefile.in | 4 +-
pkgtools/pkg_install/files/lib/conflicts.c | 15 +--
pkgtools/pkg_install/files/lib/decompress.c | 20 +--
pkgtools/pkg_install/files/lib/fexec.c | 9 +-
pkgtools/pkg_install/files/lib/iterate.c | 16 +-
pkgtools/pkg_install/files/lib/lib.h | 10 +-
pkgtools/pkg_install/files/lib/lpkg.c | 8 +-
pkgtools/pkg_install/files/lib/opattern.c | 7 +-
pkgtools/pkg_install/files/lib/parse-config.c | 16 +-
pkgtools/pkg_install/files/lib/path.c | 25 +---
pkgtools/pkg_install/files/lib/pkcs7.c | 6 +-
pkgtools/pkg_install/files/lib/pkg_io.c | 13 +-
pkgtools/pkg_install/files/lib/pkg_signature.c | 42 ++----
pkgtools/pkg_install/files/lib/pkgdb.c | 11 +-
pkgtools/pkg_install/files/lib/plist.c | 27 +---
pkgtools/pkg_install/files/lib/var.c | 17 +-
pkgtools/pkg_install/files/lib/vulnerabilities-file.c | 40 ++----
pkgtools/pkg_install/files/lib/xwrapper.c | 102 ++++++++++++++++++
29 files changed, 283 insertions(+), 335 deletions(-)
diffs (truncated from 1601 to 300 lines):
diff -r a943c5d523ba -r f8aacb929b59 pkgtools/pkg_install/files/add/perform.c
--- a/pkgtools/pkg_install/files/add/perform.c Fri Aug 01 19:14:42 2008 +0000
+++ b/pkgtools/pkg_install/files/add/perform.c Sat Aug 02 20:33:50 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.70.4.13 2008/07/30 22:26:03 joerg Exp $ */
+/* $NetBSD: perform.c,v 1.70.4.14 2008/08/02 20:33:50 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
#endif
@@ -6,7 +6,7 @@
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
-__RCSID("$NetBSD: perform.c,v 1.70.4.13 2008/07/30 22:26:03 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.70.4.14 2008/08/02 20:33:50 joerg Exp $");
/*-
* Copyright (c) 2003 Grant Beattie <grant%NetBSD.org@localhost>
@@ -137,10 +137,7 @@
if (errno != ENOENT)
return -1;
- if ((p = strdup(path)) == NULL)
- err(EXIT_FAILURE, "strdup failed");
-
- cur_end = p;
+ cur_end = p = xstrdup(path);
for (;;) {
/*
@@ -231,8 +228,7 @@
warnx("package meta data too large to process");
return -1;
}
- if ((*target = malloc(size + 1)) == NULL)
- err(2, "cannot allocate meta data");
+ *target = xmalloc(size + 1);
if (archive_read_data(pkg->archive, *target, size) != size) {
warnx("cannot read package meta data");
return -1;
@@ -284,7 +280,7 @@
return -1;
}
if (pkg->pkgname == NULL)
- pkg->pkgname = strdup(p->name);
+ pkg->pkgname = xstrdup(p->name);
else if (strcmp(pkg->pkgname, p->name) != 0) {
warnx("Signature and PLIST differ on package name");
return -1;
@@ -307,12 +303,10 @@
} else
pkg->prefix = p->name;
- if (Destdir != NULL) {
- if (asprintf(&pkg->install_prefix, "%s/%s", Destdir,
- pkg->prefix) == -1)
- err(EXIT_FAILURE, "asprintf failed");
- } else if ((pkg->install_prefix = strdup(pkg->prefix)) == NULL)
- err(EXIT_FAILURE, "strdup failed");
+ if (Destdir != NULL)
+ pkg->install_prefix = xasprintf("%s/%s", Destdir, pkg->prefix);
+ else
+ pkg->install_prefix = xstrdup(pkg->prefix);
return 0;
}
@@ -328,9 +322,7 @@
char *val;
key = strchr(line, '=');
- val = malloc(eol - key);
- if (val == NULL)
- err(2, "malloc failed");
+ val = xmalloc(eol - key);
memcpy(val, key + 1, eol - key - 1);
val[eol - key - 1] = '\0';
return val;
@@ -376,10 +368,8 @@
plist_t *p;
int status;
- if ((pkgbase = strdup(pkg->pkgname)) == NULL) {
- warnx("strdup failed");
- return -1;
- }
+ pkgbase = xstrdup(pkg->pkgname);
+
if ((iter = strrchr(pkgbase, '-')) == NULL) {
free(pkgbase);
warnx("Invalid package name %s", pkg->pkgname);
@@ -542,11 +532,8 @@
descr->entry_offset);
if (*target == NULL)
continue;
- if (asprintf(&filename, "%s/%s", pkg->install_logdir,
- descr->entry_filename) == -1) {
- warn("asprintf failed");
- return -1;
- }
+ filename = xasprintf("%s/%s", pkg->install_logdir,
+ descr->entry_filename);
(void)unlink(filename);
fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT, descr->perm);
if (fd == -1) {
@@ -668,10 +655,7 @@
p->name, archive_entry_pathname(pkg->entry));
goto out;
}
- if (asprintf(&fullpath, "%s/%s", pkg->prefix, p->name) == -1) {
- warnx("asprintf failed");
- goto out;
- }
+ fullpath = xasprintf("%s/%s", pkg->prefix, p->name);
pkgdb_store(fullpath, pkg->pkgname);
free(fullpath);
if (Verbose)
@@ -778,8 +762,7 @@
if (pkg->other_version != NULL)
return; /* XXX It's using the old dependencies. */
- if (asprintf(&text, "%s\n", pkg->pkgname) == -1)
- err(2, "asprintf failed");
+ text = xasprintf("%s\n", pkg->pkgname);
text_len = strlen(text);
for (i = 0; i < pkg->dep_length; ++i) {
@@ -972,11 +955,7 @@
} else if (p->type != PLIST_FILE)
continue;
- if (asprintf(&fullpath, "%s/%s", pkg->prefix, p->name) == -1) {
- warnx("asprintf failed");
- status = -1;
- break;
- }
+ fullpath = xasprintf("%s/%s", pkg->prefix, p->name);
existing = pkgdb_retrieve(fullpath);
free(fullpath);
if (existing == NULL)
@@ -1056,17 +1035,8 @@
if (pkg->dep_length + 1 >= pkg->dep_allocated) {
char **tmp;
pkg->dep_allocated = 2 * pkg->dep_allocated + 1;
- tmp = realloc(pkg->dependencies,
+ pkg->dependencies = xrealloc(pkg->dependencies,
pkg->dep_allocated * sizeof(*tmp));
- if (tmp == NULL) {
- warnx("realloc failed");
- free(pkg->dependencies);
- pkg->dependencies = NULL;
- pkg->dep_length = pkg->dep_allocated = 0;
- free(best_installed);
- return -1;
- }
- pkg->dependencies = tmp;
}
pkg->dependencies[pkg->dep_length++] = best_installed;
}
@@ -1217,8 +1187,7 @@
void *signature_cookie;
struct pkg_task *pkg;
- if ((pkg = calloc(1, sizeof(*pkg))) == NULL)
- err(2, "malloc failed");
+ pkg = xcalloc(1, sizeof(*pkg));
status = -1;
@@ -1249,21 +1218,18 @@
warnx("mtree specification in pkg `%s' ignored", pkg->pkgname);
if (pkg->meta_data.meta_views != NULL) {
- if ((pkg->logdir = strdup(pkg->prefix)) == NULL)
- err(EXIT_FAILURE, "strdup failed");
+ pkg->logdir = xstrdup(pkg->prefix);
_pkgdb_setPKGDB_DIR(dirname_of(pkg->logdir));
} else {
- if (asprintf(&pkg->logdir, "%s/%s", _pkgdb_getPKGDB_DIR(),
- pkg->pkgname) == -1)
- err(EXIT_FAILURE, "asprintf failed");
+ pkg->logdir = xasprintf("%s/%s", _pkgdb_getPKGDB_DIR(),
+ pkg->pkgname);
}
if (Destdir != NULL) {
- if (asprintf(&pkg->install_logdir, "%s/%s", Destdir, pkg->logdir) == -1)
- err(EXIT_FAILURE, "asprintf failed");
+ pkg->install_logdir = xasprintf("%s/%s", Destdir, pkg->logdir);
_pkgdb_setPKGDB_DIR(dirname_of(pkg->install_logdir));
- } else if ((pkg->install_logdir = strdup(pkg->logdir)) == NULL)
- err(EXIT_FAILURE, "strdup failed");
+ } else
+ pkg->install_logdir = xstrdup(pkg->logdir);
if (NoRecord && !Fake) {
const char *tmpdir;
@@ -1273,8 +1239,7 @@
tmpdir = "/tmp";
free(pkg->install_logdir);
- if (asprintf(&pkg->install_logdir, "%s/pkg_install.XXXXXX", tmpdir) == -1)
- err(EXIT_FAILURE, "asprintf failed");
+ pkg->install_logdir = xasprintf("%s/pkg_install.XXXXXX", tmpdir);
/* XXX pkg_add -u... */
if (mkdtemp(pkg->install_logdir) == NULL) {
warn("mkdtemp failed");
diff -r a943c5d523ba -r f8aacb929b59 pkgtools/pkg_install/files/admin/audit.c
--- a/pkgtools/pkg_install/files/admin/audit.c Fri Aug 01 19:14:42 2008 +0000
+++ b/pkgtools/pkg_install/files/admin/audit.c Sat Aug 02 20:33:50 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: audit.c,v 1.8.2.2 2008/07/27 16:22:53 joerg Exp $ */
+/* $NetBSD: audit.c,v 1.8.2.3 2008/08/02 20:33:50 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -8,7 +8,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: audit.c,v 1.8.2.2 2008/07/27 16:22:53 joerg Exp $");
+__RCSID("$NetBSD: audit.c,v 1.8.2.3 2008/08/02 20:33:50 joerg Exp $");
#endif
/*-
@@ -363,8 +363,7 @@
err(EXIT_FAILURE, "pkg-vulnerabilities is too large");
buf_len = st.size;
- if ((buf = malloc(buf_len + 1)) == NULL)
- err(EXIT_FAILURE, "malloc failed");
+ buf = xmalloc(buf_len + 1);
if (fetchIO_read(f, buf, buf_len) != buf_len)
err(EXIT_FAILURE, "Failure during fetch of pkg-vulnerabilities");
@@ -455,9 +454,7 @@
open_brace = inner_brace;
}
- expanded_pkg = malloc(strlen(pattern)); /* {} are going away... */
- if (expanded_pkg == NULL)
- err(EXIT_FAILURE, "malloc failed");
+ expanded_pkg = xmalloc(strlen(pattern)); /* {} are going away... */
prefix_len = open_brace - pattern;
suffix = close_brace + 1;
diff -r a943c5d523ba -r f8aacb929b59 pkgtools/pkg_install/files/admin/check.c
--- a/pkgtools/pkg_install/files/admin/check.c Fri Aug 01 19:14:42 2008 +0000
+++ b/pkgtools/pkg_install/files/admin/check.c Sat Aug 02 20:33:50 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: check.c,v 1.2.4.2 2008/05/23 15:57:04 joerg Exp $ */
+/* $NetBSD: check.c,v 1.2.4.3 2008/08/02 20:33:50 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -8,7 +8,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: check.c,v 1.2.4.2 2008/05/23 15:57:04 joerg Exp $");
+__RCSID("$NetBSD: check.c,v 1.2.4.3 2008/08/02 20:33:50 joerg Exp $");
#endif
/*-
@@ -234,8 +234,7 @@
errx(EXIT_FAILURE, "No matching pkg for %s.", pkg);
}
- if (asprintf(&pattern, "%s-[0-9]*", pkg) == -1)
- errx(EXIT_FAILURE, "asprintf failed");
+ pattern = xasprintf("%s-[0-9]*", pkg);
if (match_installed_pkgs(pattern, checkpattern_fn, &arg) == -1)
errx(EXIT_FAILURE, "Cannot process pkdbdb");
diff -r a943c5d523ba -r f8aacb929b59 pkgtools/pkg_install/files/admin/main.c
--- a/pkgtools/pkg_install/files/admin/main.c Fri Aug 01 19:14:42 2008 +0000
+++ b/pkgtools/pkg_install/files/admin/main.c Sat Aug 02 20:33:50 2008 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.42.2.5 2008/06/04 11:23:13 joerg Exp $ */
+/* $NetBSD: main.c,v 1.42.2.6 2008/08/02 20:33:50 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -8,7 +8,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.42.2.5 2008/06/04 11:23:13 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.42.2.6 2008/08/02 20:33:50 joerg Exp $");
#endif
/*-
@@ -660,7 +660,7 @@
if ((eq=strchr(argv[0], '=')) == NULL)
usage();
- variable = malloc(eq-argv[0]+1);
+ variable = xmalloc(eq-argv[0]+1);
strlcpy(variable, argv[0], eq-argv[0]+1);
arg.variable = variable;
Home |
Main Index |
Thread Index |
Old Index