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.


git-svn-id: svn+ssh://svn.openpam.org/svn/openpam/trunk@553 185d5e19-27fe-0310-9dcf-9bff6b9f3609
This commit is contained in:
Dag-Erling Smørgrav 2012-04-01 21:04:44 +00:00
parent 9a14604cd2
commit 3052dea7c0
1 changed files with 8 additions and 0 deletions

View File

@ -85,6 +85,14 @@ openpam_readword(FILE *f, int *lineno, size_t *lenp)
} else if ((ch == '\'' || ch == '"') && !quote && !escape) {
/* begin quote */
quote = ch;
/* edge case: empty quoted string */
if (word == NULL && (word = malloc(1)) == NULL) {
openpam_log(PAM_LOG_ERROR, "malloc(): %m");
errno = ENOMEM;
return (NULL);
}
*word = '\0';
size = 1;
} else if (ch == quote && !escape) {
/* end quote */
quote = 0;