+2001-11-13 Robert Collins <rbtcollins@hotmail.com>
+
+ * choose.cc (find_tar_ext): Only match at the end of the string.
+ (getpkgbyname): Prevent NULL pointer dereference.
+
2001-11-13 Robert Collins <rbtcollins@hotmail.com>
* Makefile.in (CFLAGS): Add warnings and -Werr.
{
if (lines[n].get_category () || (lines[n].get_pkg ()
&& strcasecmp (line.get_pkg ()->name,
- lines[n].get_pkg ()->
- name) < 0))
+ lines[n].
+ get_pkg ()->name) < 0))
{
insert_at (n, line);
n = nlines;
int
find_tar_ext (const char *path)
{
+ char *end = strchr (path, '\0');
/* check in longest first order */
char *ext = strstr (path, ".tar.bz2");
if (ext)
- return ext - path;
+ return (end - ext) == 8 ? ext - path : 0;
if ((ext = strstr (path, ".tar.gz")));
- return ext - path;
+ return (end - ext) == 7 ? ext - path : 0;
if ((ext = strstr (path, ".tar")));
- return ext - path;
+ return (end - ext) == 4 ? ext - path : 0;
}
/* Parse a filename into package, version, and extension components. */
Package *
getpkgbyname (const char *pkgname)
{
- for (Package * pkg = package; pkg->name; pkg++)
+ for (Package * pkg = package; pkg && pkg->name; pkg++)
if (strcasecmp (pkg->name, pkgname) == 0)
return pkg;