From 00c99833289ba7300e369b3b76cde83a6380640f Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 1 Sep 2025 10:27:18 +0900 Subject: [PATCH] stricter length check in copy_to_skad() --- lib/gem-nwif2.c | 11 ++++++----- lib/misc.c | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/gem-nwif2.c b/lib/gem-nwif2.c index 3c7e35e7..0bede655 100644 --- a/lib/gem-nwif2.c +++ b/lib/gem-nwif2.c @@ -122,8 +122,9 @@ static int prefix_to_in6 (int prefix, struct in6_addr* in6) static HAWK_INLINE void copy_to_skad (struct sockaddr* sa, hawk_oow_t sa_size, hawk_skad_t* skad) { - /* assume *skad is large enough */ - HAWK_MEMCPY(skad, sa, sa_size); + hawk_oow_t len; + len = (sa_size <= HAWK_SIZEOF(*skad))? sa_size: HAWK_SIZEOF(*skad); + HAWK_MEMCPY(skad, sa, len); } /* @@ -458,7 +459,7 @@ static int get_ifcfg (hawk_gem_t* gem, int s, hawk_ifcfg_t* cfg, struct ifreq* i if (lifrbuf.lifr_flags & IFF_BROADCAST) cfg->flags |= HAWK_IFCFG_BCAST; if (lifrbuf.lifr_flags & IFF_POINTOPOINT) cfg->flags |= HAWK_IFCFG_PTOP; - if (ioctl (s, SIOCGLIFMTU, &lifrbuf) <= -1) return -1; + if (ioctl(s, SIOCGLIFMTU, &lifrbuf) <= -1) return -1; cfg->mtu = lifrbuf.lifr_mtu; hawk_clear_skad(&cfg->addr); @@ -765,7 +766,7 @@ static void get_moreinfo (int s, hawk_ifcfg_t* cfg, struct ifreq* ifr) drvinfo.cmd = ETHTOOL_GDRVINFO; ifr->ifr_data = &drvinfo; - if (ioctl (s, SIOCETHTOOL, ifr) >= 0) + if (ioctl(s, SIOCETHTOOL, ifr) >= 0) { struct ethtool_stats *stats; hawk_uint8_t buf[1000]; /* TODO: make this dynamic according to drvinfo.n_stats */ @@ -774,7 +775,7 @@ static void get_moreinfo (int s, hawk_ifcfg_t* cfg, struct ifreq* ifr) stats->cmd = ETHTOOL_GSTATS; stats->n_stats = drvinfo.n_stats * HAWK_SIZEOF(stats->data[0]); ifr->ifr_data = (caddr_t) stats; - if (ioctl (s, SIOCETHTOOL, ifr) >= 0) + if (ioctl(s, SIOCETHTOOL, ifr) >= 0) { for (i = 0; i < drvinfo.n_stats; i++) { diff --git a/lib/misc.c b/lib/misc.c index a1ae87b0..e6fd8102 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -182,7 +182,6 @@ int hawk_rtx_matchvalwithucs (hawk_rtx_t* rtx, hawk_val_t* val, const hawk_ucs_t if (x <= -1) return -1; } - x = matchtre_ucs( code, ((str->ptr == substr->ptr)? opt: (opt | HAWK_TRE_NOTBOL)), substr, match, submat, hawk_rtx_getgem(rtx)