From owner-p4-projects@FreeBSD.ORG Tue Jun 23 19:53:07 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C1D701065674; Tue, 23 Jun 2009 19:53:06 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 65DD9106564A for ; Tue, 23 Jun 2009 19:53:06 +0000 (UTC) (envelope-from dforsyth@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 5360E8FC19 for ; Tue, 23 Jun 2009 19:53:06 +0000 (UTC) (envelope-from dforsyth@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n5NJr5Z9052904 for ; Tue, 23 Jun 2009 19:53:06 GMT (envelope-from dforsyth@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n5NJr55U052902 for perforce@freebsd.org; Tue, 23 Jun 2009 19:53:05 GMT (envelope-from dforsyth@FreeBSD.org) Date: Tue, 23 Jun 2009 19:53:05 GMT Message-Id: <200906231953.n5NJr55U052902@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to dforsyth@FreeBSD.org using -f From: David Forsythe To: Perforce Change Reviews Cc: Subject: PERFORCE change 164990 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jun 2009 19:53:07 -0000 http://perforce.freebsd.org/chv.cgi?CH=164990 Change 164990 by dforsyth@squirrel on 2009/06/23 19:52:40 Duplicate passed strings rather than assuming that the client will always pass truly constant strings. Affected files ... .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#25 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_cfl.c#4 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_dep.c#5 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_dep.h#5 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#6 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.h#5 edit .. //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#20 edit Differences ... ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg.h#25 (text+ko) ==== @@ -53,6 +53,12 @@ #define PARSE_OK 0x00000000 #define PARSE_FAIL 0x10000000 +/* TODO: All these explicit functions are great, but the client doesn't + * need to make a "new" pkg_cfl, when all they really have to insert are a + * sting and an integer (they dont even have to set the int). So write + * some functions that give them ways to make these entities with a single + * call. */ + /* pkg_file */ struct pkg_file; ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_cfl.c#4 (text+ko) ==== @@ -26,7 +26,8 @@ if (pc == NULL) arg_rage_quit(__func__, "Not a valid conflict.", RAGE_AT_LIBPKG); - pc->name = strdup(name); + free(pc->name); + pc->name = (name == NULL) ? NULL : strdup(name); return ((pc->name == NULL) ? MEMORY_ERR | NOT_OK : OK); } ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_dep.c#5 (text+ko) ==== @@ -1,5 +1,6 @@ #include #include +#include #include "pkg_dep.h" #include "pkg.h" @@ -20,7 +21,8 @@ if (pd == NULL) return (NULL); - pd->name = name; + free(pd->name); + pd->name = (name != NULL ? strdup(name) : NULL); return (pd); } @@ -30,8 +32,9 @@ { if (pd == NULL) return (NULL); - - pd->origin = origin; + + free(pd->origin); + pd->origin = (origin != NULL ? strdup(origin) : NULL); return (pd); } ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_dep.h#5 (text+ko) ==== @@ -6,8 +6,8 @@ #include struct pkg_dep { - const char *name; - const char *origin; + char *name; + char *origin; int version; ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.c#6 (text+ko) ==== @@ -1,5 +1,6 @@ #include #include +#include #include "pkg_file.h" #include "pkg.h" @@ -70,8 +71,9 @@ { if (pf == NULL) return (NOT_OK); - - pf->md5 = md5; + + free(pf->md5); + pf->md5 = (md5 != NULL ? strdup(md5) : NULL); return (OK); } @@ -80,8 +82,9 @@ { if (pf == NULL) return (NOT_OK); - - pf->path = path; + + free(pf->path); + pf->path = (path != NULL ? strdup(path) : NULL); return (OK); } @@ -91,7 +94,8 @@ if (pf == NULL) return (NOT_OK); - pf->owner = owner; + free(pf->owner); + pf->owner = (owner != NULL ? strdup(owner) : NULL); return (OK); } @@ -100,8 +104,9 @@ { if (pf == NULL) return (NOT_OK); - - pf->group = group; + + free(pf->group); + pf->group = (group != NULL ? strdup(group) : NULL); return (OK); } @@ -110,7 +115,8 @@ { if (pf == NULL) return (NOT_OK); - - pf->mode = mode; + + free(pf->mode); + pf->mode = (mode != NULL ? strdup(mode) : NULL); return (OK); } ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_file.h#5 (text+ko) ==== @@ -6,11 +6,11 @@ #include struct pkg_file { - const char *path; - const char *md5; - const char *owner; - const char *group; - const char *mode; + char *path; + char *md5; + char *owner; + char *group; + char *mode; TAILQ_ENTRY(pkg_file) next; }; ==== //depot/projects/soc2009/dforsyth_libpkg/libpkg/pkg_plist.c#20 (text+ko) ==== @@ -118,8 +118,6 @@ textp = strdup(text); if (textp == NULL) return (MEMORY_ERR); - /* Once parsed this is actually a leak because we lose track of the - * commands. */ pl->text = textp; @@ -153,7 +151,8 @@ textp = p + 1; } } - + + free(textp); pl->parsed = 1; return (OK);