[NetworkManager-pptp] pppd-plugin: use g_strlcpy()
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [NetworkManager-pptp] pppd-plugin: use g_strlcpy()
- Date: Thu, 21 Jun 2018 05:42:58 +0000 (UTC)
commit a7d75ac67d171f4f4c2bd2781c739e2e520720ea
Author: Lubomir Rintel <lkundrak v3 sk>
Date: Fri Jun 8 11:45:33 2018 +0200
pppd-plugin: use g_strlcpy()
It's nicer but also doesn't annoy gcc 8: "error: ‘strncpy’ specified bound
depends on the length of the source argument [-Werror=stringop-overflow=]"
https://gitlab.gnome.org/GNOME/NetworkManager-pptp/merge_requests/3
src/nm-pptp-pppd-plugin.c | 19 ++++---------------
1 file changed, 4 insertions(+), 15 deletions(-)
---
diff --git a/src/nm-pptp-pppd-plugin.c b/src/nm-pptp-pppd-plugin.c
index 1993b8f..f35c635 100644
--- a/src/nm-pptp-pppd-plugin.c
+++ b/src/nm-pptp-pppd-plugin.c
@@ -253,7 +253,6 @@ get_credentials (char *username, char *password)
{
const char *my_username = NULL;
const char *my_password = NULL;
- size_t len;
GVariant *ret;
GError *error = NULL;
@@ -284,21 +283,11 @@ get_credentials (char *username, char *password)
g_variant_get (ret, "(&s&s)", &my_username, &my_password);
- if (my_username) {
- len = strlen (my_username) + 1;
- len = len < MAXNAMELEN ? len : MAXNAMELEN;
+ if (my_username)
+ g_strlcpy (username, my_username, MAXNAMELEN);
- strncpy (username, my_username, len);
- username[len - 1] = '\0';
- }
-
- if (my_password) {
- len = strlen (my_password) + 1;
- len = len < MAXSECRETLEN ? len : MAXSECRETLEN;
-
- strncpy (password, my_password, len);
- password[len - 1] = '\0';
- }
+ if (my_password)
+ g_strlcpy (password, my_password, MAXSECRETLEN);
g_variant_unref (ret);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]