diff options
author | lurchi <lurchi@strangeplace.net> | 2019-06-27 10:49:40 +0200 |
---|---|---|
committer | lurchi <lurchi@strangeplace.net> | 2019-06-27 10:49:40 +0200 |
commit | b9771c5f5edcbeb965fa291a281943d866c3ddb6 (patch) | |
tree | e53141e844dfe7032d018cb5bfebd31fe02f7816 /src/util | |
parent | 0e7c93c3a0a3aa966503a8ae4caf3a21914e4126 (diff) | |
download | gnunet-b9771c5f5edcbeb965fa291a281943d866c3ddb6.tar.gz gnunet-b9771c5f5edcbeb965fa291a281943d866c3ddb6.zip |
use GNUNET_strlcpy instead of strncpy where possible
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/client.c | 6 | ||||
-rw-r--r-- | src/util/common_logging.c | 10 | ||||
-rw-r--r-- | src/util/gnunet-ecc.c | 2 | ||||
-rw-r--r-- | src/util/service.c | 6 | ||||
-rw-r--r-- | src/util/socks.c | 9 |
5 files changed, 17 insertions, 16 deletions
diff --git a/src/util/client.c b/src/util/client.c index 05e05a328..313cc23af 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -532,9 +532,9 @@ try_unixpath (const char *service_name, | |||
532 | 0, | 532 | 0, |
533 | sizeof (s_un)); | 533 | sizeof (s_un)); |
534 | s_un.sun_family = AF_UNIX; | 534 | s_un.sun_family = AF_UNIX; |
535 | strncpy (s_un.sun_path, | 535 | GNUNET_strlcpy (s_un.sun_path, |
536 | unixpath, | 536 | unixpath, |
537 | sizeof (s_un.sun_path) - 1); | 537 | sizeof (s_un.sun_path)); |
538 | #ifdef LINUX | 538 | #ifdef LINUX |
539 | { | 539 | { |
540 | int abstract; | 540 | int abstract; |
diff --git a/src/util/common_logging.c b/src/util/common_logging.c index b5678e5be..3193878b8 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c | |||
@@ -1082,11 +1082,11 @@ mylog (enum GNUNET_ErrorType kind, | |||
1082 | return; | 1082 | return; |
1083 | } | 1083 | } |
1084 | flush_bulk (date); | 1084 | flush_bulk (date); |
1085 | strncpy (last_bulk, buf, sizeof (last_bulk)); | 1085 | GNUNET_strlcpy (last_bulk, buf, sizeof (last_bulk)); |
1086 | last_bulk_repeat = 0; | 1086 | last_bulk_repeat = 0; |
1087 | last_bulk_kind = kind; | 1087 | last_bulk_kind = kind; |
1088 | last_bulk_time = GNUNET_TIME_absolute_get (); | 1088 | last_bulk_time = GNUNET_TIME_absolute_get (); |
1089 | strncpy (last_bulk_comp, comp, COMP_TRACK_SIZE); | 1089 | GNUNET_strlcpy (last_bulk_comp, comp, sizeof (last_bulk_comp)); |
1090 | output_message (kind, comp, date, buf); | 1090 | output_message (kind, comp, date, buf); |
1091 | } | 1091 | } |
1092 | } | 1092 | } |
@@ -1364,9 +1364,8 @@ GNUNET_i2s (const struct GNUNET_PeerIdentity *pid) | |||
1364 | if (NULL == pid) | 1364 | if (NULL == pid) |
1365 | return "NULL"; | 1365 | return "NULL"; |
1366 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); | 1366 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); |
1367 | strncpy (buf, ret, sizeof (buf) - 1); | 1367 | GNUNET_strlcpy (buf, ret, sizeof (buf)); |
1368 | GNUNET_free (ret); | 1368 | GNUNET_free (ret); |
1369 | buf[4] = '\0'; | ||
1370 | return buf; | 1369 | return buf; |
1371 | } | 1370 | } |
1372 | 1371 | ||
@@ -1390,9 +1389,8 @@ GNUNET_i2s2 (const struct GNUNET_PeerIdentity *pid) | |||
1390 | if (NULL == pid) | 1389 | if (NULL == pid) |
1391 | return "NULL"; | 1390 | return "NULL"; |
1392 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); | 1391 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid->public_key); |
1393 | strncpy (buf, ret, sizeof (buf) - 1); | 1392 | GNUNET_strlcpy (buf, ret, sizeof (buf)); |
1394 | GNUNET_free (ret); | 1393 | GNUNET_free (ret); |
1395 | buf[4] = '\0'; | ||
1396 | return buf; | 1394 | return buf; |
1397 | } | 1395 | } |
1398 | 1396 | ||
diff --git a/src/util/gnunet-ecc.c b/src/util/gnunet-ecc.c index 27ef59c9f..94ffb4308 100644 --- a/src/util/gnunet-ecc.c +++ b/src/util/gnunet-ecc.c | |||
@@ -96,7 +96,7 @@ create_keys (const char *fn, const char *prefix) | |||
96 | } | 96 | } |
97 | if (NULL != prefix) | 97 | if (NULL != prefix) |
98 | { | 98 | { |
99 | strncpy (vanity, prefix, KEY_STR_LEN); | 99 | GNUNET_strlcpy (vanity, prefix, sizeof (vanity)); |
100 | len = GNUNET_MIN (strlen (prefix), KEY_STR_LEN); | 100 | len = GNUNET_MIN (strlen (prefix), KEY_STR_LEN); |
101 | n = len * 5 / 8; | 101 | n = len * 5 / 8; |
102 | rest = len * 5 % 8; | 102 | rest = len * 5 % 8; |
diff --git a/src/util/service.c b/src/util/service.c index 4fd16f93d..d03650501 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -1061,9 +1061,9 @@ add_unixpath (struct sockaddr **saddrs, | |||
1061 | 1061 | ||
1062 | un = GNUNET_new (struct sockaddr_un); | 1062 | un = GNUNET_new (struct sockaddr_un); |
1063 | un->sun_family = AF_UNIX; | 1063 | un->sun_family = AF_UNIX; |
1064 | strncpy (un->sun_path, | 1064 | GNUNET_strlcpy (un->sun_path, |
1065 | unixpath, | 1065 | unixpath, |
1066 | sizeof (un->sun_path) - 1); | 1066 | sizeof (un->sun_path)); |
1067 | #ifdef LINUX | 1067 | #ifdef LINUX |
1068 | if (GNUNET_YES == abstract) | 1068 | if (GNUNET_YES == abstract) |
1069 | un->sun_path[0] = '\0'; | 1069 | un->sun_path[0] = '\0'; |
diff --git a/src/util/socks.c b/src/util/socks.c index 7eca04878..9e974e6bb 100644 --- a/src/util/socks.c +++ b/src/util/socks.c | |||
@@ -76,7 +76,7 @@ const char * SOCKS5_REP_names(int rep) | |||
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Encode a string for the SOCKS5 protocol by prefixing it a byte stating its | 78 | * Encode a string for the SOCKS5 protocol by prefixing it a byte stating its |
79 | * length and stipping the trailing zero byte. Truncates any string longer | 79 | * length and stripping the trailing zero byte. Truncates any string longer |
80 | * than 255 bytes. | 80 | * than 255 bytes. |
81 | * | 81 | * |
82 | * @param b buffer to contain the encoded string | 82 | * @param b buffer to contain the encoded string |
@@ -96,7 +96,10 @@ SOCK5_proto_string(unsigned char * b, | |||
96 | l=255; | 96 | l=255; |
97 | } | 97 | } |
98 | *(b++) = (unsigned char) l; | 98 | *(b++) = (unsigned char) l; |
99 | strncpy ((char *)b, s, l); | 99 | /* |
100 | * intentionally use strncpy (trailing zero byte must be stripped in b) | ||
101 | */ | ||
102 | strncpy ((char*)b, s, l); | ||
100 | return b+l; | 103 | return b+l; |
101 | } | 104 | } |
102 | 105 | ||
@@ -489,7 +492,7 @@ GNUNET_SOCKS_init_handshake_noauth () | |||
489 | */ | 492 | */ |
490 | void | 493 | void |
491 | GNUNET_SOCKS_set_handshake_destination (struct GNUNET_SOCKS_Handshake *ih, | 494 | GNUNET_SOCKS_set_handshake_destination (struct GNUNET_SOCKS_Handshake *ih, |
492 | const char *host, uint16_t port) | 495 | const char *host, uint16_t port) |
493 | { | 496 | { |
494 | union { | 497 | union { |
495 | struct in_addr in4; | 498 | struct in_addr in4; |