summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Build/source/texk/kpathsea/ChangeLog5
-rw-r--r--Build/source/texk/kpathsea/db.c10
2 files changed, 15 insertions, 0 deletions
diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog
index c05a72df8f2..1cb0690e38c 100644
--- a/Build/source/texk/kpathsea/ChangeLog
+++ b/Build/source/texk/kpathsea/ChangeLog
@@ -1,3 +1,8 @@
+2017-11-18 Karl Berry <karl@tug.org>
+
+ * db.c (elt_in_db): protect against either argument being NULL or
+ empty. From Doug McKenna, personal mail, 17nov17.
+
2017-11-11 Akira Kakuto <kakuto@fuk.kindai.ac.jp>
* tex-file.c: Again use a custom kpathsea_getlongpath()
diff --git a/Build/source/texk/kpathsea/db.c b/Build/source/texk/kpathsea/db.c
index 16d4941d81e..fb4658c1968 100644
--- a/Build/source/texk/kpathsea/db.c
+++ b/Build/source/texk/kpathsea/db.c
@@ -296,6 +296,7 @@ match (const_string filename, const_string path_elt)
That is, the question is whether to try the db for a file looked up
in PATH_ELT. If PATH_ELT == ".", for example, the answer is no. If
PATH_ELT == "/usr/local/lib/texmf/fonts//tfm", the answer is yes.
+ If either string is NULL or empty, return false.
In practice, ls-R is only needed for lengthy subdirectory
comparisons, but there's no gain to checking PATH_ELT to see if it is
@@ -307,6 +308,15 @@ elt_in_db (const_string db_dir, const_string path_elt)
{
boolean found = false;
+ /* If both strings are empty or null return false on the grounds that
+ it's useless to do anything further with such a strange case (which
+ likely never happens). In theory one could argue that the empty
+ string is a prefix of any other string, but let's just declare the
+ result otherwise. */
+ if (db_dir == NULL || *db_dir == 0
+ || path_elt == NULL || *path_elt == 0)
+ return false;
+
while (!found && FILECHARCASEEQ (*db_dir++, *path_elt++)) {
/* If we've matched the entire db directory, it's good. */
if (*db_dir == 0)