aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/arm/gnunet-service-arm.c2
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c7
-rw-r--r--src/exit/gnunet-helper-exit-windows.c51
-rw-r--r--src/regex/regex_test_lib.c5
-rw-r--r--src/testbed/gnunet-helper-testbed.c1
-rw-r--r--src/testbed/gnunet-service-testbed.c2
-rw-r--r--src/testbed/gnunet-service-testbed_oc.c6
-rw-r--r--src/testbed/testbed_api.c1
-rw-r--r--src/testbed/testbed_api_hosts.c6
-rw-r--r--src/transport/tcp_connection_legacy.c2
-rw-r--r--src/transport/tcp_service_legacy.c2
-rw-r--r--src/util/client.c6
-rw-r--r--src/util/common_logging.c10
-rw-r--r--src/util/gnunet-ecc.c2
-rw-r--r--src/util/service.c6
-rw-r--r--src/util/socks.c9
-rw-r--r--src/vpn/gnunet-helper-vpn-windows.c52
17 files changed, 130 insertions, 40 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index 17304d3b3..4e3474cb6 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -290,7 +290,7 @@ add_unixpath (struct sockaddr **saddrs,
290 290
291 un = GNUNET_new (struct sockaddr_un); 291 un = GNUNET_new (struct sockaddr_un);
292 un->sun_family = AF_UNIX; 292 un->sun_family = AF_UNIX;
293 strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1); 293 GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path));
294#ifdef LINUX 294#ifdef LINUX
295 if (GNUNET_YES == abstract) 295 if (GNUNET_YES == abstract)
296 un->sun_path[0] = '\0'; 296 un->sun_path[0] = '\0';
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index 8d55e6386..c25f46de5 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -256,11 +256,10 @@ GCP_2s (const struct CadetPeer *cp)
256 return "NULL"; 256 return "NULL";
257 257
258 258
259 strncpy (buf, 259 GNUNET_strlcpy (buf,
260 ret, 260 ret,
261 sizeof (buf) - 1); 261 sizeof (buf));
262 GNUNET_free (ret); 262 GNUNET_free (ret);
263 buf[4] = '\0';
264 return buf; 263 return buf;
265} 264}
266 265
diff --git a/src/exit/gnunet-helper-exit-windows.c b/src/exit/gnunet-helper-exit-windows.c
index 6633fbc31..1e17ceaac 100644
--- a/src/exit/gnunet-helper-exit-windows.c
+++ b/src/exit/gnunet-helper-exit-windows.c
@@ -250,6 +250,37 @@ WINBASEAPI HANDLE WINAPI ReOpenFile (HANDLE, DWORD, DWORD, DWORD);
250 */ 250 */
251typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); 251typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
252 252
253
254/**
255 * Like strlcpy but portable. The given string @a src is copied in full length
256 * (until its null byte). The destination buffer is guaranteed to be
257 * null-terminated.
258 *
259 * to a destination buffer
260 * and ensures that the destination string is null-terminated.
261 *
262 * @param dst destination of the copy
263 * @param src source of the copy, must be null-terminated
264 * @param n the length of the string to copy, including its terminating null
265 * byte
266 * @return the length of the string that was copied, excluding the terminating
267 * null byte
268 */
269size_t
270GNUNET_strlcpy(char *dst, const char *src, size_t n)
271{
272 size_t ret;
273 size_t slen;
274
275 GNUNET_assert (0 != n);
276 ret = strlen (src);
277 slen = GNUNET_MIN (ret, n - 1);
278 memcpy (dst, src, slen);
279 dst[slen] = '\0';
280 return ret;
281}
282
283
253/** 284/**
254 * Determines if the host OS is win32 or win64 285 * Determines if the host OS is win32 or win64
255 * 286 *
@@ -473,7 +504,9 @@ setup_interface ()
473 * Set the device's hardware ID and add it to a list. 504 * Set the device's hardware ID and add it to a list.
474 * This information will later on identify this device in registry. 505 * This information will later on identify this device in registry.
475 */ 506 */
476 strncpy (hwidlist, HARDWARE_ID, LINE_LEN); 507 str_length = GNUNET_strlcpy (hwidlist,
508 HARDWARE_ID,
509 sizeof (hwidlist)) + 1;
477 /** 510 /**
478 * this is kind of over-complicated, but allows keeps things independent of 511 * this is kind of over-complicated, but allows keeps things independent of
479 * how the openvpn-hwid is actually stored. 512 * how the openvpn-hwid is actually stored.
@@ -481,8 +514,12 @@ setup_interface ()
481 * A HWID list is double-\0 terminated and \0 separated 514 * A HWID list is double-\0 terminated and \0 separated
482 */ 515 */
483 str_length = strlen (hwidlist) + 1; 516 str_length = strlen (hwidlist) + 1;
484 strncpy (&hwidlist[str_length], secondary_hwid, LINE_LEN); 517 str_length += GNUNET_strlcpy (&hwidlist[str_length],
485 str_length += strlen (&hwidlist[str_length]) + 1; 518 secondary_hwid,
519 sizeof (hwidlist) - str_length) + 1;
520 GNUNET_assert (str_length < sizeof (hwidlist));
521 hwidlist[str_length] = '\0';
522 ++str_length;
486 523
487 /** 524 /**
488 * Locate the inf-file, we need to store it somewhere where the system can 525 * Locate the inf-file, we need to store it somewhere where the system can
@@ -716,9 +753,11 @@ resolve_interface_name ()
716 /* 753 /*
717 * we have successfully found OUR instance, 754 * we have successfully found OUR instance,
718 * save the device GUID before exiting 755 * save the device GUID before exiting
756 *
757 * We can use GNUNET_strlcpy here because instance key is null-
758 * terminated by RegEnumKeyExA.
719 */ 759 */
720 760 GNUNET_strlcpy (device_guid, instance_key, sizeof (device_guid));
721 strncpy (device_guid, instance_key, 256);
722 retval = TRUE; 761 retval = TRUE;
723 fprintf (stderr, "DEBUG: Interface Name lookup succeeded on retry %d, got \"%s\" %s\n", retrys, device_visible_name, device_guid); 762 fprintf (stderr, "DEBUG: Interface Name lookup succeeded on retry %d, got \"%s\" %s\n", retrys, device_visible_name, device_guid);
724 763
@@ -1496,7 +1535,7 @@ main (int argc, char **argv)
1496 return 1; 1535 return 1;
1497 } 1536 }
1498 1537
1499 strncpy (hwid, argv[1], LINE_LEN); 1538 GNUNET_strlcpy (hwid, argv[1], sizeof (hwid));
1500 hwid[LINE_LEN - 1] = '\0'; 1539 hwid[LINE_LEN - 1] = '\0';
1501 1540
1502 /* 1541 /*
diff --git a/src/regex/regex_test_lib.c b/src/regex/regex_test_lib.c
index bd1a06a53..7becd567c 100644
--- a/src/regex/regex_test_lib.c
+++ b/src/regex/regex_test_lib.c
@@ -392,7 +392,10 @@ regex_split (struct RegexCombineCtx *ctx,
392 char *suffix; 392 char *suffix;
393 393
394 suffix = GNUNET_malloc (len - prefix_l + 1); 394 suffix = GNUNET_malloc (len - prefix_l + 1);
395 strncpy (suffix, &ctx->s[prefix_l], len - prefix_l + 1); 395 /*
396 * We can use GNUNET_strlcpy because ctx->s is null-terminated
397 */
398 GNUNET_strlcpy (suffix, &ctx->s[prefix_l], len - prefix_l + 1);
396 399
397 /* Suffix saved, truncate current node so it only contains the prefix, 400 /* Suffix saved, truncate current node so it only contains the prefix,
398 * copy any children nodes to put as grandchildren and initialize new empty 401 * copy any children nodes to put as grandchildren and initialize new empty
diff --git a/src/testbed/gnunet-helper-testbed.c b/src/testbed/gnunet-helper-testbed.c
index 25d9724fa..c56a795a6 100644
--- a/src/testbed/gnunet-helper-testbed.c
+++ b/src/testbed/gnunet-helper-testbed.c
@@ -374,6 +374,7 @@ tokenizer_cb (void *cls,
374 if (0 != hostname_size) 374 if (0 != hostname_size)
375 { 375 {
376 hostname = GNUNET_malloc (hostname_size + 1); 376 hostname = GNUNET_malloc (hostname_size + 1);
377 /* intentionally use strncpy (hostname not null terminated) */
377 (void) strncpy (hostname, ((char *) &msg[1]) + trusted_ip_size + 1, 378 (void) strncpy (hostname, ((char *) &msg[1]) + trusted_ip_size + 1,
378 hostname_size); 379 hostname_size);
379 hostname[hostname_size] = '\0'; 380 hostname[hostname_size] = '\0';
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 51460f65b..d740d31bc 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -541,10 +541,12 @@ handle_add_host (void *cls,
541 if (0 != username_length) 541 if (0 != username_length)
542 { 542 {
543 username = GNUNET_malloc (username_length + 1); 543 username = GNUNET_malloc (username_length + 1);
544 /* intentionally use strncpy (message payload is not null terminated) */
544 strncpy (username, ptr, username_length); 545 strncpy (username, ptr, username_length);
545 ptr += username_length; 546 ptr += username_length;
546 } 547 }
547 hostname = GNUNET_malloc (hostname_length + 1); 548 hostname = GNUNET_malloc (hostname_length + 1);
549 /* intentionally use strncpy (message payload is not null terminated) */
548 strncpy (hostname, 550 strncpy (hostname,
549 ptr, 551 ptr,
550 hostname_length); 552 hostname_length);
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c
index 98a4282df..4d6a4d446 100644
--- a/src/testbed/gnunet-service-testbed_oc.c
+++ b/src/testbed/gnunet-service-testbed_oc.c
@@ -1908,9 +1908,9 @@ handle_remote_overlay_connect (void *cls,
1908 rocc->a_id = msg->peer_identity; 1908 rocc->a_id = msg->peer_identity;
1909 GNUNET_TESTING_peer_get_identity (peer->details.local.peer, 1909 GNUNET_TESTING_peer_get_identity (peer->details.local.peer,
1910 &pid); 1910 &pid);
1911 (void) strncpy (pid_str, 1911 (void) GNUNET_strlcpy (pid_str,
1912 GNUNET_i2s (&pid), 1912 GNUNET_i2s (&pid),
1913 15); 1913 sizeof (pid_str));
1914 LOG_DEBUG ("0x%llx: Remote overlay connect %s to peer %s with hello size: %u\n", 1914 LOG_DEBUG ("0x%llx: Remote overlay connect %s to peer %s with hello size: %u\n",
1915 rocc->op_id, 1915 rocc->op_id,
1916 pid_str, 1916 pid_str,
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index 793ed4edd..22ce7eb72 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -2014,6 +2014,7 @@ GNUNET_TESTBED_create_helper_init_msg_ (const char *trusted_ip,
2014 msg->config_size = htons (config_size); 2014 msg->config_size = htons (config_size);
2015 (void) strcpy ((char *) &msg[1], trusted_ip); 2015 (void) strcpy ((char *) &msg[1], trusted_ip);
2016 if (0 != hostname_len) 2016 if (0 != hostname_len)
2017 /* intentionally use strncpy (no null byte needed) */
2017 (void) strncpy (((char *) &msg[1]) + trusted_ip_len + 1, hostname, 2018 (void) strncpy (((char *) &msg[1]) + trusted_ip_len + 1, hostname,
2018 hostname_len); 2019 hostname_len);
2019 return msg; 2020 return msg;
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c
index 327f84f2a..d6521f766 100644
--- a/src/testbed/testbed_api_hosts.c
+++ b/src/testbed/testbed_api_hosts.c
@@ -462,6 +462,9 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
462 { 462 {
463 size = pmatch[2].rm_eo - pmatch[2].rm_so; 463 size = pmatch[2].rm_eo - pmatch[2].rm_so;
464 username = GNUNET_malloc (size + 1); 464 username = GNUNET_malloc (size + 1);
465 /*
466 * Intentionally use strncpy (buf is not necessarily null-terminated)
467 */
465 username[size] = '\0'; 468 username[size] = '\0';
466 GNUNET_assert (NULL != strncpy (username, buf + pmatch[2].rm_so, size)); 469 GNUNET_assert (NULL != strncpy (username, buf + pmatch[2].rm_so, size));
467 } 470 }
@@ -471,6 +474,9 @@ GNUNET_TESTBED_hosts_load_from_file (const char *filename,
471 } 474 }
472 size = pmatch[3].rm_eo - pmatch[3].rm_so; 475 size = pmatch[3].rm_eo - pmatch[3].rm_so;
473 hostname = GNUNET_malloc (size + 1); 476 hostname = GNUNET_malloc (size + 1);
477 /*
478 * Intentionally use strncpy (buf is not necessarily null-terminated)
479 */
474 hostname[size] = '\0'; 480 hostname[size] = '\0';
475 GNUNET_assert (NULL != strncpy (hostname, buf + pmatch[3].rm_so, size)); 481 GNUNET_assert (NULL != strncpy (hostname, buf + pmatch[3].rm_so, size));
476 LOG (GNUNET_ERROR_TYPE_DEBUG, 482 LOG (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/tcp_connection_legacy.c b/src/transport/tcp_connection_legacy.c
index 6ecf50b79..cfb088361 100644
--- a/src/transport/tcp_connection_legacy.c
+++ b/src/transport/tcp_connection_legacy.c
@@ -901,7 +901,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA
901 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ 901 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
902 un = GNUNET_new (struct sockaddr_un); 902 un = GNUNET_new (struct sockaddr_un);
903 un->sun_family = AF_UNIX; 903 un->sun_family = AF_UNIX;
904 strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1); 904 GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path));
905#ifdef LINUX 905#ifdef LINUX
906 { 906 {
907 int abstract; 907 int abstract;
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c
index 641d0195a..19508a39f 100644
--- a/src/transport/tcp_service_legacy.c
+++ b/src/transport/tcp_service_legacy.c
@@ -468,7 +468,7 @@ add_unixpath (struct sockaddr **saddrs,
468 468
469 un = GNUNET_new (struct sockaddr_un); 469 un = GNUNET_new (struct sockaddr_un);
470 un->sun_family = AF_UNIX; 470 un->sun_family = AF_UNIX;
471 strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1); 471 GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path));
472#ifdef LINUX 472#ifdef LINUX
473 if (GNUNET_YES == abstract) 473 if (GNUNET_YES == abstract)
474 un->sun_path[0] = '\0'; 474 un->sun_path[0] = '\0';
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 */
490void 493void
491GNUNET_SOCKS_set_handshake_destination (struct GNUNET_SOCKS_Handshake *ih, 494GNUNET_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;
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c
index 14c0c3fec..4ccecb873 100644
--- a/src/vpn/gnunet-helper-vpn-windows.c
+++ b/src/vpn/gnunet-helper-vpn-windows.c
@@ -250,6 +250,37 @@ WINBASEAPI HANDLE WINAPI ReOpenFile (HANDLE, DWORD, DWORD, DWORD);
250 */ 250 */
251typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); 251typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
252 252
253
254/**
255 * Like strlcpy but portable. The given string @a src is copied in full length
256 * (until its null byte). The destination buffer is guaranteed to be
257 * null-terminated.
258 *
259 * to a destination buffer
260 * and ensures that the destination string is null-terminated.
261 *
262 * @param dst destination of the copy
263 * @param src source of the copy, must be null-terminated
264 * @param n the length of the string to copy, including its terminating null
265 * byte
266 * @return the length of the string that was copied, excluding the terminating
267 * null byte
268 */
269size_t
270GNUNET_strlcpy(char *dst, const char *src, size_t n)
271{
272 size_t ret;
273 size_t slen;
274
275 GNUNET_assert (0 != n);
276 ret = strlen (src);
277 slen = GNUNET_MIN (ret, n - 1);
278 memcpy (dst, src, slen);
279 dst[slen] = '\0';
280 return ret;
281}
282
283
253/** 284/**
254 * Determines if the host OS is win32 or win64 285 * Determines if the host OS is win32 or win64
255 * 286 *
@@ -476,16 +507,21 @@ setup_interface ()
476 * Set the device's hardware ID and add it to a list. 507 * Set the device's hardware ID and add it to a list.
477 * This information will later on identify this device in registry. 508 * This information will later on identify this device in registry.
478 */ 509 */
479 strncpy (hwidlist, HARDWARE_ID, LINE_LEN); 510 str_len = GNUNET_strlcpy (hwidlist,
511 HARDWARE_ID,
512 sizeof (hwidList)) + 1;
480 /** 513 /**
481 * this is kind of over-complicated, but allows keeps things independent of 514 * this is kind of over-complicated, but allows keeps things independent of
482 * how the openvpn-hwid is actually stored. 515 * how the openvpn-hwid is actually stored.
483 * 516 *
484 * A HWID list is double-\0 terminated and \0 separated 517 * A HWID list is double-\0 terminated and \0 separated
485 */ 518 */
486 str_length = strlen (hwidlist) + 1; 519 str_len += GNUNET_strlcpy (&hwidlist[str_length],
487 strncpy (&hwidlist[str_length], secondary_hwid, LINE_LEN); 520 secondary_hwid,
488 str_length += strlen (&hwidlist[str_length]) + 1; 521 sizeof (hwidlist) - str_len) + 1;
522 GNUNET_assert (str_len < sizeof (hwidlist));
523 hwidlist[str_len] = '\0';
524 ++str_len;
489 525
490 /** 526 /**
491 * Locate the inf-file, we need to store it somewhere where the system can 527 * Locate the inf-file, we need to store it somewhere where the system can
@@ -719,9 +755,11 @@ resolve_interface_name ()
719 /* 755 /*
720 * we have successfully found OUR instance, 756 * we have successfully found OUR instance,
721 * save the device GUID before exiting 757 * save the device GUID before exiting
758 *
759 * We can use GNUNET_strlcpy here because instance key is null-
760 * terminated by RegEnumKeyExA.
722 */ 761 */
723 762 GNUNET_strlcpy (device_guid, instance_key, sizeof (device_guid));
724 strncpy (device_guid, instance_key, 256);
725 retval = TRUE; 763 retval = TRUE;
726 fprintf (stderr, "DEBUG: Interface Name lookup succeeded on retry %d, got \"%s\" %s\n", retrys, device_visible_name, device_guid); 764 fprintf (stderr, "DEBUG: Interface Name lookup succeeded on retry %d, got \"%s\" %s\n", retrys, device_visible_name, device_guid);
727 765
@@ -1494,7 +1532,7 @@ main (int argc, char **argv)
1494 return 1; 1532 return 1;
1495 } 1533 }
1496 1534
1497 strncpy (hwid, argv[1], LINE_LEN); 1535 GNUNET_strlcpy (hwid, argv[1], sizeof (hwid));
1498 hwid[LINE_LEN - 1] = '\0'; 1536 hwid[LINE_LEN - 1] = '\0';
1499 1537
1500 /* 1538 /*