[PATCH] virNWFilterSnoopLeaseFileLoad: Don't typecast 'ipl.timeout'

Peter Krempa posted 1 patch 1 year, 3 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/03eb02932e3e0144fc83b4b25b71a9a7fbe17420.1673268046.git.pkrempa@redhat.com
src/nwfilter/nwfilter_dhcpsnoop.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
[PATCH] virNWFilterSnoopLeaseFileLoad: Don't typecast 'ipl.timeout'
Posted by Peter Krempa 1 year, 3 months ago
Use a temporary variable to avoid memory alignment issues on ARM:

../src/nwfilter/nwfilter_dhcpsnoop.c: In function ‘virNWFilterSnoopLeaseFileLoad’:
../src/nwfilter/nwfilter_dhcpsnoop.c:1745:20: error: cast increases required alignment of target type [-Werror=cast-align]
 1745 |                    (unsigned long long *) &ipl.timeout,
      |

Fixes: 0d278aa089bf3a00bf2d6e56d2f01ea4677190a7
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---

Corresponding job:

https://gitlab.com/pipo.sk/libvirt/-/jobs/3565653957

 src/nwfilter/nwfilter_dhcpsnoop.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
index e604d67b96..20afc1b2d4 100644
--- a/src/nwfilter/nwfilter_dhcpsnoop.c
+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
@@ -1733,6 +1733,8 @@ virNWFilterSnoopLeaseFileLoad(void)
     fp = fopen(LEASEFILE, "r");
     time(&now);
     while (fp && fgets(line, sizeof(line), fp)) {
+        unsigned long long timeout;
+
         if (line[strlen(line)-1] != '\n') {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("virNWFilterSnoopLeaseFileLoad lease file "
@@ -1742,13 +1744,13 @@ virNWFilterSnoopLeaseFileLoad(void)
         ln++;
         /* key len 54 = "VMUUID"+'-'+"MAC" */
         if (sscanf(line, "%llu %54s %15s %15s",
-                   (unsigned long long *) &ipl.timeout,
-                   ifkey, ipstr, srvstr) < 4) {
+                   &timeout, ifkey, ipstr, srvstr) < 4) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("virNWFilterSnoopLeaseFileLoad lease file "
                              "line %d corrupt"), ln);
             break;
         }
+        ipl.timeout = timeout;
         if (ipl.timeout && ipl.timeout < now)
             continue;
         req = virNWFilterSnoopReqGetByIFKey(ifkey);
-- 
2.38.1

Re: [PATCH] virNWFilterSnoopLeaseFileLoad: Don't typecast 'ipl.timeout'
Posted by Martin Kletzander 1 year, 3 months ago
On Mon, Jan 09, 2023 at 01:41:17PM +0100, Peter Krempa wrote:
>Use a temporary variable to avoid memory alignment issues on ARM:
>
>../src/nwfilter/nwfilter_dhcpsnoop.c: In function ‘virNWFilterSnoopLeaseFileLoad’:
>../src/nwfilter/nwfilter_dhcpsnoop.c:1745:20: error: cast increases required alignment of target type [-Werror=cast-align]
> 1745 |                    (unsigned long long *) &ipl.timeout,
>      |
>
>Fixes: 0d278aa089bf3a00bf2d6e56d2f01ea4677190a7
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>

>---
>
>Corresponding job:
>
>https://gitlab.com/pipo.sk/libvirt/-/jobs/3565653957
>
> src/nwfilter/nwfilter_dhcpsnoop.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
>diff --git a/src/nwfilter/nwfilter_dhcpsnoop.c b/src/nwfilter/nwfilter_dhcpsnoop.c
>index e604d67b96..20afc1b2d4 100644
>--- a/src/nwfilter/nwfilter_dhcpsnoop.c
>+++ b/src/nwfilter/nwfilter_dhcpsnoop.c
>@@ -1733,6 +1733,8 @@ virNWFilterSnoopLeaseFileLoad(void)
>     fp = fopen(LEASEFILE, "r");
>     time(&now);
>     while (fp && fgets(line, sizeof(line), fp)) {
>+        unsigned long long timeout;
>+
>         if (line[strlen(line)-1] != '\n') {
>             virReportError(VIR_ERR_INTERNAL_ERROR,
>                            _("virNWFilterSnoopLeaseFileLoad lease file "
>@@ -1742,13 +1744,13 @@ virNWFilterSnoopLeaseFileLoad(void)
>         ln++;
>         /* key len 54 = "VMUUID"+'-'+"MAC" */
>         if (sscanf(line, "%llu %54s %15s %15s",
>-                   (unsigned long long *) &ipl.timeout,
>-                   ifkey, ipstr, srvstr) < 4) {
>+                   &timeout, ifkey, ipstr, srvstr) < 4) {
>             virReportError(VIR_ERR_INTERNAL_ERROR,
>                            _("virNWFilterSnoopLeaseFileLoad lease file "
>                              "line %d corrupt"), ln);
>             break;
>         }
>+        ipl.timeout = timeout;
>         if (ipl.timeout && ipl.timeout < now)
>             continue;
>         req = virNWFilterSnoopReqGetByIFKey(ifkey);
>-- 
>2.38.1
>