git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Summary of core GIT while you are away.

From
Junio C Hamano <junkio@cox.net>
Date
May 27, 2005, 00:40 UTC
Message-ID
<7vsm097b6x.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<20050526235944.GB6215@vrfy.org>
>>>>> "KS" == Kay Sievers <kay.sievers@vrfy.org> writes:

KS> I see what you mean, but allow to pass any charater through a cgi to a KS> invoked shell as a command-line option is a nightmare without being very KS> carful.

You are absolutely right that you must be careful. But being careful is not that hard.

I do not know what you are using to parse the data coming from the browser (presumably application/x-www-form-urlencoded or somesuch), but once you got the raw data out of it in a variable in your host language (sorry I do not know what language you are writing in, either), quoting that value safely for shell command line is very simple and easy. You can emulate what sq_expand() in diff.c does.

Essentially you take advantage of single quote quoting which lets you pass anything other than single quotes as literals, and deal with single quotes by stepping out temporarily of the single quote environment every time you see a single quote, quote that single quote with a backslash, and immediately after that you go back into single quote environment again and continue.

  original     sq_expand     result
  name     ==> name      ==> 'name'
  a b      ==> a b       ==> 'a b'
  a'b      ==> a'\''b    ==> 'a'\''b'
So in shell, using sed, you would do something like this:

------------ #!/bin/sh

orig="foo '"'\bar b az'

script="s/'/'\\\\\\''/g" ;# change (') to ('\'')
sq_inside=`echo "$orig" | sed "$script"`

echo "'$sq_inside'" ;# and enclose the whole thing in sq pair ------------

Previous: Kay Sievers
Message 28 of 28 in “Summary of core GIT while you are away.”
  1. Junio C HamanoMay 14, 2005
  2. Linus TorvaldsMay 16, 2005
  3. rev-list/tree committer/author information.Junio C Hamano, May 16, 2005
  4. Petr BaudisMay 16, 2005
  5. Daniel BarkalowMay 16, 2005
  6. Junio C HamanoMay 16, 2005
  7. Petr BaudisMay 16, 2005
  8. Kay SieversMay 26, 2005
  9. Junio C HamanoMay 26, 2005
  10. Linus TorvaldsMay 26, 2005
  11. Linus TorvaldsMay 26, 2005
  12. Kay SieversMay 26, 2005
  13. Junio C HamanoMay 26, 2005
  14. Kay SieversMay 26, 2005
  15. Junio C HamanoMay 26, 2005
  16. H. Peter AnvinMay 27, 2005
  17. Junio C HamanoMay 27, 2005
  18. H. Peter AnvinMay 27, 2005
  19. Junio C HamanoMay 27, 2005
  20. H. Peter AnvinMay 27, 2005
  21. Junio C HamanoMay 27, 2005
  22. Linus TorvaldsMay 27, 2005
  23. H. Peter AnvinMay 26, 2005
  24. Junio C HamanoMay 26, 2005
  25. Kay SieversMay 26, 2005
  26. Junio C HamanoMay 27, 2005
  27. Kay SieversMay 27, 2005
  28. Junio C HamanoMay 27, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.