mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
* options.h, g10.c (main), plaintext.c (handle_plaintext): Add
--max-output option to help people deal with decompression bombs.
This commit is contained in:
parent
f3de3a5eb9
commit
6c13b96a1d
4 changed files with 81 additions and 23 deletions
|
@ -24,6 +24,7 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_DOSISH_SYSTEM
|
||||
#include <fcntl.h> /* for setmode() */
|
||||
#endif
|
||||
|
@ -52,6 +53,7 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
|
|||
{
|
||||
char *fname = NULL;
|
||||
FILE *fp = NULL;
|
||||
off_t count=0;
|
||||
int rc = 0;
|
||||
int c;
|
||||
int convert = pt->mode == 't';
|
||||
|
@ -164,14 +166,23 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
|
|||
if( c == '\r' ) /* convert to native line ending */
|
||||
continue; /* fixme: this hack might be too simple */
|
||||
#endif
|
||||
if( fp ) {
|
||||
if( putc( c, fp ) == EOF ) {
|
||||
if( fp )
|
||||
{
|
||||
if((count++)>opt.max_output)
|
||||
{
|
||||
log_error("Error writing to `%s': %s\n",
|
||||
fname,"exceeded --max-output limit\n");
|
||||
rc = G10ERR_WRITE_FILE;
|
||||
goto leave;
|
||||
}
|
||||
else if( putc( c, fp ) == EOF )
|
||||
{
|
||||
log_error("Error writing to `%s': %s\n",
|
||||
fname, strerror(errno) );
|
||||
rc = G10ERR_WRITE_FILE;
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* binary mode */
|
||||
|
@ -188,15 +199,25 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
|
|||
}
|
||||
if( mfx->md )
|
||||
md_write( mfx->md, buffer, len );
|
||||
if( fp ) {
|
||||
if( fwrite( buffer, 1, len, fp ) != len ) {
|
||||
if( fp )
|
||||
{
|
||||
if((count+=len)>opt.max_output)
|
||||
{
|
||||
log_error("Error writing to `%s': %s\n",
|
||||
fname,"exceeded --max-output limit\n");
|
||||
rc = G10ERR_WRITE_FILE;
|
||||
m_free( buffer );
|
||||
goto leave;
|
||||
}
|
||||
else if( fwrite( buffer, 1, len, fp ) != len )
|
||||
{
|
||||
log_error("Error writing to `%s': %s\n",
|
||||
fname, strerror(errno) );
|
||||
rc = G10ERR_WRITE_FILE;
|
||||
m_free( buffer );
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pt->len -= len;
|
||||
}
|
||||
m_free( buffer );
|
||||
|
@ -211,14 +232,23 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
|
|||
if( convert && c == '\r' )
|
||||
continue; /* fixme: this hack might be too simple */
|
||||
#endif
|
||||
if( fp ) {
|
||||
if( putc( c, fp ) == EOF ) {
|
||||
if( fp )
|
||||
{
|
||||
if((count++)>opt.max_output)
|
||||
{
|
||||
log_error("Error writing to `%s': %s\n",
|
||||
fname,"exceeded --max-output limit\n");
|
||||
rc = G10ERR_WRITE_FILE;
|
||||
goto leave;
|
||||
}
|
||||
else if( putc( c, fp ) == EOF )
|
||||
{
|
||||
log_error("Error writing to `%s': %s\n",
|
||||
fname, strerror(errno) );
|
||||
rc = G10ERR_WRITE_FILE;
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else { /* binary mode */
|
||||
|
@ -238,15 +268,24 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
|
|||
eof = 1;
|
||||
if( mfx->md )
|
||||
md_write( mfx->md, buffer, len );
|
||||
if( fp ) {
|
||||
if( fwrite( buffer, 1, len, fp ) != len ) {
|
||||
if( fp )
|
||||
{
|
||||
if((count+=len)>opt.max_output)
|
||||
{
|
||||
log_error("Error writing to `%s': %s\n",
|
||||
fname, strerror(errno) );
|
||||
fname,"exceeded --max-output limit\n");
|
||||
rc = G10ERR_WRITE_FILE;
|
||||
m_free( buffer );
|
||||
goto leave;
|
||||
}
|
||||
else if( fwrite( buffer, 1, len, fp ) != len ) {
|
||||
log_error("Error writing to `%s': %s\n",
|
||||
fname, strerror(errno) );
|
||||
rc = G10ERR_WRITE_FILE;
|
||||
m_free( buffer );
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m_free( buffer );
|
||||
}
|
||||
|
@ -256,14 +295,23 @@ handle_plaintext( PKT_plaintext *pt, md_filter_context_t *mfx,
|
|||
int state = 0;
|
||||
|
||||
while( (c = iobuf_get(pt->buf)) != -1 ) {
|
||||
if( fp ) {
|
||||
if( putc( c, fp ) == EOF ) {
|
||||
if( fp )
|
||||
{
|
||||
if((count++)>opt.max_output)
|
||||
{
|
||||
log_error("Error writing to `%s': %s\n",
|
||||
fname, strerror(errno) );
|
||||
fname,"exceeded --max-output limit\n");
|
||||
rc = G10ERR_WRITE_FILE;
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( putc( c, fp ) == EOF )
|
||||
{
|
||||
log_error("Error writing to `%s': %s\n",
|
||||
fname, strerror(errno) );
|
||||
rc = G10ERR_WRITE_FILE;
|
||||
goto leave;
|
||||
}
|
||||
}
|
||||
if( !mfx->md )
|
||||
continue;
|
||||
if( state == 2 ) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue