aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorlurchi <lurchi@strangeplace.net>2019-06-27 10:49:40 +0200
committerlurchi <lurchi@strangeplace.net>2019-06-27 10:49:40 +0200
commitb9771c5f5edcbeb965fa291a281943d866c3ddb6 (patch)
treee53141e844dfe7032d018cb5bfebd31fe02f7816 /src/vpn
parent0e7c93c3a0a3aa966503a8ae4caf3a21914e4126 (diff)
downloadgnunet-b9771c5f5edcbeb965fa291a281943d866c3ddb6.tar.gz
gnunet-b9771c5f5edcbeb965fa291a281943d866c3ddb6.zip
use GNUNET_strlcpy instead of strncpy where possible
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-helper-vpn-windows.c52
1 files changed, 45 insertions, 7 deletions
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 /*