]> www.infradead.org Git - mtd-utils.git/commitdiff
mkfs.ubifs: don't leak copied command line arguments
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Sun, 10 Nov 2019 12:41:41 +0000 (13:41 +0100)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Sun, 10 Nov 2019 14:29:53 +0000 (15:29 +0100)
For some command line flags, the argument string is copied. Simply
writing over the buffer leads to a resource leak if the same flag
is specified on the command line more than once.

This patch adds a free() call to the old buffer before overwriting
it with the new copy.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c

index bf1290f3e91a1687101f561a21358b0a7675c3a5..ea0afeefdeef2f3d592d475b61e141a7e8b8cf08 100644 (file)
@@ -580,6 +580,7 @@ static int get_options(int argc, char**argv)
                switch (opt) {
                case 'r':
                case 'd':
+                       free(root);
                        root_len = strlen(optarg);
                        root = xmalloc(root_len + 2);
 
@@ -726,6 +727,7 @@ static int get_options(int argc, char**argv)
                        do_create_inum_attr = 1;
                        break;
                case 's':
+                       free(context);
                        context_len = strlen(optarg);
                        context = (char *) xmalloc(context_len + 1);
                        if (!context)