summaryrefslogtreecommitdiffstats
path: root/libssh/base64.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-07 13:57:17 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-07 13:57:17 +0000
commit7059e05a2a96baf8cdadf5621ff6255ec9267bfa (patch)
treeb68983f168c9ebeede43fc2eb71d2a396734fe5e /libssh/base64.c
parentfe2bc30984af5487c1871f80c31d2911ec70bc89 (diff)
downloadlibssh-7059e05a2a96baf8cdadf5621ff6255ec9267bfa.tar.gz
libssh-7059e05a2a96baf8cdadf5621ff6255ec9267bfa.tar.xz
libssh-7059e05a2a96baf8cdadf5621ff6255ec9267bfa.zip
Check return values of buffer functions.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@412 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/base64.c')
-rw-r--r--libssh/base64.c52
1 files changed, 29 insertions, 23 deletions
diff --git a/libssh/base64.c b/libssh/base64.c
index 2835220..80f3523 100644
--- a/libssh/base64.c
+++ b/libssh/base64.c
@@ -56,23 +56,28 @@ static int get_equals(char *string);
BUFFER *base64_to_bin(char *source){
int len;
int equals;
- BUFFER *buffer=buffer_new();
+ BUFFER *buffer = NULL;
unsigned char block[3];
/* get the number of equals signs, which mirrors the padding */
equals=get_equals(source);
if(equals>2){
- buffer_free(buffer);
return NULL;
}
+ buffer = buffer_new();
+ if (buffer == NULL) {
+ return NULL;
+ }
+
len=strlen(source);
while(len>4){
if(_base64_to_bin(block,source,3)){
- buffer_free(buffer);
- return NULL;
+ goto error;
+ }
+ if (buffer_add_data(buffer, block, 3) < 0) {
+ goto error;
}
- buffer_add_data(buffer,block,3);
len-=4;
source+=4;
}
@@ -83,49 +88,50 @@ BUFFER *base64_to_bin(char *source){
an integral multiple of 4 characters with no "=" padding */
case 4:
if(equals!=0){
- buffer_free(buffer);
- return NULL;
+ goto error;
}
if(_base64_to_bin(block,source,3)){
- buffer_free(buffer);
- return NULL;
+ goto error;
+ }
+ if (buffer_add_data(buffer,block,3) < 0) {
+ goto error;
}
- buffer_add_data(buffer,block,3);
return buffer;
/*(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 "="
padding characters */
case 2:
if(equals!=2){
- buffer_free(buffer);
- return NULL;
+ goto error;
}
if(_base64_to_bin(block,source,1)){
- buffer_free(buffer);
- return NULL;
+ goto error;
+ }
+ if (buffer_add_data(buffer,block,1) < 0) {
+ goto error;
}
- buffer_add_data(buffer,block,1);
return buffer;
/* the final quantum of encoding input is
exactly 16 bits; here, the final unit of encoded output will be three
characters followed by one "=" padding character */
case 3:
if(equals!=1){
- buffer_free(buffer);
- return NULL;
+ goto error;
}
if(_base64_to_bin(block,source,2)){
- buffer_free(buffer);
- return NULL;
+ goto error;
+ }
+ if (buffer_add_data(buffer,block,2) < 0) {
+ goto error;
}
- buffer_add_data(buffer,block,2);
return buffer;
default:
/* 4,3,2 are the only padding size allowed */
- buffer_free(buffer);
- return NULL;
+ goto error;
}
- return NULL;
+error:
+ buffer_free(buffer);
+ return NULL;
}
#define BLOCK(letter,n) do { ptr=strchr(alphabet,source[n]);\