Date: Tue, 23 Jun 2009 19:53:05 GMT From: David Forsythe <dforsyth@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 164990 for review Message-ID: <200906231953.n5NJr55U052902@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <stdio.h> #include <stdlib.h> +#include <string.h> #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 <sys/queue.h> 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 <stdio.h> #include <stdlib.h> +#include <string.h> #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 <sys/queue.h> 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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200906231953.n5NJr55U052902>