git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rev-parse: fix potential bus error with --parseopt option spec handling
@ 2008-02-26  4:07 Jay Soffian
  2008-02-26 11:26 ` Johannes Schindelin
  0 siblings, 1 reply; 3+ messages in thread
From: Jay Soffian @ 2008-02-26  4:07 UTC (permalink / raw)
  To: git; +Cc: Jay Soffian, Junio C Hamano, Johannes Schindelin

A non-empty line containing no spaces should be treated by --parseopt as
an option group header, but was causing a bus error. Also added a test
script for rev-parse --parseopt.

Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
e.g.
% printf "foo\n--\noption-group-header\n" | git rev-parse --parseopt -- -h
Bus error

Wasn't sure whether to add the --parseopt test to t0040-parse-options.sh or
t1500-rev-parse.sh. I ended up creating a new test script. Hopefully calling
it out will increase the likelihood of it growing additional --parseopt tests.

 builtin-rev-parse.c           |    2 +-
 t/t1502-rev-parse-parseopt.sh |   43 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 1 deletions(-)
 create mode 100755 t/t1502-rev-parse-parseopt.sh

diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index b9af1a5..90dbb9d 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -315,7 +315,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
 		s = strchr(sb.buf, ' ');
 		if (!s || *sb.buf == ' ') {
 			o->type = OPTION_GROUP;
-			o->help = xstrdup(skipspaces(s));
+			o->help = xstrdup(skipspaces(sb.buf));
 			continue;
 		}
 
diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh
new file mode 100755
index 0000000..762af5f
--- /dev/null
+++ b/t/t1502-rev-parse-parseopt.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+test_description='test git rev-parse --parseopt'
+. ./test-lib.sh
+
+cat > expect.err <<EOF
+usage: some-command [options] <args>...
+    
+    some-command does foo and bar!
+
+    -h, --help            show the help
+    --foo                 some nifty option --foo
+    --bar ...             some cool option --bar with an argument
+
+An option group Header
+    -C [...]              option C with an optional argument
+
+Extras
+    --extra1              line above used to cause a segfault but no longer does
+
+EOF
+
+test_expect_success 'test --parseopt help output' '
+	git rev-parse --parseopt -- -h 2> output.err <<EOF
+some-command [options] <args>...
+
+some-command does foo and bar!
+--
+h,help    show the help
+
+foo       some nifty option --foo
+bar=      some cool option --bar with an argument
+
+ An option group Header
+C?        option C with an optional argument
+
+Extras
+extra1    line above used to cause a segfault but no longer does
+EOF
+	git diff expect.err output.err
+'
+
+test_done
-- 
1.5.4.3.331.ga714

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rev-parse: fix potential bus error with --parseopt option spec handling
  2008-02-26  4:07 [PATCH] rev-parse: fix potential bus error with --parseopt option spec handling Jay Soffian
@ 2008-02-26 11:26 ` Johannes Schindelin
  2008-02-26 14:45   ` Jay Soffian
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Schindelin @ 2008-02-26 11:26 UTC (permalink / raw)
  To: Jay Soffian; +Cc: git, Junio C Hamano

Hi,

On Mon, 25 Feb 2008, Jay Soffian wrote:

> diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
> index b9af1a5..90dbb9d 100644
> --- a/builtin-rev-parse.c
> +++ b/builtin-rev-parse.c
> @@ -315,7 +315,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)
>  		s = strchr(sb.buf, ' ');
>  		if (!s || *sb.buf == ' ') {
>  			o->type = OPTION_GROUP;
> -			o->help = xstrdup(skipspaces(s));
> +			o->help = xstrdup(skipspaces(sb.buf));

Looks obviously correct, but I would have expected a SIGSEGV, not a 
SIGBUS.

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rev-parse: fix potential bus error with --parseopt option spec handling
  2008-02-26 11:26 ` Johannes Schindelin
@ 2008-02-26 14:45   ` Jay Soffian
  0 siblings, 0 replies; 3+ messages in thread
From: Jay Soffian @ 2008-02-26 14:45 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git, Junio C Hamano

On Tue, Feb 26, 2008 at 6:26 AM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
>  Looks obviously correct, but I would have expected a SIGSEGV, not a
>  SIGBUS.

For your entertainment only, the OS X crash log. [Please don't make
fun of me for using tcsh, I'm been meaning to switch to bash for about
10 years now. :-) ]

Process:         git [86324]
Path:            /opt/git/bin/git
Identifier:      git
Version:         ??? (???)
Code Type:       X86 (Native)
Parent Process:  tcsh [80929]

Date/Time:       2008-02-25 23:05:42.717 -0500
OS Version:      Mac OS X 10.5.2 (9C31)
Report Version:  6

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000
Crashed Thread:  0

Thread 0 Crashed:
0   git                           	0x000497f6 skipspaces + 6
1   git                           	0x00049b83 cmd_parseopt + 867
2   git                           	0x0004a355 cmd_rev_parse + 709
3   git                           	0x00001df0 handle_internal_command + 240
4   git                           	0x00001fff main + 191
5   git                           	0x00001876 start + 54

Thread 0 crashed with X86 Thread State (32-bit):
  eax: 0x00000000  ebx: 0x0004982d  ecx: 0x00805a00  edx: 0x00000000
  edi: 0x00000000  esi: 0x002006e0  ebp: 0xbffff308  esp: 0xbffff304
   ss: 0x0000001f  efl: 0x00010246  eip: 0x000497f6   cs: 0x00000017
   ds: 0x0000001f   es: 0x0000001f   fs: 0x00000000   gs: 0x00000037
  cr2: 0x00000000

Binary Images:
    0x1000 -    0xcaffb +git ??? (???) /opt/git/bin/git
  0x100000 -   0x12bffb  libcurl.4.dylib ??? (???)
<54ada27deb3b4ff7043d8836264eca0d> /usr/lib/libcurl.4.dylib
0x8fe00000 - 0x8fe2da53  dyld 96.2 (???)
<7af47d3b00b2268947563c7fa8c59a07> /usr/lib/dyld
0x9001b000 - 0x9001ffff  libmathCommon.A.dylib ??? (???)
/usr/lib/system/libmathCommon.A.dylib
0x90f51000 - 0x910b0ff3  libSystem.B.dylib ??? (???)
<4899376234e55593b22fc370935f8cdf> /usr/lib/libSystem.B.dylib
0x910fe000 - 0x9111cfff  libresolv.9.dylib ??? (???)
<0629b6dcd71f4aac6a891cbe26253e85> /usr/lib/libresolv.9.dylib
0x92898000 - 0x928a6ffd  libz.1.dylib ??? (???)
<5ddd8539ae2ebfd8e7cc1c57525385c7> /usr/lib/libz.1.dylib
0x92beb000 - 0x92bf2fe9  libgcc_s.1.dylib ??? (???)
<f53c808e87d1184c0f9df63aef53ce0b> /usr/lib/libgcc_s.1.dylib
0x93b48000 - 0x93bf8fff  edu.mit.Kerberos 6.0.12 (6.0.12)
<9e98dfb4cde8b0510fdd972dc9fa1dc9>
/System/Library/Frameworks/Kerberos.framework/Versions/A/Kerberos
0x93c2c000 - 0x93d64ff7  libicucore.A.dylib ??? (???)
<afcea652ff2ec36885b2c81c57d06d4c> /usr/lib/libicucore.A.dylib
0x93d66000 - 0x93e98fef  com.apple.CoreFoundation 6.5.1 (476.10)
<d5bed2688a5eea11a6dc3a3c5c17030e>
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
0x93ea9000 - 0x93f06ffb  libstdc++.6.dylib ??? (???)
<04b812dcec670daa8b7d2852ab14be60> /usr/lib/libstdc++.6.dylib
0x93f07000 - 0x93fe6fff  libobjc.A.dylib ??? (???)
<a53206274b6c2d42691f677863f379ae> /usr/lib/libobjc.A.dylib
0x95207000 - 0x95232fe7  libauto.dylib ??? (???)
<42d8422dc23a18071869fdf7b5d8fab5> /usr/lib/libauto.dylib
0x95773000 - 0x95825ffb  libcrypto.0.9.7.dylib ??? (???)
<330b0e48e67faffc8c22dfc069ca7a47> /usr/lib/libcrypto.0.9.7.dylib
0x95f15000 - 0x960e0ff7  com.apple.security 5.0.2 (33001)
<0788969ffe7961153219be10786da436>
/System/Library/Frameworks/Security.framework/Versions/A/Security
0x961f4000 - 0x96218feb  libssl.0.9.7.dylib ??? (???)
<acee7fc534674498dcac211318aa23e8> /usr/lib/libssl.0.9.7.dylib
0x96790000 - 0x96884ff4  libiconv.2.dylib ??? (???)
<c508c60fafca17824c0017b2e4369802> /usr/lib/libiconv.2.dylib
0xfffe8000 - 0xfffebfff  libobjc.A.dylib ??? (???) /usr/lib/libobjc.A.dylib
0xffff0000 - 0xffff1780  libSystem.B.dylib ??? (???) /usr/lib/libSystem.B.dylib

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-02-26 14:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-26  4:07 [PATCH] rev-parse: fix potential bus error with --parseopt option spec handling Jay Soffian
2008-02-26 11:26 ` Johannes Schindelin
2008-02-26 14:45   ` Jay Soffian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).