Added a size argument to hex2bin.
This avoids buffer overflows and related bad things.
This commit is contained in:
parent
f59a282db1
commit
43146709b2
@ -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))
|
else if (argc >= 3 && (weechat_strcasecmp(argv[1], "add") == 0))
|
||||||
{
|
{
|
||||||
char address[TOX_FRIEND_ADDRESS_SIZE];
|
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;
|
char *message;
|
||||||
if (argc == 3 || strlen(argv_eol[3]) == 0)
|
if (argc == 3 || strlen(argv_eol[3]) == 0)
|
||||||
|
@ -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,
|
json_t *json_message = json_object_get(json_request,
|
||||||
tox_weechat_json_friend_request_key_message);
|
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);
|
message = json_string_value(json_message);
|
||||||
|
|
||||||
tox_weechat_friend_request_add(identity,
|
tox_weechat_friend_request_add(identity,
|
||||||
|
@ -165,7 +165,7 @@ int
|
|||||||
tox_weechat_bootstrap_tox(Tox *tox, const char *address, uint16_t port, const char *public_key)
|
tox_weechat_bootstrap_tox(Tox *tox, const char *address, uint16_t port, const char *public_key)
|
||||||
{
|
{
|
||||||
char binary_key[TOX_FRIEND_ADDRESS_SIZE];
|
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,
|
int result = tox_bootstrap_from_address(tox,
|
||||||
address,
|
address,
|
||||||
|
@ -30,12 +30,11 @@
|
|||||||
#include "tox-weechat-utils.h"
|
#include "tox-weechat-utils.h"
|
||||||
|
|
||||||
void
|
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;
|
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]);
|
sscanf(position, "%2hhx", &out[i]);
|
||||||
position += 2;
|
position += 2;
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#include <tox/tox.h>
|
#include <tox/tox.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
tox_weechat_hex2bin(const char *hex, char *out);
|
tox_weechat_hex2bin(const char *hex, size_t length, char *out);
|
||||||
|
|
||||||
void
|
void
|
||||||
tox_weechat_bin2hex(const uint8_t *bin, size_t size, char *out);
|
tox_weechat_bin2hex(const uint8_t *bin, size_t size, char *out);
|
||||||
|
Loading…
Reference in New Issue
Block a user