aboutsummaryrefslogtreecommitdiff
path: root/src/exit/gnunet-helper-exit-windows.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exit/gnunet-helper-exit-windows.c')
-rw-r--r--src/exit/gnunet-helper-exit-windows.c51
1 files changed, 45 insertions, 6 deletions
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 /*