mirror of
https://github.com/weechat/weechat.git
synced 2026-06-25 04:16:38 +02:00
xfer: fix conversion of string to IPv4 on 32-bit systems (issue #1999)
This commit is contained in:
@@ -19,6 +19,7 @@ Bug fixes::
|
||||
* core: fix increment/decrement of options weechat.notify.*
|
||||
* irc: add missing tags on multiline messages (issue #1987)
|
||||
* irc: fix redirection of command `/list` when the reply doesn't start with message 321 (start of /list)
|
||||
* xfer: fix conversion of string to IPv4 on 32-bit systems (issue #1999)
|
||||
|
||||
Tests::
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
@@ -57,17 +58,17 @@ char *
|
||||
xfer_network_convert_integer_to_ipv4 (const char *str_address)
|
||||
{
|
||||
char *error, result[128];
|
||||
long number;
|
||||
long long number;
|
||||
|
||||
if (!str_address || !str_address[0])
|
||||
return NULL;
|
||||
|
||||
number = strtol (str_address, &error, 10);
|
||||
if (!error || error[0] || (number <= 0))
|
||||
number = strtoll (str_address, &error, 10);
|
||||
if (!error || error[0] || (number <= 0) || (number > UINT32_MAX))
|
||||
return NULL;
|
||||
|
||||
snprintf (result, sizeof (result),
|
||||
"%ld.%ld.%ld.%ld",
|
||||
"%lld.%lld.%lld.%lld",
|
||||
(number >> 24) & 0xFF,
|
||||
(number >> 16) & 0xFF,
|
||||
(number >> 8) & 0xFF,
|
||||
|
||||
@@ -49,6 +49,9 @@ TEST(XferNetwork, ConvertIntegerToIpv4)
|
||||
POINTERS_EQUAL(NULL, xfer_network_convert_integer_to_ipv4 ("0"));
|
||||
POINTERS_EQUAL(NULL, xfer_network_convert_integer_to_ipv4 ("-1"));
|
||||
|
||||
/* too big: UINT32_MAX + 1 = 4294967296 */
|
||||
POINTERS_EQUAL(NULL, xfer_network_convert_integer_to_ipv4 ("4294967296"));
|
||||
|
||||
WEE_TEST_STR("0.0.0.1", xfer_network_convert_integer_to_ipv4 ("1"));
|
||||
WEE_TEST_STR("0.0.1.0", xfer_network_convert_integer_to_ipv4 ("256"));
|
||||
WEE_TEST_STR("0.1.0.0", xfer_network_convert_integer_to_ipv4 ("65536"));
|
||||
|
||||
Reference in New Issue
Block a user