Make packet data a ptr-to-const.

Ensure that nobody inadvertly modifies the temporary packet data buffer.
This commit is contained in:
iphydf 2016-09-05 18:05:33 +01:00
parent aa0e3974c5
commit 8121ace449
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9
5 changed files with 14 additions and 12 deletions

View File

@ -169,7 +169,7 @@ static int send_offline_packet(Messenger *m, int friendcon_id)
}
static int handle_status(void *object, int i, uint8_t status);
static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len, void *userdata);
static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata);
static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length);
static int32_t init_new_friend(Messenger *m, const uint8_t *real_pk, uint8_t status)
@ -1622,7 +1622,7 @@ static void break_files(const Messenger *m, int32_t friendnumber)
/* return -1 on failure, 0 on success.
*/
static int handle_filecontrol(Messenger *m, int32_t friendnumber, uint8_t receive_send, uint8_t filenumber,
uint8_t control_type, uint8_t *data, uint16_t length)
uint8_t control_type, const uint8_t *data, uint16_t length)
{
if (receive_send > 1) {
return -1;
@ -2055,7 +2055,7 @@ static int handle_status(void *object, int i, uint8_t status)
return 0;
}
static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len, void *userdata)
static int handle_packet(void *object, int i, const uint8_t *temp, uint16_t len, void *userdata)
{
if (len == 0) {
return -1;
@ -2063,7 +2063,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len, void
Messenger *m = object;
uint8_t packet_id = temp[0];
uint8_t *data = temp + 1;
const uint8_t *data = temp + 1;
uint32_t data_length = len - 1;
if (m->friendlist[i].status != FRIEND_ONLINE) {
@ -2295,7 +2295,7 @@ static int handle_packet(void *object, int i, uint8_t *temp, uint16_t len, void
real_filenumber += 1;
real_filenumber <<= 16;
uint16_t file_data_length = (data_length - 1);
uint8_t *file_data;
const uint8_t *file_data;
if (file_data_length == 0) {
file_data = NULL;

View File

@ -392,7 +392,7 @@ static void dht_pk_callback(void *object, int32_t number, const uint8_t *dht_pub
onion_set_friend_DHT_pubkey(fr_c->onion_c, friend_con->onion_friendnum, dht_public_key);
}
static int handle_packet(void *object, int number, uint8_t *data, uint16_t length, void *userdata)
static int handle_packet(void *object, int number, const uint8_t *data, uint16_t length, void *userdata)
{
if (length == 0) {
return -1;
@ -647,7 +647,8 @@ void set_dht_temp_pk(Friend_Connections *fr_c, int friendcon_id, const uint8_t *
* return -1 on failure
*/
int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index,
int (*status_callback)(void *object, int id, uint8_t status), int (*data_callback)(void *object, int id, uint8_t *data,
int (*status_callback)(void *object, int id, uint8_t status), int (*data_callback)(void *object, int id,
const uint8_t *data,
uint16_t length, void *userdata), int (*lossy_data_callback)(void *object, int id, const uint8_t *data,
uint16_t length), void *object,
int number)

View File

@ -83,7 +83,7 @@ typedef struct {
void *status_callback_object;
int status_callback_id;
int (*data_callback)(void *object, int id, uint8_t *data, uint16_t length, void *userdata);
int (*data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
void *data_callback_object;
int data_callback_id;
@ -158,7 +158,8 @@ int friend_add_tcp_relay(Friend_Connections *fr_c, int friendcon_id, IP_Port ip_
* return -1 on failure
*/
int friend_connection_callbacks(Friend_Connections *fr_c, int friendcon_id, unsigned int index,
int (*status_callback)(void *object, int id, uint8_t status), int (*data_callback)(void *object, int id, uint8_t *data,
int (*status_callback)(void *object, int id, uint8_t status), int (*data_callback)(void *object, int id,
const uint8_t *data,
uint16_t length, void *userdata), int (*lossy_data_callback)(void *object, int id, const uint8_t *data,
uint16_t length), void *object,
int number);

View File

@ -2142,7 +2142,7 @@ int connection_status_handler(const Net_Crypto *c, int crypt_connection_id,
* return 0 on success.
*/
int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object,
int id, uint8_t *data, uint16_t length, void *userdata), void *object, int id)
int id, const uint8_t *data, uint16_t length, void *userdata), void *object, int id)
{
Crypto_Connection *conn = get_crypto_connection(c, crypt_connection_id);

View File

@ -135,7 +135,7 @@ typedef struct {
void *connection_status_callback_object;
int connection_status_callback_id;
int (*connection_data_callback)(void *object, int id, uint8_t *data, uint16_t length, void *userdata);
int (*connection_data_callback)(void *object, int id, const uint8_t *data, uint16_t length, void *userdata);
void *connection_data_callback_object;
int connection_data_callback_id;
@ -275,7 +275,7 @@ int connection_status_handler(const Net_Crypto *c, int crypt_connection_id,
* return 0 on success.
*/
int connection_data_handler(const Net_Crypto *c, int crypt_connection_id, int (*connection_data_callback)(void *object,
int id, uint8_t *data, uint16_t length, void *userdata), void *object, int id);
int id, const uint8_t *data, uint16_t length, void *userdata), void *object, int id);
/* Set function to be called when connection with crypt_connection_id receives a lossy data packet of length.