aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-helper-vpn-windows.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/src/vpn/gnunet-helper-vpn-windows.c b/src/vpn/gnunet-helper-vpn-windows.c
index 14c0c3fec..17f32c5a8 100644
--- a/src/vpn/gnunet-helper-vpn-windows.c
+++ b/src/vpn/gnunet-helper-vpn-windows.c
@@ -250,6 +250,33 @@ 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 until its null
256 * byte or until @a n - 1 bytes have been read. The destination buffer is
257 * guaranteed to be null-terminated.
258 *
259 * @param dst destination of the copy (must be @a n bytes long)
260 * @param src source of the copy (at most @a n - 1 bytes will be read)
261 * @param n the length of the string to copy, including its terminating null
262 * byte
263 * @return the length of the string that was copied, excluding the terminating
264 * null byte
265 */
266size_t
267GNUNET_strlcpy(char *dst, const char *src, size_t n)
268{
269 size_t ret;
270 size_t slen;
271
272 GNUNET_assert (0 != n);
273 slen = strnlen (src, n - 1);
274 memcpy (dst, src, slen);
275 dst[slen] = '\0';
276 return slen;
277}
278
279
253/** 280/**
254 * Determines if the host OS is win32 or win64 281 * Determines if the host OS is win32 or win64
255 * 282 *
@@ -476,16 +503,21 @@ setup_interface ()
476 * Set the device's hardware ID and add it to a list. 503 * Set the device's hardware ID and add it to a list.
477 * This information will later on identify this device in registry. 504 * This information will later on identify this device in registry.
478 */ 505 */
479 strncpy (hwidlist, HARDWARE_ID, LINE_LEN); 506 str_len = GNUNET_strlcpy (hwidlist,
507 HARDWARE_ID,
508 sizeof (hwidList)) + 1;
480 /** 509 /**
481 * this is kind of over-complicated, but allows keeps things independent of 510 * this is kind of over-complicated, but allows keeps things independent of
482 * how the openvpn-hwid is actually stored. 511 * how the openvpn-hwid is actually stored.
483 * 512 *
484 * A HWID list is double-\0 terminated and \0 separated 513 * A HWID list is double-\0 terminated and \0 separated
485 */ 514 */
486 str_length = strlen (hwidlist) + 1; 515 str_len += GNUNET_strlcpy (&hwidlist[str_length],
487 strncpy (&hwidlist[str_length], secondary_hwid, LINE_LEN); 516 secondary_hwid,
488 str_length += strlen (&hwidlist[str_length]) + 1; 517 sizeof (hwidlist) - str_len) + 1;
518 GNUNET_assert (str_len < sizeof (hwidlist));
519 hwidlist[str_len] = '\0';
520 ++str_len;
489 521
490 /** 522 /**
491 * Locate the inf-file, we need to store it somewhere where the system can 523 * Locate the inf-file, we need to store it somewhere where the system can
@@ -720,8 +752,7 @@ resolve_interface_name ()
720 * we have successfully found OUR instance, 752 * we have successfully found OUR instance,
721 * save the device GUID before exiting 753 * save the device GUID before exiting
722 */ 754 */
723 755 GNUNET_strlcpy (device_guid, instance_key, sizeof (device_guid));
724 strncpy (device_guid, instance_key, 256);
725 retval = TRUE; 756 retval = TRUE;
726 fprintf (stderr, "DEBUG: Interface Name lookup succeeded on retry %d, got \"%s\" %s\n", retrys, device_visible_name, device_guid); 757 fprintf (stderr, "DEBUG: Interface Name lookup succeeded on retry %d, got \"%s\" %s\n", retrys, device_visible_name, device_guid);
727 758
@@ -1494,8 +1525,7 @@ main (int argc, char **argv)
1494 return 1; 1525 return 1;
1495 } 1526 }
1496 1527
1497 strncpy (hwid, argv[1], LINE_LEN); 1528 GNUNET_strlcpy (hwid, argv[1], sizeof (hwid));
1498 hwid[LINE_LEN - 1] = '\0';
1499 1529
1500 /* 1530 /*
1501 * We use our PID for finding/resolving the control-panel name of our virtual 1531 * We use our PID for finding/resolving the control-panel name of our virtual