Review main Merged

35959[TASK] Central function for escaping of shell-args

Stefan Neufeind CR +2 V +2 Normal +66 −85 updated 01/19/15, 22:34

Commit message

Instead of doing a (locale-aware) escaping in various
places use a central utility-function.

Review

  • Code review CR +2
    • Markus Klein +2
    • Christian Kuhn +1
    • Helmut Hummel +1
  • Verified V +2
    • Markus Klein +2
    • Christian Kuhn +1

Issues 1

Files 6

Review log 36

Show 11 earlier messages
  1. Stefan Neufeind uploaded patch set 1 01/11/15, 22:44

  2. Stefan Neufeind commented on patch set 1 01/11/15, 22:48

    Is this a direction we might want to go? Utility-class chosen okay? Static call okay? (We can't really instantiate it everywhere imho.) There are some other places that currently use escapeshellarg() where we might want to look if those places also turn to the locale-aware escaping-variant to be clean.

    LocalImageProcessor.php:109

    since it is @internal and not used inside the core anymore, imho we might consider to even remove it without deprecation
  3. Markus Klein commented on patch set 1 CR -1 01/11/15, 23:23

    BasicFileUtility is deprecated since ages. See note in header: Note: All methods in this class should not be used anymore since TYPO3 6.0.
  4. Stefan Neufeind commented on patch set 1 01/12/15, 01:01

    Overlooked that. Which Utility-class and what method-name would you propose maybe? I've also thought about the CommandUtility for a moment, since that relates to executing commands (and so also possibly command-/argument-escaping imho).
  5. Markus Klein commented on patch set 1 01/12/15, 09:07

    Yes I guess CommandUtil would be a better choice
  6. Stefan Neufeind uploaded patch set 2 01/17/15, 20:51

  7. Stefan Neufeind commented on patch set 2 01/17/15, 20:53

    now in CommandUtility and the BasicFileUtility is left untouched (since deprecated anyway)

    LocalImageProcessor.php:111

    since it is @internal and not used inside the core anymore, imho we might consider to even remove it without deprecation
  8. Mathias Schreiber commented on patch set 2 01/17/15, 21:30

    LocalPreviewHelper.php:62

    is there a technical reason you didn't import this one on top?
  9. Mathias Schreiber commented on patch set 2 CR +1 V +1 01/17/15, 22:07

    Scheduler.php:424

    Maybe shorten this (although not mandatory IMO)
  10. Stefan Neufeind commented on patch set 2 01/17/15, 22:08

    LocalPreviewHelper.php:62 Reply

    No, just because it was only used once. In the past we agreed to do it if something is used "a few times". But I don't mind. I just wanted to clear up the use-statements, since having Resource included and using Resource\File is afaik not what we usually do nowadays.
  11. Oliver Klee commented on patch set 2 01/18/15, 11:16

    Isn't this more of a [FEATURE]?

    CommandUtility.php:426

    shell-argument -< shell argument

    CommandUtility.php:430

    string|array -> string|string[]

    CommandUtility.php:431

    string|array -> string|string[]

    CommandUtility.php:445

    As we have this long check two time, maybe put it in a local variable $isUtf8FileSystem.

    Scheduler.php:424 Reply

    +1 as this would probably allow us to write the whole construct in a single line.
  1. Helmut Hummel commented on patch set 2 CR -1 01/18/15, 12:46

    LocalImageProcessor.php:111 Reply

    fine with me to directly remove it

    CommandUtility.php:114

    why is this changed to escapeshellcmd?

    CommandUtility.php:431 Reply

    I'd prefer not to have ambiguous return types, but only array() arguments and returns. A separate convenieve method could be added to handle the case for only one argument.

    CommandUtility.php:433

    "escapeShellArgumentLocal" does not make sense. It is "Locale" not "Local" but I would completely skip this suffix. And name it "escapeShellArguments"
  2. Oliver Klee commented on patch set 2 01/18/15, 12:51

    CommandUtility.php:431 Reply

    +1
  3. Stefan Neufeind commented on patch set 2 01/18/15, 12:55

    Reply

    nothing "really changes" so far imho, just a cleanup / merging things in one central location. If we later use it to add escaping to other parts which maybe were "forgotton" so far that could imho then even become a bugfix (since it fixes potentially security-relevant parts).

    CommandUtility.php:114 Reply

    There are separate functions for escaping a cmd and args. The correct one for calling gm is cmd here (though in real live I guess both will work).

    CommandUtility.php:433 Reply

    I originally stumbled across some parts where I thought me might need to escape there or not. But it was in FAL - and so I wanted to indicate we can only escape taking the "locale" into account for the *local* system. Fine with me to drop that suffix now.

    CommandUtility.php:445 Reply

    fine with me

    Scheduler.php:424 Reply

    But not in the other case of this patchset? Or shorten it in both places (since the files are small and we don't have too much use-statements yet)?
  4. Oliver Klee commented on patch set 2 01/18/15, 12:58

    Reply

    Then I'm for either BUGFIX or CLEANUP.

    Scheduler.php:424 Reply

    +1 for shortening both cases
  5. Oliver Klee commented on patch set 2 01/18/15, 12:59

    "shell-args" -> "shell arguments"
  6. Helmut Hummel commented on patch set 2 01/18/15, 13:00

    CommandUtility.php:114 Reply

    If there is no particular reason (besides the existence of the other function), please keep it like it was. IMHO there were good reasons to use escapeshellarg here and there should be other good reasons to change it.
  7. Stefan Neufeind uploaded patch set 3 01/18/15, 13:06

  8. Stefan Neufeind commented on patch set 3 01/18/15, 13:06

    all feedback taken into account
  9. Mathias Schreiber commented on patch set 3 01/18/15, 13:08

    LocalPreviewHelper.php:71

    missing s at a couple of places.
  10. Stefan Neufeind commented on patch set 3 01/18/15, 13:12

    LocalPreviewHelper.php:71 Reply

    Please see the function again! Helmut suggested to have one method which takes an array of strings and a separate "convenience method" for just one string. Since we escape just one string here, it doesn't have the plural.
  11. Helmut Hummel commented on patch set 3 CR -1 01/18/15, 13:19

    CommandUtility.php:114

    I still don't want to see this changed (unless someone comes up with good reasons)

    CommandUtility.php:433

    typehint array please

    CommandUtility.php:440

    this check will be obsolete then

    CommandUtility.php:463

    I would go for return self::escapeShellArguments(array($input))[0]; but I'm also fine with the additional variable
  12. Helmut Hummel commented on patch set 3 01/18/15, 13:21

    LocalPreviewHelper.php:71 Reply

    yes, it is fine like that
  13. Stefan Neufeind commented on patch set 3 01/18/15, 13:23

    CommandUtility.php:114 Reply

    Wrong function used at the moment imho. There exist two separate functions for two separate usecases - and we should use the proper one. But maybe somebody else could comment as well. (No offense, Helmut. I really appreciate your input here.)

    CommandUtility.php:433 Reply

    ack

    CommandUtility.php:440 Reply

    sure, sorry

    CommandUtility.php:463 Reply

    I wasn't exactly sure that works without an intermediate variable. If I remember right there was a problem in previous PHP-versions. But I tested it on a recent one and expect that 5.3+ should be fine with your suggested. Agreed, let's change that.
  14. Helmut Hummel commented on patch set 3 01/18/15, 13:36

    CommandUtility.php:114 Reply

    The name of the function is highly misleading and additionally escapeshellcmd() has a very limited use case. If we do not want to allow arbitrary arguments *and* want to be sure paths with spaces work properly, we *MUST* user escapeshellarg() here. Please do not change such crutial code if you do not know exactly why you're doing so. Thanks!
  15. Stefan Neufeind uploaded patch set 4 01/18/15, 13:42

  16. Oliver Klee voted on patch set 4 CR +1 01/18/15, 13:51

  17. Helmut Hummel voted on patch set 4 CR +2 01/18/15, 14:05

  18. Markus Klein voted on patch set 4 CR +1 01/19/15, 00:28

  19. Christian Kuhn commented on patch set 4 V -1 01/19/15, 22:21

    PHP Parse error: syntax error, unexpected ';' in /var/www/t3master/cms/typo3/sysext/core/Classes/Utility/CommandUtility.php on line 434
  20. Christian Kuhn uploaded patch set 5 01/19/15, 22:22

  21. Christian Kuhn voted on patch set 5 CR +1 V +1 01/19/15, 22:23

  22. Markus Klein voted on patch set 5 CR +1 01/19/15, 22:32

  23. Helmut Hummel voted on patch set 5 CR +1 01/19/15, 22:34

  24. Markus Klein voted on patch set 5 CR +2 V +2 01/19/15, 22:34

  25. Markus Klein merged patch set 5 01/19/15, 22:34