[En-Nut-Discussion] HTTP password protection - better solution

Edwin van den Oetelaar edwin at oetelaar.com
Wed Aug 30 14:01:04 CEST 2006


Peter Sodermanns wrote:

> Hi Edwin,
>
> thanks for your critics.
> I agree that my solution is not so embedded-like and implemented your 
> proposal:
>
>
> auth.c:
> ---------------------------------------------------------------------
> /*!
>  * \brief Clear all authorization entries.
>  */
> int NutClearAuth(void)
> {
>     AUTHINFO *auth;
>     AUTHINFO *next;
>
>     auth = authList;
>     while (auth) {
>         next = auth->auth_next;
>         if (auth->auth_dirname) {
>             if (NutHeapFree((char *) auth->auth_dirname) == 0) {
>                 auth->auth_dirname = 0;
>             }
>         }
>         if (auth->auth_login) {
>             if (NutHeapFree((char *) auth->auth_login) == 0) {
>                 auth->auth_login = 0;
>             }
>         }
>         NutHeapFree(auth);
>         auth = next;
>     }
>     return 0;
> }
>
>
> /*!
>  * \brief Change name and/or password for an existing authorization 
> entry.
>  *
>  * \param dirname   Name of the directory to protect.
>  * \param oldlogin  Current login (name:password).
>  * \param newlogin  Changed login (name:password).
>  *
>  * \return 0 on success, -1 otherwise.
>  */
> int NutChangeAuth(CONST char *dirname, CONST char *oldlogin, CONST 
> char *newlogin)
> {
>     AUTHINFO *auth;
>
>     auth = (NutHttpAuthLookup(dirname, oldlogin));
>     if (auth) {
>         strcpy((char *) auth->auth_login, newlogin);


This is NOT OK! The size of your newlogin may be bigger then your 
oldlogin so this may overwrite unallocated memory!!

>         return 0;
>     } else {
>         return -1;
>     }
> }
>
>
> /*!
>  * \brief Register an authorization entry.
>  *
>  * Protect a specified directory from unauthorized access.
>  *
>  * \warning Directories not registered by this function are
>  *          accessible by anyone.
>  *
>  * \param dirname Name of the directory to protect.
>  *                Max length of dirname is 255 characters.
>  * \param login   Required login to access this directory. This
>  *                string must contain a user name, followed by
>  *                a colon followed by an uncrypted password.
>  *                Max length of login is 41 characters.
>  *
>  * \return 0 on success, -1 otherwise.
>  */
> int NutRegisterAuth(CONST char *dirname, CONST char *login)
> {
>     AUTHINFO *auth;
>
>     if ((auth = NutHeapAlloc(sizeof(AUTHINFO))) == 0)
>         return -1;
>     auth->auth_next = authList;
>     auth->auth_dirname = dirname;
>     auth->auth_login = login;
>     authList = auth;
>
>     return 0;
> }
> ------------

Whoops ! Where is the Allocating of memory done ? You copy a pointer 
without the contents, This will not work as expected !

> Development is an iterative process...
>
It sure is !

> Kind regards
>
>             Peter





More information about the En-Nut-Discussion mailing list