From: Tobias Brunner Date: Thu, 24 Jan 2013 17:43:10 +0000 (+0100) Subject: Properly read data from stream in pki --pkcs7 X-Git-Tag: 5.0.2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cd3fb788d0e0fe27f5f6fffe353d1792e6c6e08;p=thirdparty%2Fstrongswan.git Properly read data from stream in pki --pkcs7 --- diff --git a/src/pki/commands/pkcs7.c b/src/pki/commands/pkcs7.c index 9f167d3768..790656c62b 100644 --- a/src/pki/commands/pkcs7.c +++ b/src/pki/commands/pkcs7.c @@ -31,13 +31,16 @@ static chunk_t read_from_stream(FILE *stream) while (TRUE) { len = fread(buf + total, 1, sizeof(buf) - total, stream); - if (len < 0) + if (len < (sizeof(buf) - total)) { - return chunk_empty; - } - if (len == 0) - { - return chunk_clone(chunk_create(buf, total)); + if (ferror(stream)) + { + return chunk_empty; + } + if (feof(stream)) + { + return chunk_clone(chunk_create(buf, total + len)); + } } total += len; if (total == sizeof(buf))