Send connman mailing list submissions to
[email protected]
To subscribe or unsubscribe via email, send a message with subject or
body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."
Today's Topics:
1. [PATCH v0 1/3] service: Replace GTimeVal with GDateTime
(Daniel Wagner)
2. [PATCH v0 2/3] tools: Replace GTimeVal with GDateTime
(Daniel Wagner)
3. [PATCH v0 3/3] plugins/ethernet: Properly NUL-terminated strncpy()
operations
(Daniel Wagner)
4. Re: [PATCH] plugins/ethernet: fix strncpy errors with GCC>9.1
(Böszörményi Zoltán)
5. Re: [PATCH] plugins/ethernet: fix strncpy errors with GCC>9.1
(Daniel Wagner)
6. [PATCH v1 3/3] plugins/ethernet: Use stpncpy() instead of strcpy() for
interface names
(Daniel Wagner)
----------------------------------------------------------------------
Date: Sat, 2 Nov 2019 13:39:43 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v0 1/3] service: Replace GTimeVal with GDateTime
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>
GTimeVal has been deprecated. Replace it with GDateTime, which is
available since 2.26.
---
src/service.c | 42 +++++++++++++++++++++++++++++++++++-------
1 file changed, 35 insertions(+), 7 deletions(-)
diff --git a/src/service.c b/src/service.c
index 6f467eaf153b..552b788f017d 100644
--- a/src/service.c
+++ b/src/service.c
@@ -84,7 +84,7 @@ struct connman_service {
bool hidden;
bool ignore;
bool autoconnect;
- GTimeVal modified;
+ GDateTime *modified;
unsigned int order;
char *name;
char *passphrase;
@@ -378,6 +378,31 @@ static void set_split_routing(struct connman_service
*service, bool value)
service->order = 10;
}
+static void update_modified(struct connman_service *service)
+{
+ GTimeZone *tz;
+
+ if (service->modified)
+ g_date_time_unref(service->modified);
+
+ tz = g_time_zone_new_local();
+ service->modified = g_date_time_new_now(tz);
+ g_time_zone_unref(tz);
+}
+
+static void update_modified_from_iso8601(struct connman_service *service,
+ char *str)
+{
+ GTimeZone *tz;
+
+ if (service->modified)
+ g_date_time_unref(service->modified);
+
+ tz = g_time_zone_new_local();
+ service->modified = g_date_time_new_from_iso8601(str, tz);
+ g_time_zone_unref(tz);
+}
+
int __connman_service_load_modifiable(struct connman_service *service)
{
GKeyFile *keyfile;
@@ -419,7 +444,7 @@ int __connman_service_load_modifiable(struct
connman_service *service)
str = g_key_file_get_string(keyfile,
service->identifier, "Modified", NULL);
if (str) {
- g_time_val_from_iso8601(str, &service->modified);
+ update_modified_from_iso8601(service, str);
g_free(str);
}
@@ -536,7 +561,7 @@ static int service_load(struct connman_service *service)
str = g_key_file_get_string(keyfile,
service->identifier, "Modified", NULL);
if (str) {
- g_time_val_from_iso8601(str, &service->modified);
+ update_modified_from_iso8601(service, str);
g_free(str);
}
@@ -703,7 +728,7 @@ static int service_save(struct connman_service *service)
break;
}
- str = g_time_val_to_iso8601(&service->modified);
+ str = g_date_time_format_iso8601(service->modified);
if (str) {
g_key_file_set_string(keyfile, service->identifier,
"Modified", str);
@@ -3933,7 +3958,7 @@ static void service_complete(struct connman_service
*service)
if (service->connect_reason != CONNMAN_SERVICE_CONNECT_REASON_USER)
do_auto_connect(service, service->connect_reason);
- g_get_current_time(&service->modified);
+ update_modified(service);
service_save(service);
}
@@ -4861,7 +4886,7 @@ static DBusMessage *move_service(DBusConnection *conn,
}
}
- g_get_current_time(&service->modified);
+ update_modified(service);
service_save(service);
service_save(target);
@@ -5057,6 +5082,9 @@ static void service_free(gpointer user_data)
g_free(service->config_file);
g_free(service->config_entry);
+ if (service->modified)
+ g_date_time_unref(service->modified);
+
if (service->stats.timer)
g_timer_destroy(service->stats.timer);
if (service->stats_roaming.timer)
@@ -5943,7 +5971,7 @@ static int service_indicate_state(struct connman_service
*service)
"WiFi.UseWPS", false);
}
- g_get_current_time(&service->modified);
+ update_modified(service);
service_save(service);
domain_changed(service);
--
2.23.0
------------------------------
Date: Sat, 2 Nov 2019 13:39:44 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v0 2/3] tools: Replace GTimeVal with GDateTime
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>
GTimeVal has been deprecated. Replace it with GDateTime, which is
available since 2.26.
---
tools/stats-tool.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/tools/stats-tool.c b/tools/stats-tool.c
index 5695048fcdca..193eed24565f 100644
--- a/tools/stats-tool.c
+++ b/tools/stats-tool.c
@@ -108,13 +108,18 @@ static char *option_last_file_name = NULL;
static bool parse_start_ts(const char *key, const char *value,
gpointer user_data, GError **error)
{
- GTimeVal time_val;
+ GTimeZone *tz;
+ GDateTime *dt;
- if (!g_time_val_from_iso8601(value, &time_val))
+ tz = g_time_zone_new_local();
+ dt = g_date_time_new_from_iso8601(value, tz);
+ g_time_zone_unref(tz);
+ if (!dt)
return false;
- option_start_ts = time_val.tv_sec;
+ option_start_ts = g_date_time_get_second(dt);
+ g_date_time_unref(dt);
return true;
}
--
2.23.0
------------------------------
Date: Sat, 2 Nov 2019 13:39:45 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v0 3/3] plugins/ethernet: Properly NUL-terminated
strncpy() operations
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
gcc detects more string truncation since version gcc 8. All interface
names from the kernel are max 16 characters including the NUL
byte. gcc is not able to detect this. The canonical way to fix this is
to explicitly insert a NUL byte, which gcc is able to detect and
disables the warning:
In function ‘strncpy’,
inlined from ‘get_dsa_port’ at plugins/ethernet.c:102:2:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:10:
error: ‘__builtin_strncpy’ specified bound 16 equals destination size
[-Werror=stringop-truncation]
106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
plugins/ethernet.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/plugins/ethernet.c b/plugins/ethernet.c
index b0395c8331f3..d2537e2e18f4 100644
--- a/plugins/ethernet.c
+++ b/plugins/ethernet.c
@@ -74,6 +74,7 @@ static int get_vlan_vid(const char *ifname)
vifr.cmd = GET_VLAN_VID_CMD;
strncpy(vifr.device1, ifname, sizeof(vifr.device1));
+ vifr.device1[sizeof(vifr.device1) - 1] = '\0';
if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0)
vid = vifr.u.VID;
@@ -100,13 +101,17 @@ static int get_dsa_port(const char *ifname)
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
/* check if it is a vlan and get physical interface name*/
vifr.cmd = GET_VLAN_REALDEV_NAME_CMD;
strncpy(vifr.device1, ifname, sizeof(vifr.device1));
+ vifr.device1[sizeof(vifr.device1) - 1] = '\0';
- if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0)
+ if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0) {
strncpy(ifr.ifr_name, vifr.u.device2, sizeof(ifr.ifr_name));
+ ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
+ }
/* get driver info */
drvinfocmd.cmd = ETHTOOL_GDRVINFO;
--
2.23.0
------------------------------
Date: Sat, 2 Nov 2019 15:26:33 +0100
From: Böszörményi Zoltán <[email protected]>
Subject: Re: [PATCH] plugins/ethernet: fix strncpy errors with GCC>9.1
To: Daniel Wagner <[email protected]>, nick83ola <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-2; format=flowed
2019. 11. 02. 13:34 keltezéssel, Daniel Wagner írta:
> Hi,
>
> On Sun, Oct 20, 2019 at 02:29:29PM +0100, nick83ola wrote:
>> Hi to all,
>> I'm not totally sure about this part
>>
>> +#pragma GCC diagnostic push
>> +#pragma GCC diagnostic ignored "-Wstringop-truncation"
>> if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0)
>> - strncpy(ifr.ifr_name, vifr.u.device2, sizeof(ifr.ifr_name));
>> + strncpy(ifr.ifr_name, vifr.u.device2, sizeof(ifr.ifr_name) -
>> 1);
>> +#pragma GCC diagnostic pop
>>
>> The problem is that ifr_name and device2 are defined on my system with
>> two different length
>>
>> What to do in this case?
>>
>> The rest should be fine
>
> There is an artical about the string truncation detection of gcc:
>
> https://developers.redhat.com/blog/2018/05/24/detecting-string-truncation-with-gcc-8/
>
> The fix to disable the warning is to explicitly set the NUL byte after
> the strncpy. I'll send a patch.
That's where "stpncpy" is better: it returns the pointer to the next byte,
i.e. where the NULL byte should be. Or from where you can do another copy
instead of using strcat that has to find the NULL byte first.
>
> Thanks,
> Daniel
>
------------------------------
Date: Sat, 2 Nov 2019 21:38:03 +0100
From: Daniel Wagner <[email protected]>
Subject: Re: [PATCH] plugins/ethernet: fix strncpy errors with GCC>9.1
To: Böszörményi Zoltán <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
Hi Böszörményi,
On Sat, Nov 02, 2019 at 03:26:33PM +0100, Böszörményi Zoltán wrote:
> > The fix to disable the warning is to explicitly set the NUL byte after
> > the strncpy. I'll send a patch.
>
> That's where "stpncpy" is better: it returns the pointer to the next byte,
> i.e. where the NULL byte should be. Or from where you can do another copy
> instead of using strcat that has to find the NULL byte first.
Oh didn't know about stpncpy. Sounds like the right function for this
job. I've changed the strncpy to stpncpy and the compiler warnings are
gone. And it's event better as you have pointed out.
Thanks for the review!
Daniel
------------------------------
Date: Sat, 2 Nov 2019 21:46:52 +0100
From: Daniel Wagner <[email protected]>
Subject: [PATCH v1 3/3] plugins/ethernet: Use stpncpy() instead of
strcpy() for interface names
To: [email protected]
Cc: Daniel Wagner <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
gcc detects more string truncation issues since version gcc 8. All
interface names from the kernel are max 16 characters including the
NULL byte. gcc is not able to detect this. By using stpncpy we can
ensure that the destination buffers are properly terminated with NULL
bytes and gcc is happy.
stpncpy() suggested by Böszörményi Zoltán.
---
plugins/ethernet.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/plugins/ethernet.c b/plugins/ethernet.c
index b0395c8331f3..ed4208ad7ec2 100644
--- a/plugins/ethernet.c
+++ b/plugins/ethernet.c
@@ -73,7 +73,7 @@ static int get_vlan_vid(const char *ifname)
return -errno;
vifr.cmd = GET_VLAN_VID_CMD;
- strncpy(vifr.device1, ifname, sizeof(vifr.device1));
+ stpncpy(vifr.device1, ifname, sizeof(vifr.device1));
if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0)
vid = vifr.u.VID;
@@ -99,14 +99,14 @@ static int get_dsa_port(const char *ifname)
return -errno;
memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ stpncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
/* check if it is a vlan and get physical interface name*/
vifr.cmd = GET_VLAN_REALDEV_NAME_CMD;
- strncpy(vifr.device1, ifname, sizeof(vifr.device1));
+ stpncpy(vifr.device1, ifname, sizeof(vifr.device1));
if(ioctl(sk, SIOCSIFVLAN, &vifr) >= 0)
- strncpy(ifr.ifr_name, vifr.u.device2, sizeof(ifr.ifr_name));
+ stpncpy(ifr.ifr_name, vifr.u.device2, sizeof(ifr.ifr_name));
/* get driver info */
drvinfocmd.cmd = ETHTOOL_GDRVINFO;
--
2.23.0
------------------------------
Subject: Digest Footer
_______________________________________________
connman mailing list -- [email protected]
To unsubscribe send an email to [email protected]
------------------------------
End of connman Digest, Vol 49, Issue 1
**************************************