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

Re: [PATCH 2/2] connect: improve check for plink to reduce false positives

From
Jeff King <peff@peff.net>
Date
Apr 23, 2015, 15:53 UTC
Message-ID
<20150423155304.GA26018@peff.net>
In-Reply-To
<b6b4da1f7735b834043375e3d8eaa331@www.dscho.org>
On Thu, Apr 23, 2015 at 08:50:17AM +0200, Johannes Schindelin wrote:
Show 9 quoted lines
> > +				tortoiseplink = tplink == ssh ||
> > +					(tplink && is_dir_sep(tplink[-1]));
> 
> Maybe have a helper function here? Something like
> `basename_matches(const char *path, const char *basename, int
> ignore_case)`? That would be easier to read (I have to admit that I
> had to wrap my head around the logic to ensure that tplink[-1] is
> valid; It is, but it requires more brain cycles to verify than I would
> like).
Yeah, I had a similar thought when reading the patch.
Show 5 quoted lines
> Also, I am really hesitant to just test the start of the basename; I
> would rather have an entire basename match so that something  like
> "PLinKoeln" would not match. (And of course, for Windows I would want
> that hypothetical `basename_matches()` function to allow basenames to
> end in `.exe` automatically).

What about "plink-0.83" that was mentioned earlier in the thread? I think that is the reason brian's patch stuck to matching the start and not the end. But I have no idea if that is actually a real thing, or just a hypothetical.

If I were writing from scratch, I would probably keep things as tight as possible, like:

  const char *base = basename(ssh);
  plink = !strcasecmp(base, "plink") ||
          !strcasecmp(base, "plink.exe");
  tplink = !strcasecmp(base, "tortoiseplink") ||
           !strcasecmp(base, "tortoiseplink.exe"));

but maybe that is too tight at this point in time; we don't really know what's out there and working (or maybe _we_ do, but _I_ do not :) ).

At any rate, brian's patch only looks for a dir-separator anywhere, not the actual basename. So:

  /path/to/plink/ssh

would match, and I'm not sure if that's a good thing or not. So yet another variant is to use basename(), and then just check that the basename starts with "plink" (to catch "plink.exe", "plink-0.83", etc). That avoids cruft in the intermediate path, and unless your actual binary is named PlinKoeln, it will not false positive on the example you gave.

-Peff
Previous: Johannes SchindelinNext: brian m. carlson
Message 14 of 41 in “[BUG] having 'plink' anywhere in the GIT_SSH environment variables sets putty = true”
  1. Patrick SharpApr 22, 2015
  2. Johannes SchindelinApr 22, 2015
  3. Patrick SharpApr 22, 2015
  4. Jeff KingApr 22, 2015
  5. brian m. carlsonApr 22, 2015
  6. Jeff KingApr 22, 2015
  7. brian m. carlsonApr 22, 2015
  8. Jeff KingApr 22, 2015
  9. brian m. carlsonApr 22, 2015
  10. Jeff KingApr 22, 2015
  11. 1/2 connect: simplify SSH connection code pathbrian m. carlson, Apr 23, 2015
  12. 2/2 connect: improve check for plink to reduce false positivesbrian m. carlson, Apr 23, 2015
  13. Johannes SchindelinApr 23, 2015
  14. Jeff KingApr 23, 2015
  15. brian m. carlsonApr 23, 2015
  16. Johannes SchindelinApr 24, 2015
  17. 1/2 connect: simplify SSH connection code pathbrian m. carlson, Apr 24, 2015
  18. 2/2 connect: improve check for plink to reduce false positivesbrian m. carlson, Apr 24, 2015
  19. Pete HarlanApr 24, 2015
  20. brian m. carlsonApr 24, 2015
  21. Torsten BögershausenApr 25, 2015
  22. brian m. carlsonApr 26, 2015
  23. 0/3 Improve robustness of putty detectionbrian m. carlson, Apr 26, 2015
  24. 1/3 connect: simplify SSH connection code pathbrian m. carlson, Apr 26, 2015
  25. 2/3 t5601: fix quotation error leading to skipped testsbrian m. carlson, Apr 26, 2015
  26. 3/3 connect: improve check for plink to reduce false positivesbrian m. carlson, Apr 26, 2015
  27. Johannes SchindelinApr 27, 2015
  28. Jeff KingApr 28, 2015
  29. Jeff KingJun 26, 2015
  30. Junio C HamanoJun 26, 2015
  31. Jeff KingJun 26, 2015
  32. Johannes SchindelinJun 26, 2015
  33. Jeff KingJun 26, 2015
  34. brian m. carlsonJun 26, 2015
  35. Junio C HamanoApr 26, 2015
  36. Torsten BögershausenApr 27, 2015
  37. Jeff KingApr 28, 2015
  38. brian m. carlsonApr 29, 2015
  39. Johannes SchindelinApr 24, 2015
  40. Torsten BögershausenApr 23, 2015
  41. Patrick SharpApr 23, 2015

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.