netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Maya Rashish <mrashish@redhat.com>
To: netfilter-devel@vger.kernel.org
Subject: [libnftnl PATCH 1/2] Avoid out of bound reads in tests.
Date: Wed, 17 Feb 2021 22:45:45 +0200	[thread overview]
Message-ID: <6b4add9f-7947-9f81-48c9-83b77286d2e6@redhat.com> (raw)

Our string isn't NUL-terminated. To avoid reading past
the last character, use strndup.

Signed-off-by: Maya Rashish <mrashish@redhat.com>
---
  tests/nft-expr_match-test.c  | 2 +-
  tests/nft-expr_target-test.c | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/nft-expr_match-test.c b/tests/nft-expr_match-test.c
index 39a49d8..f6b7bc0 100644
--- a/tests/nft-expr_match-test.c
+++ b/tests/nft-expr_match-test.c
@@ -71,7 +71,7 @@ int main(int argc, char *argv[])

  	nftnl_expr_set_str(ex, NFTNL_EXPR_MT_NAME, "Tests");
  	nftnl_expr_set_u32(ex, NFTNL_EXPR_MT_REV, 0x12345678);
-	nftnl_expr_set(ex, NFTNL_EXPR_MT_INFO, strdup(data), sizeof(data));
+	nftnl_expr_set(ex, NFTNL_EXPR_MT_INFO, strndup(data, sizeof(data)), sizeof(data));
  	nftnl_rule_add_expr(a, ex);

  	nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234);
diff --git a/tests/nft-expr_target-test.c b/tests/nft-expr_target-test.c
index ba56b27..a135b9c 100644
--- a/tests/nft-expr_target-test.c
+++ b/tests/nft-expr_target-test.c
@@ -71,7 +71,7 @@ int main(int argc, char *argv[])

  	nftnl_expr_set(ex, NFTNL_EXPR_TG_NAME, "test", strlen("test"));
  	nftnl_expr_set_u32(ex, NFTNL_EXPR_TG_REV, 0x56781234);
-	nftnl_expr_set(ex, NFTNL_EXPR_TG_INFO, strdup(data), sizeof(data));
+	nftnl_expr_set(ex, NFTNL_EXPR_TG_INFO, strndup(data, sizeof(data)), sizeof(data));
  	nftnl_rule_add_expr(a, ex);

  	nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234);
-- 
2.29.2


             reply	other threads:[~2021-02-17 20:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17 20:45 Maya Rashish [this message]
2021-02-17 23:00 ` [libnftnl PATCH 1/2] Avoid out of bound reads in tests Pablo Neira Ayuso
2021-02-18  6:39   ` Maya Rashish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6b4add9f-7947-9f81-48c9-83b77286d2e6@redhat.com \
    --to=mrashish@redhat.com \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).