Bug in sftp's chmod

Michail Pishchagin mailfrom at mail.ru
Tue Oct 26 02:02:03 EST 2004


On 25.10.2004, at 19:42, Michail Pishchagin wrote:
> I've discovered that on OpenSSH_3.6.1p1 (the latest SSH available on 
> OSX, but I've also tried a couple of different linux distributions), 
> when you 'sftp' to it, and try to 'chmod' some file or directory, only 
> last three octal digits do actually matter.

I think I've found it (read the inline comments):

process_setstat(void)
{
    Attrib *a;
    u_int32_t id;
    char *name;
    int status = SSH2_FX_OK, ret;

    id = get_int();
    name = get_string(NULL);
    a = get_attrib();
    TRACE("setstat id %u name %s", id, name);
    if (a->flags & SSH2_FILEXFER_ATTR_SIZE) {
        ret = truncate(name, a->size);
        if (ret == -1)
            status = errno_to_portable(errno);
    }
    if (a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS) {
        ret = chmod(name, a->perm & 0777);
//                                  ^^^^
// This is plain wrong. You should be doing "perm & 07777" instead :)
// Same bug in process_fsetstat.

        if (ret == -1)
            status = errno_to_portable(errno);
    }
    if (a->flags & SSH2_FILEXFER_ATTR_ACMODTIME) {
        ret = utimes(name, attrib_to_tv(a));
        if (ret == -1)
            status = errno_to_portable(errno);
    }
    if (a->flags & SSH2_FILEXFER_ATTR_UIDGID) {
        ret = chown(name, a->uid, a->gid);
        if (ret == -1)
            status = errno_to_portable(errno);
    }
    send_status(id, status);
    xfree(name);
}

Also, yet another bug :)

You seem to ignore the SSH2_FXF_APPEND flag in process_open() function. 
If this flag is set, you should seek to the end of file. At the present 
time, appending files effectively doesn't work, which is bad.

Thank you for your hard work bringing us OpenSSH, and keep it up ;-)

> PS: I'm not subscribed, please CC me on reply.
-mblsha




More information about the openssh-unix-dev mailing list