btrfs-progs: fix error checking in load_device_info
[platform/upstream/btrfs-progs.git] / cmds-restore.c
index 059fbf2..8fc8b2a 100644 (file)
@@ -1386,25 +1386,25 @@ const char * const cmd_restore_usage[] = {
        "btrfs restore [options] <device> <path> | -l <device>",
        "Try to restore files from a damaged filesystem (unmounted)",
        "",
-       "-s              get snapshots",
-       "-x              get extended attributes",
-       "-m|--metadata   restore owner, mode and times",
-       "-S|--symlinks   restore symbolic links"
-       "-v              verbose",
-       "-i              ignore errors",
-       "-o              overwrite",
-       "-t <bytenr>     tree location",
-       "-f <bytenr>     filesystem location",
-       "-u <mirror>     super mirror",
-       "-r <rootid>     root objectid",
-       "-d              find dir",
-       "-l              list tree roots",
-       "-D|--dry-run    dry run (only list files that would be recovered)",
+       "-s|--snapshots       get snapshots",
+       "-x|--xattr           get extended attributes",
+       "-m|--metadata        restore owner, mode and times",
+       "-S|--symlinks        restore symbolic links",
+       "-v|--verbose         verbose",
+       "-i|--ignore-errors   ignore errors",
+       "-o|--overwrite       overwrite",
+       "-t <bytenr>          tree location",
+       "-f <bytenr>          filesystem location",
+       "-u|--super <mirror>  super mirror",
+       "-r|--root <rootid>   root objectid",
+       "-d                   find dir",
+       "-l|--list-roots      list tree roots",
+       "-D|--dry-run         dry run (only list files that would be recovered)",
        "--path-regex <regex>",
-       "                restore only filenames matching regex,",
-       "                you have to use following syntax (possibly quoted):",
-       "                ^/(|home(|/username(|/Desktop(|/.*))))$",
-       "-c              ignore case (--path-regex only)",
+       "                     restore only filenames matching regex,",
+       "                     you have to use following syntax (possibly quoted):",
+       "                     ^/(|home(|/username(|/Desktop(|/.*))))$",
+       "-c                   ignore case (--path-regex only)",
        NULL
 };
 
@@ -1412,7 +1412,7 @@ int cmd_restore(int argc, char **argv)
 {
        struct btrfs_root *root;
        struct btrfs_key key;
-       char dir_name[128];
+       char dir_name[PATH_MAX];
        u64 tree_location = 0;
        u64 fs_location = 0;
        u64 root_objectid = 0;
@@ -1433,6 +1433,14 @@ int cmd_restore(int argc, char **argv)
                        { "dry-run", no_argument, NULL, 'D'},
                        { "metadata", no_argument, NULL, 'm'},
                        { "symlinks", no_argument, NULL, 'S'},
+                       { "snapshots", no_argument, NULL, 's'},
+                       { "xattr", no_argument, NULL, 'x'},
+                       { "verbose", no_argument, NULL, 'v'},
+                       { "ignore-errors", no_argument, NULL, 'i'},
+                       { "overwrite", no_argument, NULL, 'o'},
+                       { "super", required_argument, NULL, 'u'},
+                       { "root", required_argument, NULL, 'r'},
+                       { "list-roots", no_argument, NULL, 'l'},
                        { NULL, 0, NULL, 0}
                };
 
@@ -1544,6 +1552,11 @@ int cmd_restore(int argc, char **argv)
 
        memset(path_name, 0, PATH_MAX);
 
+       if (strlen(argv[optind + 1]) >= PATH_MAX) {
+               fprintf(stderr, "ERROR: path too long\n");
+               ret = 1;
+               goto out;
+       }
        strncpy(dir_name, argv[optind + 1], sizeof dir_name);
        dir_name[sizeof dir_name - 1] = 0;