Skip to content

proxy-lookup.exe returns wrong result #3818

Closed
@miimou

Description

@miimou
  • I was not able to find an open or closed issue matching what I'm seeing

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
$ git --version --build-options
git version 2.36.0.windows.1
cpu: x86_64
built from commit: ea1e13f73339d57cbe81a0bae6fba669aaccf656
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
$ cmd.exe /c ver

Microsoft Windows [Version 10.0.19044.1645]
  • What options did you set as part of the installation? Or did you choose the
    defaults?
$ cat /etc/install-options.txt
Editor Option: VIM
Custom Editor Path:
Default Branch Option:
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behavior Option: Merge
Use Credential Manager: Enabled
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable Pseudo Console Support: Disabled
Enable FSMonitor: Disabled
  • Any other interesting things about your environment that might be related
    to the issue you're seeing?

    • As this issue occurs in proxy-lookup.exe, I have a proxy.pac set when I found this problem.

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

    • I am using Bash
  • What commands did you run to trigger this issue? If you can provide a
    Minimal, Complete, and Verifiable example
    this will help us understand the issue.

    • Make proxy.pac that specifies proxy for 192.168.0.0/24
      function FindProxyForURL(url, host) {
          if (isInNet(host, "192.168.0.0", "255.255.255.0")) {
          return "PROXY 192.168.0.1:8080";
          }
          return "DIRECT";
      }
    • Make it accessible via HTTP
      • for example, by Perl in Git Bash
        $ cd directory/that/have/proxy.pac/
        $ perl -MHTTP::Daemon -MHTTP::Status -e "my \$d=HTTP::Daemon->new(LocalPort=>3000);
          while(my \$c=\$d->accept){
            \$c->get_request;\$c->send_file_response('proxy.pac');
          \$c->close;undef(\$c)}"
        • Edited on April 30, 2022 for later reference,
          modified the code to close connection after sending file to avoid stall by Keep-Alive
    • Configure to use the proxy.pac
      • In "Local Area Network (LAN) Settings" > "Automatic configuration",
    • Use proxy-lookup.exe to lookup proxy for http://192.168.0.1/
      $ proxy-lookup.exe http://192.168.0.1/
      1
      $ proxy-lookup.exe -v http://192.168.0.1/
      URL: h, proxy: 1
  • What did you expect to occur after running these commands?

    $ proxy-lookup.exe http://192.168.0.1/
    192.168.0.1:8080
    $ proxy-lookup.exe -v http://192.168.0.1/
    URL: http://192.168.0.1/, proxy: 192.168.0.1:8080
  • What actually happened instead?

    $ proxy-lookup.exe http://192.168.0.1/
    1
    $ proxy-lookup.exe -v http://192.168.0.1/
    URL: h, proxy: 1

My thought

  • In proxy-lookup.c lines 83 and 85,
    format string used in wprintf for wide character string is %s, but it should be %ls.
  • Wide character string (UTF-16LE in Windows) is parsed as narrow string, causing characters at second and latter position to be stripped.
  • Changing like this worked in my environment.
     diff --git a/git-extra/proxy-lookup.c b/git-extra/proxy-lookup.c
     --- a/git-extra/proxy-lookup.c
     +++ b/git-extra/proxy-lookup.c
     @@ -80,9 +80,9 @@ int main(int argc, char **argv)
      			proxy = L"";
      
      			if (verbose)
     -				wprintf(L"URL: %s, proxy: %s\n", arg, proxy);
     +				wprintf(L"URL: %ls, proxy: %ls\n", arg, proxy);
      			else
     -				wprintf(L"%s\n", proxy);
     +				wprintf(L"%ls\n", proxy);
      		}
      
      		return 0;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions