Added a size argument to hex2bin.

This avoids buffer overflows and related bad things.
This commit is contained in:
Håvard Pettersson 2014-09-20 20:28:03 +02:00
parent f59a282db1
commit 43146709b2
5 changed files with 6 additions and 7 deletions

View File

@ -125,7 +125,7 @@ tox_weechat_cmd_friend(void *data, struct t_gui_buffer *buffer,
else if (argc >= 3 && (weechat_strcasecmp(argv[1], "add") == 0))
{
char address[TOX_FRIEND_ADDRESS_SIZE];
tox_weechat_hex2bin(argv[2], address);
tox_weechat_hex2bin(argv[2], TOX_FRIEND_ADDRESS_SIZE * 2, address);
char *message;
if (argc == 3 || strlen(argv_eol[3]) == 0)

View File

@ -141,7 +141,7 @@ tox_weechat_friend_request_init_identity(struct t_tox_weechat_identity *identity
json_t *json_message = json_object_get(json_request,
tox_weechat_json_friend_request_key_message);
tox_weechat_hex2bin(json_string_value(json_id), client_id);
tox_weechat_hex2bin(json_string_value(json_id), TOX_CLIENT_ID_SIZE * 2, client_id);
message = json_string_value(json_message);
tox_weechat_friend_request_add(identity,

View File

@ -165,7 +165,7 @@ int
tox_weechat_bootstrap_tox(Tox *tox, const char *address, uint16_t port, const char *public_key)
{
char binary_key[TOX_FRIEND_ADDRESS_SIZE];
tox_weechat_hex2bin(public_key, binary_key);
tox_weechat_hex2bin(public_key, TOX_FRIEND_ADDRESS_SIZE * 2, binary_key);
int result = tox_bootstrap_from_address(tox,
address,

View File

@ -30,12 +30,11 @@
#include "tox-weechat-utils.h"
void
tox_weechat_hex2bin(const char *hex, char *out)
tox_weechat_hex2bin(const char *hex, size_t length, char *out)
{
size_t length = strlen(hex) / 2;
const char *position = hex;
for (size_t i = 0; i < length; ++i)
for (size_t i = 0; i < length / 2; ++i)
{
sscanf(position, "%2hhx", &out[i]);
position += 2;

View File

@ -26,7 +26,7 @@
#include <tox/tox.h>
void
tox_weechat_hex2bin(const char *hex, char *out);
tox_weechat_hex2bin(const char *hex, size_t length, char *out);
void
tox_weechat_bin2hex(const uint8_t *bin, size_t size, char *out);