From e223cca4f66bf2e201b21869304dc63befbbf9be Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sun, 20 Mar 2016 11:13:21 -0700 Subject: basename: fix segfault on null input; add tests When passed an empty string, glibc's basename() returns a pointer to the string "." in read-only memory. If an empty suffix is given, it fits the condition of being shorter than the path, so we try to overwrite the null byte and crash. Fix this by just ignoring empty suffixes; they don't do anything anyway. --- tests/basename.test | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests/basename.test') diff --git a/tests/basename.test b/tests/basename.test index 9d3b2961..ab2cc20a 100755 --- a/tests/basename.test +++ b/tests/basename.test @@ -21,3 +21,6 @@ testing "reappearing suffix 2" "basename a.txt.old .txt" "a.txt.old\n" "" "" # A suffix should be a real suffix, only a the end. testing "invalid suffix" "basename isthisasuffix? suffix" "isthisasuffix?\n" "" "" + +# Zero-length suffix +testing "zero-length suffix" "basename a/b/c ''" "c\n" "" "" -- cgit v1.2.3