diff options
author | Dale Rahn <drahn@cvs.openbsd.org> | 2003-11-11 14:51:02 +0000 |
---|---|---|
committer | Dale Rahn <drahn@cvs.openbsd.org> | 2003-11-11 14:51:02 +0000 |
commit | 47ac571b28414165099b6642cff5a275d8abf9ab (patch) | |
tree | 06216acf13137243216f9fcbe1244650fcfdc82b | |
parent | e4fe4057bcd01bb2b4dc2ba258e532eec9419b9e (diff) |
Better fix to the library name parsing. now correctly handles
libpython2.2.so.0.0 vs libpython2.1.so.0.0. Clean up a potential
memory leak if the filename is not a valid library.
ok brad@
-rw-r--r-- | libexec/ld.so/sod.c | 26 | ||||
-rw-r--r-- | libexec/ld.so/util.h | 20 |
2 files changed, 30 insertions, 16 deletions
diff --git a/libexec/ld.so/sod.c b/libexec/ld.so/sod.c index 2c709265ef5..74e3f031f43 100644 --- a/libexec/ld.so/sod.c +++ b/libexec/ld.so/sod.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sod.c,v 1.19 2003/10/26 23:23:12 drahn Exp $ */ +/* $OpenBSD: sod.c,v 1.20 2003/11/11 14:51:01 drahn Exp $ */ /* * Copyright (c) 1993 Paul Kranenburg @@ -69,40 +69,36 @@ _dl_build_sod(const char *name, struct sod *sodp) /* does it look like /^lib/ ? */ if (_dl_strncmp((char *)sodp->sod_name, "lib", 3) != 0) - return; + goto backout; /* is this a filename? */ if (_dl_strchr((char *)sodp->sod_name, '/')) - return; + goto backout; /* skip over 'lib' */ cp = (char *)sodp->sod_name + 3; + realname = cp; + /* dot guardian */ if ((_dl_strchr(cp, '.') == NULL) || (*(cp+_dl_strlen(cp)-1) == '.')) - return; + goto backout; + + cp = _dl_strstr(cp, ".so"); + if (cp == NULL) + goto backout; /* default */ major = minor = -1; - realname = NULL; /* loop through name - parse skipping name */ for (tuplet = 0; (tok = strsep(&cp, ".")) != NULL; tuplet++) { switch (tuplet) { case 0: - /* removed 'lib' and extensions from name */ - realname = tok; + /* empty tok, we already skipped to "\.so.*" */ break; case 1: /* 'so' extension */ - if (_dl_strcmp(tok, "so") != 0) { - /* - * filenames such as libX-A.B.so.X.Y - * screw this up, decrement tuplet - * and try to continue. - */ - tuplet--; - } break; case 2: /* major version extension */ diff --git a/libexec/ld.so/util.h b/libexec/ld.so/util.h index 6a027480919..54b3fffc09b 100644 --- a/libexec/ld.so/util.h +++ b/libexec/ld.so/util.h @@ -1,4 +1,4 @@ -/* $OpenBSD: util.h,v 1.16 2003/07/06 20:03:58 deraadt Exp $ */ +/* $OpenBSD: util.h,v 1.17 2003/11/11 14:51:01 drahn Exp $ */ /* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> @@ -144,4 +144,22 @@ _dl_strchr(const char *p, const int ch) /* NOTREACHED */ } +static inline char * +_dl_strstr(const char *s, const char *find) +{ + char c, sc; + size_t len; + if ((c = *find++) != 0) { + len = _dl_strlen(find); + do { + do { + if ((sc = *s++) == 0) + return (NULL); + } while (sc != c); + } while (_dl_strncmp(s, find, len) != 0); + s--; + } + return ((char *)s); +} + #endif /*__DL_UTIL_H__*/ |