Fixing “percent_expand: NULL replacement” SSH bug on OS X Leopard

Apple decided to fix up some of their UNIX functions to operate more like the standard, but they didn’t test very thoroughly because they broke the SSH client Update: Actually, this is a problem with MacPorts, Apple’s SSH still works (if you see “percent_expand: NULL replacement”, you’ve hit the bug). They’ll probably fix this, but if you need a quicker solution, here it is.

  1. Download the latest OpenSSH and untar it to the desktop (Link)
  2. Go into this directory and open up “ssh.c”
  3. Make the following patch near line 1252 (Leave out the ‘+’):
    Code Sample:

    #endif /* SMARTCARD */
           if ((pw = getpwuid(original_real_uid)) == NULL)
                   fatal("load_public_identity_files: getpwuid failed");
    +        pw = pwcopy(pw);
           if (gethostname(thishost, sizeof(thishost)) == -1)
                   fatal("load_public_identity_files: gethostname: %s",
                       strerror(errno));

  4. Open up the terminal, and run the following commands:
    Code Sample:

    cd ~/Desktop/openssh-4.7p1
    ./configure --exec-prefix=/usr/local  --prefix=/
    make
    sudo make install

Web 2.0, Go! These icons link to social bookmarking sites where readers can share and discover new web pages.
  • co.mments
  • del.icio.us
  • digg
  • Reddit
  • Shadows
  • YahooMyWeb

6 Comments »

  1. vulgarisoip said,

    October 29, 2007 @ 10:18 am

    Use the above instructions with the following configure command:

    ./configure --exec-prefix=/opt/local --prefix=/

    To overwrite broken MacPorts version

  2. Steve said,

    October 29, 2007 @ 5:02 pm

    An even quicker fix is to rename the ’scp’ and ’ssh’ binaries in /opt/local/bin, and symlink to the working Apple versions shipped with Leopard in /usr/bin.

    That way, programs like git that explicitly look for ssh in /opt/local/bin will continue to work.

    I’ll look at submitting a macports patch if nobody else has done so already.

  3. Steve said,

    October 30, 2007 @ 3:40 am

    Update: I’ve submitted a patch to MacPorts, so hopefully the issue will go away soon:

    http://trac.macosforge.org/projects/macports/ticket/13046

  4. Paul Betts said,

    October 30, 2007 @ 12:12 pm

    @vulgarisoip: Even better - when I wrote this article, I thought it was the Apple ssh that was broken, so that’s a better fix

    @steve: I didn’t want to suggest that, because I didn’t know the differences between Apple’s ssh and MacPorts’ ssh. Thanks for submitting the patch though, good work!

  5. Travis Vachon said,

    November 2, 2007 @ 8:55 pm

    An even nicer solution can be found here:

    http://www.nabble.com/ssh:-percent_expand:-NULL-replacement-t4701144.html

    Worked like a charm for me.

  6. fablamenas said,

    November 10, 2007 @ 9:48 am

    thanks for your help. I was crazy with that. I used the link provided by Travis Vachon… Easier to test first and worked fine… so far enough for me. thanks.

RSS feed for comments on this post · TrackBack URI

Leave a Comment