[4/5] util: fixup issubpath to handle sub-paths ending with slash

Submitted by Pavel Tikhomirov on Sept. 11, 2018, 8:09 a.m.

Details

Message ID 20180911080906.4555-5-ptikhomirov@virtuozzo.com
State Accepted
Series "minor fixes related to paths and logs"
Headers show

Commit Message

Pavel Tikhomirov Sept. 11, 2018, 8:09 a.m.
Before fix issubpath("./zdtm/static/mntns_shared_vs_private.test",
"./") returned false, though should return true.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 criu/include/util.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/include/util.h b/criu/include/util.h
index 5c18e69f7..dd280ec3a 100644
--- a/criu/include/util.h
+++ b/criu/include/util.h
@@ -206,12 +206,10 @@  int vaddr_to_pfn(int fd, unsigned long vaddr, u64 *pfn);
  */
 static inline bool strstartswith2(const char *str, const char *sub, char *end)
 {
-	const char *osub = sub;
-
 	while (1) {
 		if (*sub == '\0') /* end of sub -- match */ {
 			if (end) {
-				if (sub == osub + 1) /* pure root */
+				if (*(sub-1) == '/') /* "/", "./" or "path/" */
 					*end = '/';
 				else
 					*end = *str;