Changeset 553 in openpam


Ignore:
Timestamp:
Apr 1, 2012, 9:04:44 PM (5 years ago)
Author:
Dag-Erling Smørgrav
Message:

Another bug uncovered by unit tests:

If the first character encountered is a quote, immediately allocate a
single byte. This way, if the word we've started reading is actually
an empty quoted string ( or ""), we correctly return an empty string
instead of NULL.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/openpam_readword.c

    r550 r553  
    8686                        /* begin quote */
    8787                        quote = ch;
     88                        /* edge case: empty quoted string */
     89                        if (word == NULL && (word = malloc(1)) == NULL) {
     90                                openpam_log(PAM_LOG_ERROR, "malloc(): %m");
     91                                errno = ENOMEM;
     92                                return (NULL);
     93                        }
     94                        *word = '\0';
     95                        size = 1;
    8896                } else if (ch == quote && !escape) {
    8997                        /* end quote */
Note: See TracChangeset for help on using the changeset viewer.