diff options
author | Neal H. Walfield <[email protected]> | 2015-08-17 09:56:42 +0000 |
---|---|---|
committer | Neal H. Walfield <[email protected]> | 2015-08-20 12:16:24 +0000 |
commit | 827cc922d84d8113d4f13ebbed1314e03da5f7d2 (patch) | |
tree | 64589acc2ea9283826f3b17b270f15f0133c6f38 /common/iobuf.c | |
parent | common/iobuf.c: Flush the pipeline in iobuf_temp_to_buffer. (diff) | |
download | gnupg-827cc922d84d8113d4f13ebbed1314e03da5f7d2.tar.gz gnupg-827cc922d84d8113d4f13ebbed1314e03da5f7d2.zip |
common/iobuf.c: Buffered data should not be processed by new filters.
* common/iobuf.c (iobuf_push_filter2): If the pipeline is an output or
temp pipeline, the new filter shouldn't assume ownership of the old
head's internal buffer: the data was written before the filter was
added.
* common/t-iobuf.c (double_filter): New function.
(main): Add test cases for the above bug.
--
Signed-off-by: Neal H. Walfield <[email protected]>.
Diffstat (limited to 'common/iobuf.c')
-rw-r--r-- | common/iobuf.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/common/iobuf.c b/common/iobuf.c index e6b70a114..6d85124eb 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -1607,20 +1607,21 @@ iobuf_push_filter2 (iobuf_t a, /* make a write stream from a temp stream */ a->use = IOBUF_OUTPUT; - if (a->use == IOBUF_OUTPUT) - { /* allocate a fresh buffer for the - original stream */ - b->d.buf = xmalloc (a->d.size); - b->d.len = 0; - b->d.start = 0; - } - else - { /* allocate a fresh buffer for the new - stream */ - a->d.buf = xmalloc (a->d.size); - a->d.len = 0; - a->d.start = 0; - } + /* The new filter (A) gets a new buffer. + + If the pipeline is an output or temp pipeline, then giving the + buffer to the new filter means that data that was written before + the filter was pushed gets sent to the filter. That's clearly + wrong. + + If the pipeline is an input pipeline, then giving the buffer to + the new filter (A) means that data that has read from (B), but + not yet read from the pipeline won't be processed by the new + filter (A)! That's certainly not what we want. */ + a->d.buf = xmalloc (a->d.size); + a->d.len = 0; + a->d.start = 0; + /* disable nlimit for the new stream */ a->ntotal = b->ntotal + b->nbytes; a->nlimit = a->nbytes = 0; |