{"thread":{"id":"12324","subject":"[PATCH] rev-parse: fix potential bus error with --parseopt option spec handling","startedAt":"2008-02-26T04:07:39Z","lastAt":"2008-02-26T14:45:29Z","messageCount":3,"participants":["Jay Soffian","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"69960","messageId":"1203998859-86344-1-git-send-email-jaysoffian@gmail.com","threadId":"12324","inReplyTo":null,"subject":"[PATCH] rev-parse: fix potential bus error with --parseopt option spec handling","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-26T04:07:39Z","receivedAt":"2008-02-26T04:07:39Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"A non-empty line containing no spaces should be treated by --parseopt as\nan option group header, but was causing a bus error. Also added a test\nscript for rev-parse --parseopt.\n\nSigned-off-by: Jay Soffian <jaysoffian@gmail.com>\n---\ne.g.\n% printf \"foo\\n--\\noption-group-header\\n\" | git rev-parse --parseopt -- -h\nBus error\n\nWasn't sure whether to add the --parseopt test to t0040-parse-options.sh or\nt1500-rev-parse.sh. I ended up creating a new test script. Hopefully calling\nit out will increase the likelihood of it growing additional --parseopt tests.\n\n builtin-rev-parse.c           |    2 +-\n t/t1502-rev-parse-parseopt.sh |   43 +++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 44 insertions(+), 1 deletions(-)\n create mode 100755 t/t1502-rev-parse-parseopt.sh\n\ndiff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\nindex b9af1a5..90dbb9d 100644\n--- a/builtin-rev-parse.c\n+++ b/builtin-rev-parse.c\n@@ -315,7 +315,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)\n \t\ts = strchr(sb.buf, ' ');\n \t\tif (!s || *sb.buf == ' ') {\n \t\t\to->type = OPTION_GROUP;\n-\t\t\to->help = xstrdup(skipspaces(s));\n+\t\t\to->help = xstrdup(skipspaces(sb.buf));\n \t\t\tcontinue;\n \t\t}\n \ndiff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh\nnew file mode 100755\nindex 0000000..762af5f\n--- /dev/null\n+++ b/t/t1502-rev-parse-parseopt.sh\n@@ -0,0 +1,43 @@\n+#!/bin/sh\n+\n+test_description='test git rev-parse --parseopt'\n+. ./test-lib.sh\n+\n+cat > expect.err <<EOF\n+usage: some-command [options] <args>...\n+    \n+    some-command does foo and bar!\n+\n+    -h, --help            show the help\n+    --foo                 some nifty option --foo\n+    --bar ...             some cool option --bar with an argument\n+\n+An option group Header\n+    -C [...]              option C with an optional argument\n+\n+Extras\n+    --extra1              line above used to cause a segfault but no longer does\n+\n+EOF\n+\n+test_expect_success 'test --parseopt help output' '\n+\tgit rev-parse --parseopt -- -h 2> output.err <<EOF\n+some-command [options] <args>...\n+\n+some-command does foo and bar!\n+--\n+h,help    show the help\n+\n+foo       some nifty option --foo\n+bar=      some cool option --bar with an argument\n+\n+ An option group Header\n+C?        option C with an optional argument\n+\n+Extras\n+extra1    line above used to cause a segfault but no longer does\n+EOF\n+\tgit diff expect.err output.err\n+'\n+\n+test_done\n-- \n1.5.4.3.331.ga714\n"},{"id":"69978","messageId":"alpine.LSU.1.00.0802261126130.17164@racer.site","threadId":"12324","inReplyTo":"1203998859-86344-1-git-send-email-jaysoffian@gmail.com","subject":"Re: [PATCH] rev-parse: fix potential bus error with --parseopt option spec handling","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-02-26T11:26:41Z","receivedAt":"2008-02-26T11:26:41Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Mon, 25 Feb 2008, Jay Soffian wrote:\n\n> diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c\n> index b9af1a5..90dbb9d 100644\n> --- a/builtin-rev-parse.c\n> +++ b/builtin-rev-parse.c\n> @@ -315,7 +315,7 @@ static int cmd_parseopt(int argc, const char **argv, const char *prefix)\n>  \t\ts = strchr(sb.buf, ' ');\n>  \t\tif (!s || *sb.buf == ' ') {\n>  \t\t\to->type = OPTION_GROUP;\n> -\t\t\to->help = xstrdup(skipspaces(s));\n> +\t\t\to->help = xstrdup(skipspaces(sb.buf));\n\nLooks obviously correct, but I would have expected a SIGSEGV, not a \nSIGBUS.\n\nCiao,\nDscho\n"},{"id":"69997","messageId":"76718490802260645i8bd74b0mf643820f5cfb1aa0@mail.gmail.com","threadId":"12324","inReplyTo":"alpine.LSU.1.00.0802261126130.17164@racer.site","subject":"Re: [PATCH] rev-parse: fix potential bus error with --parseopt option spec handling","fromName":"Jay Soffian","fromEmail":"jaysoffian@gmail.com","sentAt":"2008-02-26T14:45:29Z","receivedAt":"2008-02-26T14:45:29Z","isPatch":true,"sender":{"key":"jaysoffian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/155970?v=4"},"body":"On Tue, Feb 26, 2008 at 6:26 AM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n>  Looks obviously correct, but I would have expected a SIGSEGV, not a\n>  SIGBUS.\n\nFor your entertainment only, the OS X crash log. [Please don't make\nfun of me for using tcsh, I'm been meaning to switch to bash for about\n10 years now. :-) ]\n\nProcess:         git [86324]\nPath:            /opt/git/bin/git\nIdentifier:      git\nVersion:         ??? (???)\nCode Type:       X86 (Native)\nParent Process:  tcsh [80929]\n\nDate/Time:       2008-02-25 23:05:42.717 -0500\nOS Version:      Mac OS X 10.5.2 (9C31)\nReport Version:  6\n\nException Type:  EXC_BAD_ACCESS (SIGBUS)\nException Codes: KERN_PROTECTION_FAILURE at 0x0000000000000000\nCrashed Thread:  0\n\nThread 0 Crashed:\n0   git                           \t0x000497f6 skipspaces + 6\n1   git                           \t0x00049b83 cmd_parseopt + 867\n2   git                           \t0x0004a355 cmd_rev_parse + 709\n3   git                           \t0x00001df0 handle_internal_command + 240\n4   git                           \t0x00001fff main + 191\n5   git                           \t0x00001876 start + 54\n\nThread 0 crashed with X86 Thread State (32-bit):\n  eax: 0x00000000  ebx: 0x0004982d  ecx: 0x00805a00  edx: 0x00000000\n  edi: 0x00000000  esi: 0x002006e0  ebp: 0xbffff308  esp: 0xbffff304\n   ss: 0x0000001f  efl: 0x00010246  eip: 0x000497f6   cs: 0x00000017\n   ds: 0x0000001f   es: 0x0000001f   fs: 0x00000000   gs: 0x00000037\n  cr2: 0x00000000\n\nBinary Images:\n    0x1000 -    0xcaffb +git ??? (???) /opt/git/bin/git\n  0x100000 -   0x12bffb  libcurl.4.dylib ??? (???)\n<54ada27deb3b4ff7043d8836264eca0d> /usr/lib/libcurl.4.dylib\n0x8fe00000 - 0x8fe2da53  dyld 96.2 (???)\n<7af47d3b00b2268947563c7fa8c59a07> /usr/lib/dyld\n0x9001b000 - 0x9001ffff  libmathCommon.A.dylib ??? (???)\n/usr/lib/system/libmathCommon.A.dylib\n0x90f51000 - 0x910b0ff3  libSystem.B.dylib ??? (???)\n<4899376234e55593b22fc370935f8cdf> /usr/lib/libSystem.B.dylib\n0x910fe000 - 0x9111cfff  libresolv.9.dylib ??? (???)\n<0629b6dcd71f4aac6a891cbe26253e85> /usr/lib/libresolv.9.dylib\n0x92898000 - 0x928a6ffd  libz.1.dylib ??? (???)\n<5ddd8539ae2ebfd8e7cc1c57525385c7> /usr/lib/libz.1.dylib\n0x92beb000 - 0x92bf2fe9  libgcc_s.1.dylib ??? (???)\n<f53c808e87d1184c0f9df63aef53ce0b> /usr/lib/libgcc_s.1.dylib\n0x93b48000 - 0x93bf8fff  edu.mit.Kerberos 6.0.12 (6.0.12)\n<9e98dfb4cde8b0510fdd972dc9fa1dc9>\n/System/Library/Frameworks/Kerberos.framework/Versions/A/Kerberos\n0x93c2c000 - 0x93d64ff7  libicucore.A.dylib ??? (???)\n<afcea652ff2ec36885b2c81c57d06d4c> /usr/lib/libicucore.A.dylib\n0x93d66000 - 0x93e98fef  com.apple.CoreFoundation 6.5.1 (476.10)\n<d5bed2688a5eea11a6dc3a3c5c17030e>\n/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation\n0x93ea9000 - 0x93f06ffb  libstdc++.6.dylib ??? (???)\n<04b812dcec670daa8b7d2852ab14be60> /usr/lib/libstdc++.6.dylib\n0x93f07000 - 0x93fe6fff  libobjc.A.dylib ??? (???)\n<a53206274b6c2d42691f677863f379ae> /usr/lib/libobjc.A.dylib\n0x95207000 - 0x95232fe7  libauto.dylib ??? (???)\n<42d8422dc23a18071869fdf7b5d8fab5> /usr/lib/libauto.dylib\n0x95773000 - 0x95825ffb  libcrypto.0.9.7.dylib ??? (???)\n<330b0e48e67faffc8c22dfc069ca7a47> /usr/lib/libcrypto.0.9.7.dylib\n0x95f15000 - 0x960e0ff7  com.apple.security 5.0.2 (33001)\n<0788969ffe7961153219be10786da436>\n/System/Library/Frameworks/Security.framework/Versions/A/Security\n0x961f4000 - 0x96218feb  libssl.0.9.7.dylib ??? (???)\n<acee7fc534674498dcac211318aa23e8> /usr/lib/libssl.0.9.7.dylib\n0x96790000 - 0x96884ff4  libiconv.2.dylib ??? (???)\n<c508c60fafca17824c0017b2e4369802> /usr/lib/libiconv.2.dylib\n0xfffe8000 - 0xfffebfff  libobjc.A.dylib ??? (???) /usr/lib/libobjc.A.dylib\n0xffff0000 - 0xffff1780  libSystem.B.dylib ??? (???) /usr/lib/libSystem.B.dylib\n"}]}