mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 16:09:35 -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 <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <openpgpsdk/final.h>
|
||||
|
||||
@ -112,17 +111,16 @@ typedef struct
|
||||
ops_headers_t headers;
|
||||
} dearmour_arg_t;
|
||||
|
||||
static void push_back(dearmour_arg_t *arg,const unsigned char *buf,
|
||||
unsigned length)
|
||||
{
|
||||
static void push_back(dearmour_arg_t *arg,const unsigned char *buf, unsigned length)
|
||||
{
|
||||
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);
|
||||
for(n=0 ; n < length ; ++n)
|
||||
arg->pushed_back[n]=buf[length-n-1];
|
||||
arg->npushed_back=length;
|
||||
}
|
||||
}
|
||||
|
||||
static int set_lastseen_headerline(dearmour_arg_t* arg, char* buf, ops_error_t **errors)
|
||||
{
|
||||
@ -350,7 +348,7 @@ void ops_dup_headers(ops_headers_t *dest,const ops_headers_t *src)
|
||||
static int process_dash_escaped(dearmour_arg_t *arg,ops_error_t **errors,
|
||||
ops_reader_info_t *rinfo,
|
||||
ops_parse_cb_info_t *cbinfo)
|
||||
{
|
||||
{
|
||||
ops_parser_content_t content;
|
||||
ops_parser_content_t content2;
|
||||
ops_signed_cleartext_body_t *body=&content.content.signed_cleartext_body;
|
||||
@ -421,7 +419,11 @@ static int process_dash_escaped(dearmour_arg_t *arg,ops_error_t **errors,
|
||||
}
|
||||
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')
|
||||
hash->add(hash,(unsigned char *)"\r",1);
|
||||
hash->add(hash,body->data,body->length);
|
||||
@ -442,15 +444,23 @@ static int process_dash_escaped(dearmour_arg_t *arg,ops_error_t **errors,
|
||||
}
|
||||
}
|
||||
|
||||
assert(body->data[0] == '\n');
|
||||
assert(body->length == 1);
|
||||
if(!(body->data[0] == '\n')) // ASSERT(body->data[0] == '\n');
|
||||
{
|
||||
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. */
|
||||
|
||||
trailer->hash=hash;
|
||||
CB(cbinfo,OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER,&content2);
|
||||
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
static int add_header(dearmour_arg_t *arg,const char *key,const char
|
||||
*value)
|
||||
@ -479,7 +489,7 @@ static int add_header(dearmour_arg_t *arg,const char *key,const char
|
||||
/* \todo what does a return value of 0 indicate? 1 is good, -1 is bad */
|
||||
static int parse_headers(dearmour_arg_t *arg,ops_error_t **errors,
|
||||
ops_reader_info_t *rinfo,ops_parse_cb_info_t *cbinfo)
|
||||
{
|
||||
{
|
||||
int rtn=1;
|
||||
char *buf;
|
||||
unsigned nbuf;
|
||||
@ -508,7 +518,11 @@ static int parse_headers(dearmour_arg_t *arg,ops_error_t **errors,
|
||||
if(nbuf == 0)
|
||||
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';
|
||||
|
||||
s=strchr(buf,':');
|
||||
@ -564,11 +578,11 @@ static int parse_headers(dearmour_arg_t *arg,ops_error_t **errors,
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
end:
|
||||
free(buf);
|
||||
|
||||
return rtn;
|
||||
}
|
||||
}
|
||||
|
||||
static int read4(dearmour_arg_t *arg,ops_error_t **errors,
|
||||
ops_reader_info_t *rinfo,ops_parse_cb_info_t *cbinfo,
|
||||
@ -630,14 +644,18 @@ unsigned ops_crc24(unsigned checksum,unsigned char c)
|
||||
|
||||
static int decode64(dearmour_arg_t *arg,ops_error_t **errors,
|
||||
ops_reader_info_t *rinfo,ops_parse_cb_info_t *cbinfo)
|
||||
{
|
||||
{
|
||||
unsigned n;
|
||||
int n2;
|
||||
unsigned long l;
|
||||
int c;
|
||||
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);
|
||||
if(ret < 0)
|
||||
@ -685,15 +703,28 @@ static int decode64(dearmour_arg_t *arg,ops_error_t **errors,
|
||||
}
|
||||
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;
|
||||
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)
|
||||
{
|
||||
// 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);
|
||||
if(c != '\n')
|
||||
{
|
||||
@ -743,8 +774,11 @@ static int decode64(dearmour_arg_t *arg,ops_error_t **errors,
|
||||
}
|
||||
arg->eof64=ops_true;
|
||||
}
|
||||
else
|
||||
assert(arg->buffered);
|
||||
else if(!(arg->buffered)) // ASSERT(arg->buffered);
|
||||
{
|
||||
OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Buffer error");
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(n=0 ; n < arg->buffered ; ++n)
|
||||
{
|
||||
@ -762,7 +796,7 @@ static int decode64(dearmour_arg_t *arg,ops_error_t **errors,
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static void base64(dearmour_arg_t *arg)
|
||||
{
|
||||
@ -779,7 +813,7 @@ static void base64(dearmour_arg_t *arg)
|
||||
static int armoured_data_reader(void *dest_,size_t length,ops_error_t **errors,
|
||||
ops_reader_info_t *rinfo,
|
||||
ops_parse_cb_info_t *cbinfo)
|
||||
{
|
||||
{
|
||||
dearmour_arg_t *arg=ops_reader_get_arg(rinfo);
|
||||
ops_parser_content_t content;
|
||||
int ret;
|
||||
@ -788,7 +822,11 @@ static int armoured_data_reader(void *dest_,size_t length,ops_error_t **errors,
|
||||
int saved=length;
|
||||
|
||||
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)
|
||||
{
|
||||
@ -832,7 +870,7 @@ static int armoured_data_reader(void *dest_,size_t length,ops_error_t **errors,
|
||||
/* then I guess this wasn't a proper header */
|
||||
break;
|
||||
|
||||
got_minus:
|
||||
got_minus:
|
||||
buf[n]='\0';
|
||||
|
||||
/* Consume trailing '-' */
|
||||
@ -899,7 +937,11 @@ static int armoured_data_reader(void *dest_,size_t length,ops_error_t **errors,
|
||||
}
|
||||
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)
|
||||
{
|
||||
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;
|
||||
--length;
|
||||
@ -932,7 +978,7 @@ static int armoured_data_reader(void *dest_,size_t length,ops_error_t **errors,
|
||||
OPS_ERROR(errors,OPS_E_R_BAD_FORMAT,"Bad ASCII armour trailer");
|
||||
break;
|
||||
|
||||
got_minus2:
|
||||
got_minus2:
|
||||
buf[n]='\0';
|
||||
|
||||
if (!set_lastseen_headerline(arg,buf,errors))
|
||||
@ -979,12 +1025,12 @@ static int armoured_data_reader(void *dest_,size_t length,ops_error_t **errors,
|
||||
}
|
||||
break;
|
||||
}
|
||||
reloop:
|
||||
reloop:
|
||||
continue;
|
||||
}
|
||||
|
||||
return saved;
|
||||
}
|
||||
}
|
||||
|
||||
static void armoured_data_destroyer(ops_reader_info_t *rinfo)
|
||||
{ free(ops_reader_get_arg(rinfo)); }
|
||||
|
Loading…
Reference in New Issue
Block a user