LibC status and others...

Matthew Dillon dillon at apollo.backplane.com
Wed Dec 10 17:09:18 PST 2003


:well, it took me less than 30 minutes...
:but it was really simple and is most likely not correct.
:
:but maybe it is, and this way, we could concentrate on something different.
:btw: if this looks right, i may tackle the other _r's tomorrow.
:
:~ibotty

    That's not going to quite work, but it was a good try!

    The issue is that the supplied buffer must be used to hold auxillary
    data... the pointers to pw_name, pw_passwd, and so forth in the
    struct passwd.

    This means that __hashpw() in the same file must be adjusted.  It
    uses a static u_int max and static char *line at the moment... instead
    the buffer and buffer size must be passed to hashpw() and it must
    properly return an error if the buffer is not large enough.

    getpwnam() must allocate a sufficiently sized buffer and deal with
    ERANGE.  ERANGE must be returned if the buffer is not sufficient.

    This is how FreeBSD-current deals with it.  I'm not saying copy this,
    because it's rather messy code, but just to demonstrate the problem...

        if (pwd_storage == NULL) {
                pwd_storage = malloc(PWD_STORAGE_INITIAL);
                if (pwd_storage == NULL)
                        return (NULL);
                pwd_storage_size = PWD_STORAGE_INITIAL;
        }
        do {
                rv = fn(key, &pwd, pwd_storage, pwd_storage_size, &res);
                if (res == NULL && rv == ERANGE) {
                        free(pwd_storage);
                        if ((pwd_storage_size << 1) > PWD_STORAGE_MAX) {
                                pwd_storage = NULL;
                                return (NULL);
                        }
                        pwd_storage_size <<= 1;
                        pwd_storage = malloc(pwd_storage_size);
                        if (pwd_storage == NULL)
                                return (NULL);
                }
        } while (res == NULL && rv == ERANGE);

    Would you like to try again?

					-Matt
					Matthew Dillon 
					<dillon at xxxxxxxxxxxxx>






More information about the Kernel mailing list