@@ -31,6 +31,7 @@ static Persistent<String> version_symbol;
3131
3232
3333static int verify_callback (int ok, X509_STORE_CTX *ctx) {
34+ assert (ok);
3435 return (1 ); // Ignore errors by now. VerifyPeer will catch them by using SSL_get_verify_result.
3536}
3637
@@ -693,7 +694,8 @@ void base64(unsigned char *input, int length, char** buf64, int* buf64_len) {
693694 BIO_set_flags (b64, BIO_FLAGS_BASE64_NO_NL);
694695 len = BIO_write (b64, input, length);
695696 assert (len == length);
696- BIO_flush (b64);
697+ int r = BIO_flush (b64);
698+ assert (r == 1 );
697699 BIO_get_mem_ptr (b64, &bptr);
698700
699701 *buf64_len = bptr->length ;
@@ -804,7 +806,7 @@ int local_EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx,
804806 return (0 );
805807 }
806808
807- if (b > (sizeof (ctx->final ) / sizeof (ctx->final [0 ]))) {
809+ if (b > (int )( sizeof (ctx->final ) / sizeof (ctx->final [0 ]))) {
808810 EVPerr (EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
809811 return (0 );
810812 }
@@ -961,6 +963,10 @@ class Cipher : public ObjectWrap {
961963
962964 delete [] key_buf;
963965
966+ if (!r) {
967+ return ThrowException (Exception::Error (String::New (" CipherInit error" )));
968+ }
969+
964970 return args.This ();
965971 }
966972
@@ -1005,6 +1011,10 @@ class Cipher : public ObjectWrap {
10051011 delete [] key_buf;
10061012 delete [] iv_buf;
10071013
1014+ if (!r) {
1015+ return ThrowException (Exception::Error (String::New (" CipherInitIv error" )));
1016+ }
1017+
10081018 return args.This ();
10091019 }
10101020
@@ -1023,21 +1033,27 @@ class Cipher : public ObjectWrap {
10231033 }
10241034
10251035 unsigned char *out=0 ;
1026- int out_len=0 ;
1036+ int out_len=0 , r ;
10271037 if (Buffer::HasInstance (args[0 ])) {
10281038 Local<Object> buffer_obj = args[0 ]->ToObject ();
10291039 char *buffer_data = Buffer::Data (buffer_obj);
10301040 size_t buffer_length = Buffer::Length (buffer_obj);
10311041
1032- int r = cipher->CipherUpdate (buffer_data, buffer_length, &out, &out_len);
1042+ r = cipher->CipherUpdate (buffer_data, buffer_length, &out, &out_len);
10331043 } else {
10341044 char * buf = new char [len];
10351045 ssize_t written = DecodeWrite (buf, len, args[0 ], enc);
10361046 assert (written == len);
1037- int r = cipher->CipherUpdate (buf, len,&out,&out_len);
1047+ r = cipher->CipherUpdate (buf, len,&out,&out_len);
10381048 delete [] buf;
10391049 }
10401050
1051+ if (!r) {
1052+ delete [] out;
1053+ Local<Value> exception = Exception::TypeError (String::New (" DecipherUpdate fail" ));
1054+ return ThrowException (exception);
1055+ }
1056+
10411057 Local<Value> outString;
10421058 if (out_len==0 ) {
10431059 outString=String::New (" " );
@@ -1308,6 +1324,10 @@ class Decipher : public ObjectWrap {
13081324
13091325 delete [] key_buf;
13101326
1327+ if (!r) {
1328+ return ThrowException (Exception::Error (String::New (" DecipherInit error" )));
1329+ }
1330+
13111331 return args.This ();
13121332 }
13131333
@@ -1353,6 +1373,10 @@ class Decipher : public ObjectWrap {
13531373 delete [] key_buf;
13541374 delete [] iv_buf;
13551375
1376+ if (!r) {
1377+ return ThrowException (Exception::Error (String::New (" DecipherInitIv error" )));
1378+ }
1379+
13561380 return args.This ();
13571381 }
13581382
@@ -1443,6 +1467,12 @@ class Decipher : public ObjectWrap {
14431467 int out_len=0 ;
14441468 int r = cipher->DecipherUpdate (buf, len, &out, &out_len);
14451469
1470+ if (!r) {
1471+ delete [] out;
1472+ Local<Value> exception = Exception::TypeError (String::New (" DecipherUpdate fail" ));
1473+ return ThrowException (exception);
1474+ }
1475+
14461476 Local<Value> outString;
14471477 if (out_len==0 ) {
14481478 outString=String::New (" " );
@@ -1491,9 +1521,7 @@ class Decipher : public ObjectWrap {
14911521
14921522 unsigned char * out_value;
14931523 int out_len;
1494- char * out_hexdigest;
1495- int out_hex_len;
1496- Local<Value> outString ;
1524+ Local<Value> outString;
14971525
14981526 int r = cipher->DecipherFinal (&out_value, &out_len, false );
14991527
@@ -1536,8 +1564,6 @@ class Decipher : public ObjectWrap {
15361564
15371565 unsigned char * out_value;
15381566 int out_len;
1539- char * out_hexdigest;
1540- int out_hex_len;
15411567 Local<Value> outString ;
15421568
15431569 int r = cipher->DecipherFinal (&out_value, &out_len, true );
@@ -1677,6 +1703,10 @@ class Hmac : public ObjectWrap {
16771703
16781704 delete [] buf;
16791705
1706+ if (!r) {
1707+ return ThrowException (Exception::Error (String::New (" hmac error" )));
1708+ }
1709+
16801710 return args.This ();
16811711 }
16821712
@@ -1692,21 +1722,28 @@ class Hmac : public ObjectWrap {
16921722 Local<Value> exception = Exception::TypeError (String::New (" Bad argument" ));
16931723 return ThrowException (exception);
16941724 }
1725+
1726+ int r;
16951727
16961728 if ( Buffer::HasInstance (args[0 ])) {
16971729 Local<Object> buffer_obj = args[0 ]->ToObject ();
16981730 char *buffer_data = Buffer::Data (buffer_obj);
16991731 size_t buffer_length = Buffer::Length (buffer_obj);
17001732
1701- int r = hmac->HmacUpdate (buffer_data, buffer_length);
1733+ r = hmac->HmacUpdate (buffer_data, buffer_length);
17021734 } else {
17031735 char * buf = new char [len];
17041736 ssize_t written = DecodeWrite (buf, len, args[0 ], enc);
17051737 assert (written == len);
1706- int r = hmac->HmacUpdate (buf, len);
1738+ r = hmac->HmacUpdate (buf, len);
17071739 delete [] buf;
17081740 }
17091741
1742+ if (!r) {
1743+ Local<Value> exception = Exception::TypeError (String::New (" HmacUpdate fail" ));
1744+ return ThrowException (exception);
1745+ }
1746+
17101747 return args.This ();
17111748 }
17121749
@@ -1842,21 +1879,26 @@ class Hash : public ObjectWrap {
18421879 return ThrowException (exception);
18431880 }
18441881
1882+ int r;
18451883
18461884 if (Buffer::HasInstance (args[0 ])) {
18471885 Local<Object> buffer_obj = args[0 ]->ToObject ();
18481886 char *buffer_data = Buffer::Data (buffer_obj);
18491887 size_t buffer_length = Buffer::Length (buffer_obj);
1850-
1851- int r = hash->HashUpdate (buffer_data, buffer_length);
1888+ r = hash->HashUpdate (buffer_data, buffer_length);
18521889 } else {
18531890 char * buf = new char [len];
18541891 ssize_t written = DecodeWrite (buf, len, args[0 ], enc);
18551892 assert (written == len);
1856- int r = hash->HashUpdate (buf, len);
1893+ r = hash->HashUpdate (buf, len);
18571894 delete[] buf;
18581895 }
18591896
1897+ if (!r) {
1898+ Local<Value> exception = Exception::TypeError (String::New (" HashUpdate fail" ));
1899+ return ThrowException (exception);
1900+ }
1901+
18601902 return args.This ();
18611903 }
18621904
@@ -2000,6 +2042,10 @@ class Sign : public ObjectWrap {
20002042
20012043 bool r = sign->SignInit (*signType);
20022044
2045+ if (!r) {
2046+ return ThrowException (Exception::Error (String::New (" SignInit error" )));
2047+ }
2048+
20032049 return args.This ();
20042050 }
20052051
@@ -2016,20 +2062,27 @@ class Sign : public ObjectWrap {
20162062 return ThrowException (exception);
20172063 }
20182064
2065+ int r;
2066+
20192067 if (Buffer::HasInstance (args[0 ])) {
20202068 Local<Object> buffer_obj = args[0 ]->ToObject ();
20212069 char *buffer_data = Buffer::Data (buffer_obj);
20222070 size_t buffer_length = Buffer::Length (buffer_obj);
20232071
2024- int r = sign->SignUpdate (buffer_data, buffer_length);
2072+ r = sign->SignUpdate (buffer_data, buffer_length);
20252073 } else {
20262074 char * buf = new char [len];
20272075 ssize_t written = DecodeWrite (buf, len, args[0 ], enc);
20282076 assert (written == len);
2029- int r = sign->SignUpdate (buf, len);
2077+ r = sign->SignUpdate (buf, len);
20302078 delete [] buf;
20312079 }
20322080
2081+ if (!r) {
2082+ Local<Value> exception = Exception::TypeError (String::New (" SignUpdate fail" ));
2083+ return ThrowException (exception);
2084+ }
2085+
20332086 return args.This ();
20342087 }
20352088
@@ -2201,6 +2254,10 @@ class Verify : public ObjectWrap {
22012254
22022255 bool r = verify->VerifyInit (*verifyType);
22032256
2257+ if (!r) {
2258+ return ThrowException (Exception::Error (String::New (" VerifyInit error" )));
2259+ }
2260+
22042261 return args.This ();
22052262 }
22062263
@@ -2218,20 +2275,27 @@ class Verify : public ObjectWrap {
22182275 return ThrowException (exception);
22192276 }
22202277
2278+ int r;
2279+
22212280 if (Buffer::HasInstance (args[0 ])) {
22222281 Local<Object> buffer_obj = args[0 ]->ToObject ();
22232282 char *buffer_data = Buffer::Data (buffer_obj);
22242283 size_t buffer_length = Buffer::Length (buffer_obj);
22252284
2226- int r = verify->VerifyUpdate (buffer_data, buffer_length);
2285+ r = verify->VerifyUpdate (buffer_data, buffer_length);
22272286 } else {
22282287 char * buf = new char [len];
22292288 ssize_t written = DecodeWrite (buf, len, args[0 ], enc);
22302289 assert (written == len);
2231- int r = verify->VerifyUpdate (buf, len);
2290+ r = verify->VerifyUpdate (buf, len);
22322291 delete [] buf;
22332292 }
22342293
2294+ if (!r) {
2295+ Local<Value> exception = Exception::TypeError (String::New (" VerifyUpdate fail" ));
2296+ return ThrowException (exception);
2297+ }
2298+
22352299 return args.This ();
22362300 }
22372301
0 commit comments