Skip to content

Commit

Permalink
Suppress irrelevant gcc warning (mpls).
Browse files Browse the repository at this point in the history
Modern gcc can warn about MPLS array accessed above its defined size
(which is MPLS_DEPTH) in Elements switch:

  warning: array subscript is above array bounds [-Warray-bounds]

Disabling this warning is safe, because, these statements only called
for a valid array length (due to template definition is based on
MPLS_DEPTH), so, supposedly over-reading code is never called.
For a double safety, sanity checking is added for --promisc-mpls value
(which defines MPLS_DEPTH) to be in range of 1..10.
  • Loading branch information
aabc committed Jan 19, 2016
1 parent a7eff55 commit f70fa76
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 5 additions & 4 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ do
--enable-sampl*) KOPTS="$KOPTS -DENABLE_SAMPLER" ;;
--enable-aggr*) KOPTS="$KOPTS -DENABLE_AGGR" ;;
--enable-promi*) ENABLE_PROMISC=1 ;;
--promisc-mpls*) ENABLE_PROMISC=1; PROMISC_MPLS=1; MPLS_DEPTH="$ac_optarg" ;;
--promisc-mpls*) ENABLE_PROMISC=1; PROMISC_MPLS=1; MPLS_DEPTH=${ac_optarg:-3} ;;
--enable-snmp-r*) KOPTS="$KOPTS -DENABLE_SNMP" ;;
--enable-physdev) KOPTS="$KOPTS -DENABLE_PHYSDEV" ;;
--enable-physdev-over*) KOPTS="$KOPTS -DENABLE_PHYSDEV_OVER" ;;
Expand All @@ -324,11 +324,12 @@ done
if [ "$ENABLE_PROMISC" = 1 ]; then KOPTS="$KOPTS -DENABLE_PROMISC"; fi
if [ "$PROMISC_MPLS" = 1 ]; then
KOPTS="$KOPTS -DPROMISC_MPLS"
if [ "$MPLS_DEPTH" -gt 10 ]; then
case "$MPLS_DEPTH" in (*[!0-9]*|"") MPLS_DEPTH=1 ;; esac
if [ "$MPLS_DEPTH" -lt 1 ]; then
echo "! Requested MPLS stack depth is too small, limiting to 1."
elif [ "$MPLS_DEPTH" -gt 10 ]; then
echo "! Requested MPLS stack depth is too big, limiting to 10."
MPLS_DEPTH=10;
elif [ ! "$MPLS_DEPTH" ]; then
MPLS_DEPTH=3
fi
if [ "$MPLS_DEPTH" -ge 1 ]; then KOPTS="$KOPTS -DMPLS_DEPTH=$MPLS_DEPTH"; fi
fi
Expand Down
6 changes: 6 additions & 0 deletions ipt_NETFLOW.c
Original file line number Diff line number Diff line change
Expand Up @@ -3463,6 +3463,8 @@ static inline void add_tpl_field(__u8 *ptr, const int type, const struct ipt_net
case sourceMacAddress: memcpy(ptr, &nf->tuple.h_src, ETH_ALEN); break;
#endif
#ifdef MPLS_DEPTH
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Warray-bounds"
case MPLS_LABEL_1: memcpy(ptr, &nf->tuple.mpls[0], 3); break;
case MPLS_LABEL_2: memcpy(ptr, &nf->tuple.mpls[1], 3); break;
case MPLS_LABEL_3: memcpy(ptr, &nf->tuple.mpls[2], 3); break;
Expand All @@ -3475,6 +3477,7 @@ static inline void add_tpl_field(__u8 *ptr, const int type, const struct ipt_net
case MPLS_LABEL_9: memcpy(ptr, &nf->tuple.mpls[8], 3); break;
case MPLS_LABEL_10: memcpy(ptr, &nf->tuple.mpls[9], 3); break;
# endif
# pragma GCC diagnostic pop
case mplsTopLabelTTL: *ptr = ntohl(nf->tuple.mpls[0]); break;
#endif
#ifdef ENABLE_DIRECTION
Expand Down Expand Up @@ -5413,6 +5416,9 @@ static int __init ipt_netflow_init(void)
}

#ifdef MPLS_DEPTH
/* template_mpls is terminated on the MPLS_DEPTH mark, so, it
* never send Element which can access mpls labels array above
* its defined MPLS_DEPTH value. */
if (MPLS_DEPTH >= 0 && MPLS_DEPTH < 10)
template_mpls.types[MPLS_LABELS_BASE_INDEX + MPLS_DEPTH] = 0;
#endif
Expand Down

0 comments on commit f70fa76

Please sign in to comment.