Commit e930ed9e authored by DanmeiChen's avatar DanmeiChen

remove variable lenth arrays

parent 142ab58b
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
#include "belle-sip/defs.h" #include "belle-sip/defs.h"
#include "belle-sip/belle-sip.h" #include "belle-sip/belle-sip.h"
#define MAX_LENGTH_BYTE 32
#define MAX_RESPONSE_SIZE 65
BELLE_SIP_BEGIN_DECLS BELLE_SIP_BEGIN_DECLS
/** /**
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include <string.h> #include <string.h>
#include "bctoolbox/crypto.h" #include "bctoolbox/crypto.h"
#ifndef BELLE_SIP_CNONCE_LENGTH #ifndef BELLE_SIP_CNONCE_LENGTH
#define BELLE_SIP_CNONCE_LENGTH 16 #define BELLE_SIP_CNONCE_LENGTH 16
#endif #endif
...@@ -100,7 +99,7 @@ int belle_sip_auth_helper_compute_ha1_for_algorithm(const char *userid, const ch ...@@ -100,7 +99,7 @@ int belle_sip_auth_helper_compute_ha1_for_algorithm(const char *userid, const ch
return -1; return -1;
} }
size_t length_byte = (size - 1) / 2; size_t length_byte = (size - 1) / 2;
uint8_t out[32]; uint8_t out[MAX_LENGTH_BYTE];
size_t di; size_t di;
char *ask; char *ask;
if (!userid) { if (!userid) {
...@@ -138,7 +137,7 @@ int belle_sip_auth_helper_compute_ha2_for_algorithm(const char *method, const ch ...@@ -138,7 +137,7 @@ int belle_sip_auth_helper_compute_ha2_for_algorithm(const char *method, const ch
return -1; return -1;
} }
size_t length_byte = (size - 1) / 2; size_t length_byte = (size - 1) / 2;
uint8_t out[32]; uint8_t out[MAX_LENGTH_BYTE];
size_t di; size_t di;
char *ask; char *ask;
ha2[length_byte * 2] = '\0'; ha2[length_byte * 2] = '\0';
...@@ -165,7 +164,7 @@ int belle_sip_auth_helper_compute_response_for_algorithm(const char *ha1, const ...@@ -165,7 +164,7 @@ int belle_sip_auth_helper_compute_response_for_algorithm(const char *ha1, const
return -1; return -1;
} }
size_t length_byte = (size - 1) / 2; size_t length_byte = (size - 1) / 2;
uint8_t out[32]; uint8_t out[MAX_LENGTH_BYTE];
size_t di; size_t di;
char *ask; char *ask;
response[length_byte * 2] = '\0'; response[length_byte * 2] = '\0';
...@@ -200,7 +199,7 @@ int belle_sip_auth_helper_compute_response_qop_auth_for_algorithm(const char* ha ...@@ -200,7 +199,7 @@ int belle_sip_auth_helper_compute_response_qop_auth_for_algorithm(const char* ha
return -1; return -1;
} }
size_t length_byte = (size - 1) / 2; size_t length_byte = (size - 1) / 2;
uint8_t out[32]; uint8_t out[MAX_LENGTH_BYTE];
size_t di; size_t di;
char *ask; char *ask;
char nounce_count_as_string[9]; char nounce_count_as_string[9];
...@@ -240,8 +239,8 @@ int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* a ...@@ -240,8 +239,8 @@ int belle_sip_auth_helper_fill_authorization(belle_sip_header_authorization_t* a
} }
int auth_mode=0; int auth_mode=0;
char* uri; char* uri;
char ha2[65]; char ha2[MAX_RESPONSE_SIZE];
char response[65]; char response[MAX_RESPONSE_SIZE];
char cnonce[BELLE_SIP_CNONCE_LENGTH + 1]; char cnonce[BELLE_SIP_CNONCE_LENGTH + 1];
response[size-1]=ha2[size-1]='\0'; response[size-1]=ha2[size-1]='\0';
......
...@@ -120,7 +120,7 @@ static void compute_response(const char* username ...@@ -120,7 +120,7 @@ static void compute_response(const char* username
,char* response ,char* response
,size_t size ,size_t size
,const char* algo) { ,const char* algo) {
char ha1[65],ha2[65]; char ha1[MAX_RESPONSE_SIZE],ha2[MAX_RESPONSE_SIZE];
belle_sip_auth_helper_compute_ha1_for_algorithm(username,realm,passwd,ha1,size,algo); belle_sip_auth_helper_compute_ha1_for_algorithm(username,realm,passwd,ha1,size,algo);
belle_sip_auth_helper_compute_ha2_for_algorithm(method,uri,ha2,size,algo); belle_sip_auth_helper_compute_ha2_for_algorithm(method,uri,ha2,size,algo);
belle_sip_auth_helper_compute_response_for_algorithm(ha1,nonce,ha2,response,size,algo); belle_sip_auth_helper_compute_response_for_algorithm(ha1,nonce,ha2,response,size,algo);
...@@ -138,7 +138,7 @@ static void compute_response_auth_qop(const char* username ...@@ -138,7 +138,7 @@ static void compute_response_auth_qop(const char* username
,char* response ,char* response
,size_t size ,size_t size
,const char* algo) { ,const char* algo) {
char ha1[65],ha2[65]; char ha1[MAX_RESPONSE_SIZE],ha2[MAX_RESPONSE_SIZE];
belle_sip_auth_helper_compute_ha1_for_algorithm(username,realm,passwd,ha1,size,algo); belle_sip_auth_helper_compute_ha1_for_algorithm(username,realm,passwd,ha1,size,algo);
belle_sip_auth_helper_compute_ha2_for_algorithm(method,uri,ha2,size,algo); belle_sip_auth_helper_compute_ha2_for_algorithm(method,uri,ha2,size,algo);
belle_sip_auth_helper_compute_response_qop_auth_for_algorithm(ha1, nonce,nonce_count, cnonce,qop,ha2,response,size,algo); belle_sip_auth_helper_compute_response_qop_auth_for_algorithm(ha1, nonce,nonce_count, cnonce,qop,ha2,response,size,algo);
...@@ -206,7 +206,7 @@ static void server_process_request_event(void *obj, const belle_sip_request_even ...@@ -206,7 +206,7 @@ static void server_process_request_event(void *obj, const belle_sip_request_even
belle_sip_error("Algorithm [%s] is not correct ", algo); belle_sip_error("Algorithm [%s] is not correct ", algo);
return; return;
} }
char local_resp[65]; char local_resp[MAX_RESPONSE_SIZE];
if (qop && strcmp(qop, "auth") == 0) { if (qop && strcmp(qop, "auth") == 0) {
compute_response_auth_qop(belle_sip_header_authorization_get_username(authorization) compute_response_auth_qop(belle_sip_header_authorization_get_username(authorization)
, belle_sip_header_authorization_get_realm(authorization) , belle_sip_header_authorization_get_realm(authorization)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment