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:
parent
9a14604cd2
commit
3052dea7c0
1 changed files with 8 additions and 0 deletions
|
@ -85,6 +85,14 @@ openpam_readword(FILE *f, int *lineno, size_t *lenp)
|
||||||
} else if ((ch == '\'' || ch == '"') && !quote && !escape) {
|
} else if ((ch == '\'' || ch == '"') && !quote && !escape) {
|
||||||
/* begin quote */
|
/* begin quote */
|
||||||
quote = ch;
|
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) {
|
} else if (ch == quote && !escape) {
|
||||||
/* end quote */
|
/* end quote */
|
||||||
quote = 0;
|
quote = 0;
|
||||||
|
|
Loading…
Reference in a new issue