[PATCH] setup_revisions(): do not access outside argv

Subsystems: the rest

DORMANTno replies

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] setup_revisions(): do not access outside argv

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:46:48

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 revision.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/revision.c b/revision.c
index 18b7ebb..be1e307 100644
--- a/revision.c
+++ b/revision.c
@@ -1241,9 +1241,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 		if (strcmp(arg, "--"))
 			continue;
 		argv[i] = NULL;
-		argc = i;
-		if (argv[i + 1])
+		if (i + 1 < argc && argv[i + 1])
 			revs->prune_data = get_pathspec(revs->prefix, argv + i + 1);
+		argc = i;
 		seen_dashdash = 1;
 		break;
 	}
-- 
test

Re: [PATCH] setup_revisions(): do not access outside argv

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:46:48

Nguyễn Thái Ngọc Duy schrieb:
quoted hunk
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 revision.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/revision.c b/revision.c
index 18b7ebb..be1e307 100644
--- a/revision.c
+++ b/revision.c
@@ -1241,9 +1241,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
 		if (strcmp(arg, "--"))
 			continue;
 		argv[i] = NULL;
-		argc = i;
-		if (argv[i + 1])
+		if (i + 1 < argc && argv[i + 1])
 			revs->prune_data = get_pathspec(revs->prefix, argv + i + 1);
+		argc = i;
 		seen_dashdash = 1;
 		break;
 	}
Why is this necessary? I'd expect that argv arrays have NULL at the end.
If this is a bug, why did noboy notice this earlier? IOW, your commit
message is really lacking justification.

-- Hannes

Re: [PATCH] setup_revisions(): do not access outside argv

From: Nguyen Thai Ngoc Duy <hidden>
Date: 2016-06-15 22:46:48

2009/5/20 Johannes Sixt [off-list ref]:
Nguyễn Thái Ngọc Duy schrieb:
quoted
Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 revision.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/revision.c b/revision.c
index 18b7ebb..be1e307 100644
--- a/revision.c
+++ b/revision.c
@@ -1241,9 +1241,9 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
              if (strcmp(arg, "--"))
                      continue;
              argv[i] = NULL;
-             argc = i;
-             if (argv[i + 1])
+             if (i + 1 < argc && argv[i + 1])
                      revs->prune_data = get_pathspec(revs->prefix, argv + i + 1);
+             argc = i;
              seen_dashdash = 1;
              break;
      }
Why is this necessary? I'd expect that argv arrays have NULL at the end.
I have no idea. I hit this "bug" in my builtin-rebase.c and had that
question too. But I grepped through and saw that
at least verify_bundle() does not terminate argv with NULL. So I
assume that setup_revisions() does not expect NULL at the end.
-- 
Duy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help