From 3052dea7c0870844dd13f585ca31105d7f0783c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag-Erling=20Sm=C3=B8rgrav?= Date: Sun, 1 Apr 2012 21:04:44 +0000 Subject: [PATCH] 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 --- lib/openpam_readword.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/openpam_readword.c b/lib/openpam_readword.c index 8a78e9c..15654a5 100644 --- a/lib/openpam_readword.c +++ b/lib/openpam_readword.c @@ -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;