NetBSD Problem Report #37031
From dholland@eecs.harvard.edu Wed Sep 26 20:59:28 2007
Return-Path: <dholland@eecs.harvard.edu>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
by narn.NetBSD.org (Postfix) with ESMTP id A8E7C63B8C2
for <gnats-bugs@gnats.NetBSD.org>; Wed, 26 Sep 2007 20:59:28 +0000 (UTC)
Message-Id: <20070926194410.CBAEAF8DD@tanaqui.eecs.harvard.edu>
Date: Wed, 26 Sep 2007 15:44:00 -0400 (EDT)
From: dholland@eecs.harvard.edu
Reply-To: dholland@eecs.harvard.edu
To: gnats-bugs@NetBSD.org
Subject: realloc failing in audit-packages
X-Send-Pr-Version: 3.95
>Number: 37031
>Category: pkg
>Synopsis: realloc failing in audit-packages
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: pkg-manager
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Sep 26 21:00:00 +0000 2007
>Closed-Date: Thu Sep 27 13:31:26 +0000 2007
>Last-Modified: Thu Sep 27 13:35:02 +0000 2007
>Originator: David A. Holland <dholland@eecs.harvard.edu>
>Release: NetBSD 2.1.0_STABLE
>Organization:
Harvard EECS
>Environment:
System: NetBSD bantha 2.1.0_STABLE NetBSD 2.1.0_STABLE (GENERIC) #3: Fri Dec 1 14:58:15 EST 2006 root@bantha:/usr/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386
>Description:
audit-packages from pkg_install-20070916 bombs with
audit-packages: mkver realloc failed: Cannot allocate memory
>How-To-Repeat:
Update, build, install, run.
>Fix:
The problem turns out to be that it's doubling the size of an array
every time it adds one element. So, don't do that.
Index: files/lib/dewey.c
===================================================================
RCS file: /cvsroot/pkgsrc/pkgtools/pkg_install/files/lib/dewey.c,v
retrieving revision 1.7
diff -u -p -r1.7 dewey.c
--- files/lib/dewey.c 16 Sep 2007 19:03:52 -0000 1.7
+++ files/lib/dewey.c 26 Sep 2007 19:09:07 -0000
@@ -110,6 +110,28 @@ dewey_mktest(int *op, const char *test)
}
/*
+ * add to arr_t
+ */
+static void
+addcomponent(arr_t *ap, int x)
+{
+ if (ap->c >= ap->size) {
+ if (ap->size == 0) {
+ ap->size = 62;
+ if ((ap->v = malloc(ap->size * sizeof(int))) == NULL)
+ err(EXIT_FAILURE, "mkver malloc failed");
+ } else {
+ ap->size *= 2;
+ if ((ap->v = realloc(ap->v, ap->size * sizeof(int)))
+ == NULL)
+ err(EXIT_FAILURE, "mkver realloc failed");
+ }
+ }
+
+ ap->v[ap->c++] = x;
+}
+
+/*
* make a component of a version number.
* '.' encodes as Dot which is '0'
* '_' encodes as 'patch level', or 'Dot', which is 0.
@@ -127,25 +149,16 @@ mkcomponent(arr_t *ap, const char *num)
int n;
const char *cp;
- if (ap->size == 0) {
- ap->size = 62;
- if ((ap->v = malloc(ap->size * sizeof(int))) == NULL)
- err(EXIT_FAILURE, "mkver malloc failed");
- } else {
- ap->size *= 2;
- if ((ap->v = realloc(ap->v, ap->size * sizeof(int))) == NULL)
- err(EXIT_FAILURE, "mkver realloc failed");
- }
if (isdigit((unsigned char)*num)) {
for (cp = num, n = 0 ; isdigit((unsigned char)*num) ; num++) {
n = (n * 10) + (*num - '0');
}
- ap->v[ap->c++] = n;
+ addcomponent(ap, n);
return (int)(num - cp);
}
for (modp = modifiers ; modp->s ; modp++) {
if (strncasecmp(num, modp->s, modp->len) == 0) {
- ap->v[ap->c++] = modp->t;
+ addcomponent(ap, modp->t);
return modp->len;
}
}
@@ -157,12 +170,9 @@ mkcomponent(arr_t *ap, const char *num)
return (int)(num - cp);
}
if (isalpha((unsigned char)*num)) {
- ap->v[ap->c++] = Dot;
+ addcomponent(ap, Dot);
cp = strchr(alphas, tolower((unsigned char)*num));
- ap->size *= 2;
- if ((ap->v = realloc(ap->v, ap->size * sizeof(int))) == NULL)
- err(EXIT_FAILURE, "mkver realloc failed");
- ap->v[ap->c++] = (int)(cp - alphas) + 1;
+ addcomponent(ap, (int)(cp - alphas) + 1);
return 1;
}
return 1;
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed
State-Changed-By: joerg@netbsd.org
State-Changed-When: Thu, 27 Sep 2007 13:31:26 +0000
State-Changed-Why:
Fixed with a different patch. Thanks.
From: Joerg Sonnenberger <joerg@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc:
Subject: PR/37031 CVS commit: pkgsrc/pkgtools/pkg_install
Date: Thu, 27 Sep 2007 13:30:28 +0000 (UTC)
Module Name: pkgsrc
Committed By: joerg
Date: Thu Sep 27 13:30:28 UTC 2007
Modified Files:
pkgsrc/pkgtools/pkg_install: Makefile
pkgsrc/pkgtools/pkg_install/files/lib: dewey.c version.h
Log Message:
- Be less aggressive when resizing the version field, just resize if
the old size is not enough. Fixes PR 37031.
- Disable dependency tracking in libarchive build. Supposed to address
PR 36953.
Bump version to 20070927.
To generate a diff of this commit:
cvs rdiff -r1.142 -r1.143 pkgsrc/pkgtools/pkg_install/Makefile
cvs rdiff -r1.7 -r1.8 pkgsrc/pkgtools/pkg_install/files/lib/dewey.c
cvs rdiff -r1.82 -r1.83 pkgsrc/pkgtools/pkg_install/files/lib/version.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.