From: Leon Romanovsky Date: Sun, 9 Jan 2022 18:41:38 +0000 (+0200) Subject: rdma: Limit copy data by the destination size X-Git-Tag: v5.17.0~36^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b87671681e8aa9318e30c4e646419d96f1063d23;p=thirdparty%2Fiproute2.git rdma: Limit copy data by the destination size The strncat() function will copy upto n bytes supplied as third argument. The n bytes shouldn't be no more than destination and not the source. This change fixes the following clang compilation warnings: res-srq.c:75:25: warning: size argument in 'strncat' call appears to be size of the source [-Wstrncat-size] strncat(qp_str, tmp, sizeof(tmp) - 1); ^~~~~~~~~~~~~~~ res-srq.c:99:23: warning: size argument in 'strncat' call appears to be size of the source [-Wstrncat-size] strncat(qp_str, tmp, sizeof(tmp) - 1); ^~~~~~~~~~~~~~~ res-srq.c:142:25: warning: size argument in 'strncat' call appears to be size of the source [-Wstrncat-size] strncat(qp_str, tmp, sizeof(tmp) - 1); ^~~~~~~~~~~~~~~ Fixes: 9b272e138d23 ("rdma: Add SRQ resource tracking information") Reported-by: Stephen Hemminger Signed-off-by: Leon Romanovsky Signed-off-by: David Ahern --- diff --git a/rdma/res-srq.c b/rdma/res-srq.c index 5d8f38429..3038c3522 100644 --- a/rdma/res-srq.c +++ b/rdma/res-srq.c @@ -70,9 +70,8 @@ static int filter_srq_range_qps(struct rd *rd, struct nlattr **qp_line, *delimiter, tmp_min_range, tmp_max_range); - if (strlen(qp_str) + strlen(tmp) >= MAX_QP_STR_LEN) - return -EINVAL; - strncat(qp_str, tmp, sizeof(tmp) - 1); + strncat(qp_str, tmp, + MAX_QP_STR_LEN - strlen(qp_str) - 1); memset(tmp, 0, strlen(tmp)); *delimiter = ","; @@ -94,9 +93,7 @@ static int filter_srq_range_qps(struct rd *rd, struct nlattr **qp_line, snprintf(tmp, sizeof(tmp), "%s%d-%d", *delimiter, tmp_min_range, tmp_max_range); - if (strlen(qp_str) + strlen(tmp) >= MAX_QP_STR_LEN) - return -EINVAL; - strncat(qp_str, tmp, sizeof(tmp) - 1); + strncat(qp_str, tmp, MAX_QP_STR_LEN - strlen(qp_str) - 1); *delimiter = ","; return 0; } @@ -137,9 +134,8 @@ static int get_srq_qps(struct rd *rd, struct nlattr *qp_table, char *qp_str) qp_line[RDMA_NLDEV_ATTR_RES_LQPN])) continue; snprintf(tmp, sizeof(tmp), "%s%d", delimiter, qpn); - if (strlen(qp_str) + strlen(tmp) >= MAX_QP_STR_LEN) - goto out; - strncat(qp_str, tmp, sizeof(tmp) - 1); + strncat(qp_str, tmp, + MAX_QP_STR_LEN - strlen(qp_str) - 1); delimiter = ","; } else if (qp_line[RDMA_NLDEV_ATTR_MIN_RANGE] && qp_line[RDMA_NLDEV_ATTR_MAX_RANGE]) {