Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [Bug] modules zsh/tcp, zsh/zftp unloadable, probably affecting most modern Linuxes



Hi Phil,

thanks for the follow-up:

On 6/4/23 23:17, Philippe Troin wrote:
Interestingly:
    % zsh -f
    % echo $ZSH_VERSION
    5.9
    % rpm -q zsh
    zsh-5.9-5.fc38.x86_64
    % zmodload zsh/zftp
    zsh: failed to load module `zsh/zftp': /usr/lib64/zsh/5.9/zsh/zftp.so: undefined symbol: freehostent
    % autoload zfinit
    % zfinit
    % zmodload zsh/zftp
ah, ok, that's how it's supposed to work? Shouldn't the module then not trigger some warning or specific error on load, before the dynamic loader runs and fails?
freehostent is defined in zsh/net/tcp:

    % nm --dynamic /usr/lib64/zsh/5.9/zsh/net/tcp.so| grep freehostent
    00000000000027c0 T freehostent

Hui. Looking into tcp.c:197, that function is

---

/**/
mod_export void
freehostent(UNUSED(struct hostent *ptr))
{
}

---

Why is that not calling `free`? Oh, very simple, because above, the comment near the getipnodebyname implementation says:

---

/* note: this is not a complete implementation.  If ignores the flags,
   and does not provide the memory allocation of the standard interface.
   Each returned structure will overwrite the previous one. */

---

Ah, so we're exporting and thus overwriting a symbol that overwrites a pointer by the name of an existing libc function with a "overrides potentially unowned memory" one?

That sounds a tad undesirable in the grander scheme of things :)

Since the only use of this function pair (zsh_getipnodebyname, freehostent) is to be used internally in zfinit'ed modules, and the number of internal consumers is zftp.c, could I propose we just rename `freehostent` to `zsh_freehostent`? That would sound less invasive, and would at least send the next person not down the tracks looking for libc anachronisms (not blaming anyone but me for going down that road) ;-)

Since I think you're supposed to initialize zftp through zfinit, I do
not think this qualifies as a bug.
Hm, yeah, surprising to me, but probably documented somewhere well enough.
But the freehostent symbol in zsh/net/tcp.so feels a little funky.

I'd agree, see above

Cheers,
Marcus





Messages sorted by: Reverse Date, Date, Thread, Author