summaryrefslogtreecommitdiff
path: root/restore.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2012-04-20 21:27:24 +0200
committerHugo Mills <hugo@carfax.org.uk>2012-06-05 19:56:20 +0100
commit47f029cc8bcf5a03ef6ee939fcb64007aafa50c4 (patch)
tree834804c3cc9079b1308d0c12c7fcec73d4506628 /restore.c
parent6fc24e4a701397ca2bfc4bfc8dd5da813f9ab24d (diff)
restore: don't corrupt stack for a zero-length command-line argument
Given a zero-length directory name, the trailing-slash removal code would test dir_name[-1], and if it were found to be a slash, would set it to '\0'. Reviewed-by: Josef Bacik <josef@redhat.com>
Diffstat (limited to 'restore.c')
-rw-r--r--restore.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/restore.c b/restore.c
index 250c9d3c..26748324 100644
--- a/restore.c
+++ b/restore.c
@@ -849,11 +849,9 @@ int main(int argc, char **argv)
strncpy(dir_name, argv[optind + 1], 128);
/* Strip the trailing / on the dir name */
- while (1) {
- len = strlen(dir_name);
- if (dir_name[len - 1] != '/')
- break;
- dir_name[len - 1] = '\0';
+ len = strlen(dir_name);
+ while (len && dir_name[--len] == '/') {
+ dir_name[len] = '\0';
}
if (find_dir) {