1
1

Check return values of buffer functions.

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@412 7dcaeef0-15fb-0310-b436-a5af3365683c
Этот коммит содержится в:
Andreas Schneider 2009-04-07 13:57:17 +00:00
родитель fe2bc30984
Коммит 7059e05a2a

Просмотреть файл

@ -56,23 +56,28 @@ static int get_equals(char *string);
BUFFER *base64_to_bin(char *source){ BUFFER *base64_to_bin(char *source){
int len; int len;
int equals; int equals;
BUFFER *buffer=buffer_new(); BUFFER *buffer = NULL;
unsigned char block[3]; unsigned char block[3];
/* get the number of equals signs, which mirrors the padding */ /* get the number of equals signs, which mirrors the padding */
equals=get_equals(source); equals=get_equals(source);
if(equals>2){ if(equals>2){
buffer_free(buffer);
return NULL; return NULL;
} }
buffer = buffer_new();
if (buffer == NULL) {
return NULL;
}
len=strlen(source); len=strlen(source);
while(len>4){ while(len>4){
if(_base64_to_bin(block,source,3)){ if(_base64_to_bin(block,source,3)){
buffer_free(buffer); goto error;
return NULL; }
if (buffer_add_data(buffer, block, 3) < 0) {
goto error;
} }
buffer_add_data(buffer,block,3);
len-=4; len-=4;
source+=4; source+=4;
} }
@ -83,49 +88,50 @@ BUFFER *base64_to_bin(char *source){
an integral multiple of 4 characters with no "=" padding */ an integral multiple of 4 characters with no "=" padding */
case 4: case 4:
if(equals!=0){ if(equals!=0){
buffer_free(buffer); goto error;
return NULL;
} }
if(_base64_to_bin(block,source,3)){ if(_base64_to_bin(block,source,3)){
buffer_free(buffer); goto error;
return NULL; }
if (buffer_add_data(buffer,block,3) < 0) {
goto error;
} }
buffer_add_data(buffer,block,3);
return buffer; return buffer;
/*(2) the final quantum of encoding input is exactly 8 bits; here, the final /*(2) the final quantum of encoding input is exactly 8 bits; here, the final
unit of encoded output will be two characters followed by two "=" unit of encoded output will be two characters followed by two "="
padding characters */ padding characters */
case 2: case 2:
if(equals!=2){ if(equals!=2){
buffer_free(buffer); goto error;
return NULL;
} }
if(_base64_to_bin(block,source,1)){ if(_base64_to_bin(block,source,1)){
buffer_free(buffer); goto error;
return NULL; }
if (buffer_add_data(buffer,block,1) < 0) {
goto error;
} }
buffer_add_data(buffer,block,1);
return buffer; return buffer;
/* the final quantum of encoding input is /* the final quantum of encoding input is
exactly 16 bits; here, the final unit of encoded output will be three exactly 16 bits; here, the final unit of encoded output will be three
characters followed by one "=" padding character */ characters followed by one "=" padding character */
case 3: case 3:
if(equals!=1){ if(equals!=1){
buffer_free(buffer); goto error;
return NULL;
} }
if(_base64_to_bin(block,source,2)){ if(_base64_to_bin(block,source,2)){
buffer_free(buffer); goto error;
return NULL; }
if (buffer_add_data(buffer,block,2) < 0) {
goto error;
} }
buffer_add_data(buffer,block,2);
return buffer; return buffer;
default: default:
/* 4,3,2 are the only padding size allowed */ /* 4,3,2 are the only padding size allowed */
buffer_free(buffer); goto error;
return NULL;
} }
return NULL; error:
buffer_free(buffer);
return NULL;
} }
#define BLOCK(letter,n) do { ptr=strchr(alphabet,source[n]);\ #define BLOCK(letter,n) do { ptr=strchr(alphabet,source[n]);\