From 34cb65ce5d92d4d1e86b9bb18ce09a38c8d72cca Mon Sep 17 00:00:00 2001 From: Andrey Vagin Date: Fri, 17 Jul 2015 17:40:22 +0300 Subject: [PATCH] mount: handle a case when a source argument is empty (v2) For example: mount -t tmpfs "" test v2: don't leak memory Reported-by: Ross Boucher Signed-off-by: Andrey Vagin Signed-off-by: Pavel Emelyanov --- proc_parse.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/proc_parse.c b/proc_parse.c index e940fc143..19bc620b5 100644 --- a/proc_parse.c +++ b/proc_parse.c @@ -1024,8 +1024,15 @@ static int parse_mountinfo_ent(char *str, struct mount_info *new, char **fsname) str += n; ret = sscanf(str, "%ms %ms %ms", fsname, &new->source, &opt); - if (ret != 3) + if (ret == 2) { + /* src may be empty */ + opt = new->source; + new->source = xstrdup(""); + if (new->source == NULL) + goto err; + } else if (ret != 3) goto err; + /* * The kernel reports "subtypes" sometimes and the valid * type-vs-subtype delimiter is the dot symbol. We disregard