aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2013-03-04 18:46:55 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2013-03-04 18:46:55 +0000
commit8a441b006240afe43bf29535b9111f19189b02cd (patch)
treee0624ce39900610dd6d5ac21bbf5fc06703c33d1
parentab43f156ee91d80e74b83b1d4aaf5d6897a23536 (diff)
downloadsrc-8a441b006240afe43bf29535b9111f19189b02cd.tar.gz
src-8a441b006240afe43bf29535b9111f19189b02cd.zip
Merge upstream r634:646: correctly parse mixed quoted / unquoted text.
Notes
Notes: svn path=/vendor/openpam/dist/; revision=247809
-rw-r--r--doc/man/openpam_straddch.321
-rw-r--r--lib/openpam_readline.c6
-rw-r--r--lib/openpam_readword.c7
3 files changed, 22 insertions, 12 deletions
diff --git a/doc/man/openpam_straddch.3 b/doc/man/openpam_straddch.3
index c55582477ed5..ea11c93b540b 100644
--- a/doc/man/openpam_straddch.3
+++ b/doc/man/openpam_straddch.3
@@ -34,7 +34,7 @@
.\"
.\" $Id$
.\"
-.Dd May 26, 2012
+.Dd March 3, 2013
.Dt OPENPAM_STRADDCH 3
.Os
.Sh NAME
@@ -73,6 +73,21 @@ and
argument point to variables used to hold the size
of the buffer and the length of the string it contains, respectively.
.Pp
+The final argument,
+.Fa ch ,
+is the character that should be appended to
+the string. If
+.Fa ch
+is 0, nothing is appended, but a new buffer is
+still allocated if
+.Fa str
+is NULL. This can be used to
+.Do
+bootstrap
+.Dc
+the
+string.
+.Pp
If a new buffer is allocated or an existing buffer is reallocated to
make room for the additional character,
.Fa str
@@ -91,7 +106,9 @@ If the
function is successful, it increments the
integer variable pointed to by
.Fa len
-and returns 0.
+(unless
+.Fa ch
+was 0) and returns 0.
Otherwise, it leaves the variables pointed to by
.Fa str ,
.Fa size
diff --git a/lib/openpam_readline.c b/lib/openpam_readline.c
index 014acfb2c1cf..047ab836910a 100644
--- a/lib/openpam_readline.c
+++ b/lib/openpam_readline.c
@@ -62,11 +62,9 @@ openpam_readline(FILE *f, int *lineno, size_t *lenp)
size_t len, size;
int ch;
- if ((line = malloc(size = MIN_LINE_LENGTH)) == NULL) {
- openpam_log(PAM_LOG_ERROR, "malloc(): %m");
+ line = NULL;
+ if (openpam_straddch(&line, &size, &len, 0) != 0)
return (NULL);
- }
- len = 0;
for (;;) {
ch = fgetc(f);
/* strip comment */
diff --git a/lib/openpam_readword.c b/lib/openpam_readword.c
index 74a4d462ce44..1c0e9b68149c 100644
--- a/lib/openpam_readword.c
+++ b/lib/openpam_readword.c
@@ -86,13 +86,8 @@ openpam_readword(FILE *f, int *lineno, size_t *lenp)
/* 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;
+ if (openpam_straddch(&word, &size, &len, 0) != 0)
return (NULL);
- }
- *word = '\0';
- size = 1;
} else if (ch == quote && !escape) {
/* end quote */
quote = 0;