mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 08:29:26 -05:00
removed asserts in reader_armoured.c
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6939 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5800069acf
commit
f4ec563595
@ -38,7 +38,6 @@
|
|||||||
#include "parse_local.h"
|
#include "parse_local.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include <openpgpsdk/final.h>
|
#include <openpgpsdk/final.h>
|
||||||
|
|
||||||
@ -112,12 +111,11 @@ typedef struct
|
|||||||
ops_headers_t headers;
|
ops_headers_t headers;
|
||||||
} dearmour_arg_t;
|
} dearmour_arg_t;
|
||||||
|
|
||||||
static void push_back(dearmour_arg_t *arg,const unsigned char *buf,
|
static void push_back(dearmour_arg_t *arg,const unsigned char *buf, unsigned length)
|
||||||
unsigned length)
|
|
||||||
{
|
{
|
||||||
unsigned n;
|
unsigned n;
|
||||||
|
|
||||||
assert(!arg->pushed_back);
|
//ASSERT(!arg->pushed_back); // in the least, there will be a memory leak. Not a big issue.
|
||||||
arg->pushed_back=malloc(length);
|
arg->pushed_back=malloc(length);
|
||||||
for(n=0 ; n < length ; ++n)
|
for(n=0 ; n < length ; ++n)
|
||||||
arg->pushed_back[n]=buf[length-n-1];
|
arg->pushed_back[n]=buf[length-n-1];
|
||||||
@ -421,7 +419,11 @@ static int process_dash_escaped(dearmour_arg_t *arg,ops_error_t **errors,
|
|||||||
}
|
}
|
||||||
if(c == '\n' && body->length)
|
if(c == '\n' && body->length)
|
||||||
{
|
{
|
||||||
assert(memchr(body->data+1,'\n',body->length-1) == NULL);
|
if(!(memchr(body->data+1,'\n',body->length-1) == NULL)) // ASSERT(memchr(body->data+1,'\n',body->length-1) == NULL);
|
||||||
|
{
|
||||||
|
fprintf(stderr,"no \\n in armoured file.") ;
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
if(body->data[0] == '\n')
|
if(body->data[0] == '\n')
|
||||||
hash->add(hash,(unsigned char *)"\r",1);
|
hash->add(hash,(unsigned char *)"\r",1);
|
||||||
hash->add(hash,body->data,body->length);
|
hash->add(hash,body->data,body->length);
|
||||||
@ -442,8 +444,16 @@ static int process_dash_escaped(dearmour_arg_t *arg,ops_error_t **errors,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(body->data[0] == '\n');
|
if(!(body->data[0] == '\n')) // ASSERT(body->data[0] == '\n');
|
||||||
assert(body->length == 1);
|
{
|
||||||
|
fprintf(stderr,"Body should end with \\n\n");
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
|
if(!(body->length == 1)) // ASSERT(body->length == 1);
|
||||||
|
{
|
||||||
|
fprintf(stderr,"Body length error\n");
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
/* don't send that one character, because its part of the trailer. */
|
/* don't send that one character, because its part of the trailer. */
|
||||||
|
|
||||||
trailer->hash=hash;
|
trailer->hash=hash;
|
||||||
@ -508,7 +518,11 @@ static int parse_headers(dearmour_arg_t *arg,ops_error_t **errors,
|
|||||||
if(nbuf == 0)
|
if(nbuf == 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
assert(nbuf < size);
|
if(!(nbuf < size)) // ASSERT(nbuf < size);
|
||||||
|
{
|
||||||
|
OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Size error in armour header");
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
buf[nbuf]='\0';
|
buf[nbuf]='\0';
|
||||||
|
|
||||||
s=strchr(buf,':');
|
s=strchr(buf,':');
|
||||||
@ -637,7 +651,11 @@ static int decode64(dearmour_arg_t *arg,ops_error_t **errors,
|
|||||||
int c;
|
int c;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
assert(arg->buffered == 0);
|
if(!(arg->buffered == 0)) // ASSERT(arg->buffered == 0);
|
||||||
|
{
|
||||||
|
OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Badly formed base64");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
ret=read4(arg,errors,rinfo,cbinfo,&c,&n,&l);
|
ret=read4(arg,errors,rinfo,cbinfo,&c,&n,&l);
|
||||||
if(ret < 0)
|
if(ret < 0)
|
||||||
@ -685,15 +703,28 @@ static int decode64(dearmour_arg_t *arg,ops_error_t **errors,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
assert(n == 4);
|
if(n != 4) // ASSERT(n == 4);
|
||||||
|
{
|
||||||
|
OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"n should be 4");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
arg->buffered=3;
|
arg->buffered=3;
|
||||||
assert(c != '-' && c != '=');
|
|
||||||
|
if(!(c != '-' && c != '=')) // ASSERT(c != '-' && c != '=');
|
||||||
|
{
|
||||||
|
OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Badly terminated Base64 chunk");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(arg->buffered < 3 && arg->buffered > 0)
|
if(arg->buffered < 3 && arg->buffered > 0)
|
||||||
{
|
{
|
||||||
// then we saw padding
|
// then we saw padding
|
||||||
assert(c == '=');
|
if(!(c == '=')) // ASSERT(c == '=');
|
||||||
|
{
|
||||||
|
OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Badly terminated Base64 chunk");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
c=read_and_eat_whitespace(arg,errors,rinfo,cbinfo,ops_true);
|
c=read_and_eat_whitespace(arg,errors,rinfo,cbinfo,ops_true);
|
||||||
if(c != '\n')
|
if(c != '\n')
|
||||||
{
|
{
|
||||||
@ -743,8 +774,11 @@ static int decode64(dearmour_arg_t *arg,ops_error_t **errors,
|
|||||||
}
|
}
|
||||||
arg->eof64=ops_true;
|
arg->eof64=ops_true;
|
||||||
}
|
}
|
||||||
else
|
else if(!(arg->buffered)) // ASSERT(arg->buffered);
|
||||||
assert(arg->buffered);
|
{
|
||||||
|
OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Buffer error");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
for(n=0 ; n < arg->buffered ; ++n)
|
for(n=0 ; n < arg->buffered ; ++n)
|
||||||
{
|
{
|
||||||
@ -788,7 +822,11 @@ static int armoured_data_reader(void *dest_,size_t length,ops_error_t **errors,
|
|||||||
int saved=length;
|
int saved=length;
|
||||||
|
|
||||||
if(arg->eof64 && !arg->buffered)
|
if(arg->eof64 && !arg->buffered)
|
||||||
assert(arg->state == OUTSIDE_BLOCK || arg->state == AT_TRAILER_NAME);
|
if(!(arg->state == OUTSIDE_BLOCK || arg->state == AT_TRAILER_NAME)) // ASSERT(arg->state == OUTSIDE_BLOCK || arg->state == AT_TRAILER_NAME);
|
||||||
|
{
|
||||||
|
OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Outside block or trailer name expected");
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
|
|
||||||
while(length > 0)
|
while(length > 0)
|
||||||
{
|
{
|
||||||
@ -899,7 +937,11 @@ static int armoured_data_reader(void *dest_,size_t length,ops_error_t **errors,
|
|||||||
}
|
}
|
||||||
if(!arg->buffered)
|
if(!arg->buffered)
|
||||||
{
|
{
|
||||||
assert(arg->eof64);
|
if(!(arg->eof64)) // ASSERT(arg->eof64);
|
||||||
|
{
|
||||||
|
OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Format error");
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
if(first)
|
if(first)
|
||||||
{
|
{
|
||||||
arg->state=AT_TRAILER_NAME;
|
arg->state=AT_TRAILER_NAME;
|
||||||
@ -909,7 +951,11 @@ static int armoured_data_reader(void *dest_,size_t length,ops_error_t **errors,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(arg->buffered);
|
if(!(arg->buffered)) // ASSERT(arg->buffered);
|
||||||
|
{
|
||||||
|
OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Format error");
|
||||||
|
return -1 ;
|
||||||
|
}
|
||||||
*dest=arg->buffer[--arg->buffered];
|
*dest=arg->buffer[--arg->buffered];
|
||||||
++dest;
|
++dest;
|
||||||
--length;
|
--length;
|
||||||
|
Loading…
Reference in New Issue
Block a user