[CRIU] [PATCH 1/2] fix the wrong usage of strtok() in fsname_is_auto()

Oleg Nesterov oleg at redhat.com
Mon Apr 20 08:42:22 PDT 2015


I am stupid. fsname_is_auto() can't use strtok(), the 2nd call will
see zeroes instead of commas in fsauto_names.

Add the css_contains() helper and change fsname_is_auto() to use it.

Signed-off-by: Oleg Nesterov <oleg at redhat.com>
---
 mount.c |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/mount.c b/mount.c
index b47041d..970da99 100644
--- a/mount.c
+++ b/mount.c
@@ -1367,22 +1367,34 @@ static struct fstype fstypes[32] = {
 
 static char *fsauto_names;
 
-static bool fsname_is_auto(const char *name)
+static bool css_contains(const char *css, const char *str)
 {
-	const char *p;
+	int len = strlen(str);
+	const char *cur;
+
+	if (!len)
+		return false;
+
+	for (cur = css; (cur = strstr(cur, str)); cur += len) {
+		if (cur > css && cur[-1] != ',')
+			continue;
+		if (cur[len] && cur[len] != ',')
+			continue;
+		return true;
+	}
+
+	return false;
+}
 
+static bool fsname_is_auto(const char *name)
+{
 	if (!fsauto_names)
 		return false;
 
 	if (strcmp(fsauto_names, "all") == 0)
 		return true;
 
-	for (p = strtok(fsauto_names, ","); p; p = strtok(NULL, ",")) {
-		if (strcmp(name, p) == 0)
-			return true;
-	}
-
- 	return false;
+	return css_contains(fsauto_names, name);
 }
 
 bool add_fsname_auto(const char *names)
-- 
1.5.5.1



More information about the CRIU mailing list