summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2015-08-28 10:22:39 +0200
committerWerner Koch <wk@gnupg.org>2015-08-28 10:22:39 +0200
commit5a52404c704d0e99629a2db79dda17e3b95c9680 (patch)
tree77a78eb338dafd130862907b477381f7ddefa140
parentd4bef26a49879761867ad6d57113341915db6acf (diff)
downloadlibassuan-5a52404c704d0e99629a2db79dda17e3b95c9680.tar.gz
Read up remaining lines in assuan_inquire after reaching MAXLEN
* src/assuan-inquire.c (assuan_inquire): Clear return args on error. Read up remaining lines after MAXLEN has been hit. -- If we would stop immediately at MAXLEN, as we did, the client would continue to send data which the server may consider as new Assuan commands. Signed-off-by: Werner Koch <wk@gnupg.org>
-rw-r--r--doc/assuan.texi4
-rw-r--r--src/assuan-inquire.c26
2 files changed, 19 insertions, 11 deletions
diff --git a/doc/assuan.texi b/doc/assuan.texi
index 1c3c2ca..14f2cf0 100644
--- a/doc/assuan.texi
+++ b/doc/assuan.texi
@@ -1763,8 +1763,8 @@ the required data (@var{keyword}). All other parameters may be
On success the result is stored in a newly allocated buffer stored at
@var{r_buffer}. The length of the data is stored at @var{r_length}.
-If @var{maxlen} has not been given as @code{0}, it describes an upper
-size limited of the expected data. If the client returns too much
+If @var{maxlen} has not been given as @code{0}, it specifies an upper
+size limit of the expected data. If the client returns too much
data the function fails and an error with the error code
@code{GPG_ERR_ASS_TOO_MUCH_DATA} will be returned.
@end deftypefun
diff --git a/src/assuan-inquire.c b/src/assuan-inquire.c
index a4cfc20..f863935 100644
--- a/src/assuan-inquire.c
+++ b/src/assuan-inquire.c
@@ -136,7 +136,7 @@ free_membuf (assuan_context_t ctx, struct membuf *mb)
* A server may use this to send an inquire. r_buffer, r_length and
* maxlen may all be NULL/0 to indicate that no real data is expected.
* The returned buffer is guaranteed to have an extra 0-byte after the
- * length. Thus it can be used as a string if embedded o bytes are
+ * length. Thus it can be used as a string if embedded 0 bytes are
* not an issue.
*
* Return value: 0 on success or an ASSUAN error code
@@ -152,6 +152,11 @@ assuan_inquire (assuan_context_t ctx, const char *keyword,
int linelen;
int nodataexpected;
+ if (r_buffer)
+ *r_buffer = NULL;
+ if (r_length)
+ *r_length = 0;
+
if (!ctx || !keyword || (10 + strlen (keyword) >= sizeof (cmdbuf)))
return _assuan_error (ctx, GPG_ERR_ASS_INV_VALUE);
nodataexpected = !r_buffer && !r_length && !maxlen;
@@ -212,6 +217,9 @@ assuan_inquire (assuan_context_t ctx, const char *keyword,
line += 2;
linelen -= 2;
+ if (mb.too_large)
+ continue; /* Need to read up the remaining data. */
+
p = line;
while (linelen)
{
@@ -229,18 +237,18 @@ assuan_inquire (assuan_context_t ctx, const char *keyword,
}
line = p;
}
- if (mb.too_large)
- {
- rc = _assuan_error (ctx, GPG_ERR_ASS_TOO_MUCH_DATA);
- goto out;
- }
}
if (!nodataexpected)
{
- *r_buffer = get_membuf (ctx, &mb, r_length);
- if (!*r_buffer)
- rc = _assuan_error (ctx, gpg_err_code_from_syserror ());
+ if (mb.too_large)
+ rc = _assuan_error (ctx, GPG_ERR_ASS_TOO_MUCH_DATA);
+ else
+ {
+ *r_buffer = get_membuf (ctx, &mb, r_length);
+ if (!*r_buffer)
+ rc = _assuan_error (ctx, gpg_err_code_from_syserror ());
+ }
}
out: