lttng-dev.lists.lttng.org archive mirror
 help / color / mirror / Atom feed
From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: jgalar@efficios.com, simon.marchi@efficios.com
Cc: lttng-dev@lists.lttng.org
Subject: [PATCH babeltrace 1/1] Fix: test_bitfield: buffer overrun accesses
Date: Sat, 18 May 2019 16:25:23 -0400	[thread overview]
Message-ID: <20190518202523.23618-1-mathieu.desnoyers__15170.0908363395$1558211488$gmane$org@efficios.com> (raw)

This issue is due to a type mismatch between union member vs type passed
as parameter to the macros as found by Coverity:

** CID 1401409:  Memory - corruptions  (OVERRUN)
/tests/lib/test_bitfield.c: 450 in run_test_signed_write()

Issue introduced by commit 0675eb8c07 "Extend test_bitfield coverage"

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I14c9d69011b369e5dc8be4305ac8bf32cc86d3dd
---
 tests/lib/test_bitfield.c | 64 +++++++++++++++++++++++------------------------
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/tests/lib/test_bitfield.c b/tests/lib/test_bitfield.c
index 5ba566f6..bc61e118 100644
--- a/tests/lib/test_bitfield.c
+++ b/tests/lib/test_bitfield.c
@@ -285,32 +285,32 @@ void run_test_unsigned_read(unsigned int src_ui, unsigned long long src_ull)
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.s, unsigned char, s, l, src_ui);
-			bt_bitfield_read(target.c, unsigned short, s, l, &readval_ui);
+			bt_bitfield_write(target.c, unsigned char, s, l, src_ui);
+			bt_bitfield_read(target.s, unsigned short, s, l, &readval_ui);
 			if (check_result(src_ui, readval_ui, target.c, unsigned short,
 					s, l, UNSIGNED_INT_READ_TEST_DESC_FMT_STR)) {
 				return;
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.i, unsigned char, s, l, src_ui);
-			bt_bitfield_read(target.c, unsigned int, s, l, &readval_ui);
+			bt_bitfield_write(target.c, unsigned char, s, l, src_ui);
+			bt_bitfield_read(target.i, unsigned int, s, l, &readval_ui);
 			if (check_result(src_ui, readval_ui, target.c, unsigned int,
 					s, l, UNSIGNED_INT_READ_TEST_DESC_FMT_STR)) {
 				return;
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.l, unsigned char, s, l, src_ui);
-			bt_bitfield_read(target.c, unsigned long, s, l, &readval_ui);
+			bt_bitfield_write(target.c, unsigned char, s, l, src_ui);
+			bt_bitfield_read(target.l, unsigned long, s, l, &readval_ui);
 			if (check_result(src_ui, readval_ui, target.c, unsigned long,
 					s, l, UNSIGNED_INT_READ_TEST_DESC_FMT_STR)) {
 				return;
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.ll, unsigned char, s, l, src_ui);
-			bt_bitfield_read(target.c, unsigned long long, s, l, &readval_ui);
+			bt_bitfield_write(target.c, unsigned char, s, l, src_ui);
+			bt_bitfield_read(target.ll, unsigned long long, s, l, &readval_ui);
 			if (check_result(src_ui, readval_ui, target.c, unsigned long long,
 					s, l, UNSIGNED_INT_READ_TEST_DESC_FMT_STR)) {
 				return;
@@ -333,32 +333,32 @@ void run_test_unsigned_read(unsigned int src_ui, unsigned long long src_ull)
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.s, unsigned char, s, l, src_ull);
-			bt_bitfield_read(target.c, unsigned short, s, l, &readval_ull);
+			bt_bitfield_write(target.c, unsigned char, s, l, src_ull);
+			bt_bitfield_read(target.s, unsigned short, s, l, &readval_ull);
 			if (check_result(src_ull, readval_ull, target.c, unsigned short,
 					s, l, UNSIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
 				return;
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.i, unsigned char, s, l, src_ull);
-			bt_bitfield_read(target.c, unsigned int, s, l, &readval_ull);
+			bt_bitfield_write(target.c, unsigned char, s, l, src_ull);
+			bt_bitfield_read(target.i, unsigned int, s, l, &readval_ull);
 			if (check_result(src_ull, readval_ull, target.c, unsigned int,
 					s, l, UNSIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
 				return;
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.l, unsigned char, s, l, src_ull);
-			bt_bitfield_read(target.c, unsigned long, s, l, &readval_ull);
+			bt_bitfield_write(target.c, unsigned char, s, l, src_ull);
+			bt_bitfield_read(target.l, unsigned long, s, l, &readval_ull);
 			if (check_result(src_ull, readval_ull, target.c, unsigned long,
 					s, l, UNSIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
 				return;
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.ll, unsigned char, s, l, src_ull);
-			bt_bitfield_read(target.c, unsigned long long, s, l, &readval_ull);
+			bt_bitfield_write(target.c, unsigned char, s, l, src_ull);
+			bt_bitfield_read(target.ll, unsigned long long, s, l, &readval_ull);
 			if (check_result(src_ull, readval_ull, target.c, unsigned long long,
 					s, l, UNSIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
 				return;
@@ -520,32 +520,32 @@ void run_test_signed_read(int src_i, long long src_ll)
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.s, signed char, s, l, src_i);
-			bt_bitfield_read(target.c, short, s, l, &readval_i);
+			bt_bitfield_write(target.c, signed char, s, l, src_i);
+			bt_bitfield_read(target.s, short, s, l, &readval_i);
 			if (check_result(src_i, readval_i, target.c, short,
 					s, l, SIGNED_INT_READ_TEST_DESC_FMT_STR)) {
 				return;
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.i, signed char, s, l, src_i);
-			bt_bitfield_read(target.c, int, s, l, &readval_i);
+			bt_bitfield_write(target.c, signed char, s, l, src_i);
+			bt_bitfield_read(target.i, int, s, l, &readval_i);
 			if (check_result(src_i, readval_i, target.c, int,
 					s, l, SIGNED_INT_READ_TEST_DESC_FMT_STR)) {
 				return;
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.l, signed char, s, l, src_i);
-			bt_bitfield_read(target.c, long, s, l, &readval_i);
+			bt_bitfield_write(target.c, signed char, s, l, src_i);
+			bt_bitfield_read(target.l, long, s, l, &readval_i);
 			if (check_result(src_i, readval_i, target.c, long,
 					s, l, SIGNED_INT_READ_TEST_DESC_FMT_STR)) {
 				return;
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.ll, signed char, s, l, src_i);
-			bt_bitfield_read(target.c, long long, s, l, &readval_i);
+			bt_bitfield_write(target.c, signed char, s, l, src_i);
+			bt_bitfield_read(target.ll, long long, s, l, &readval_i);
 			if (check_result(src_i, readval_i, target.c, long long,
 					s, l, SIGNED_INT_READ_TEST_DESC_FMT_STR)) {
 				return;
@@ -571,32 +571,32 @@ void run_test_signed_read(int src_i, long long src_ll)
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.s, signed char, s, l, src_ll);
-			bt_bitfield_read(target.c, short, s, l, &readval_ll);
+			bt_bitfield_write(target.c, signed char, s, l, src_ll);
+			bt_bitfield_read(target.s, short, s, l, &readval_ll);
 			if (check_result(src_ll, readval_ll, target.c, short,
 					s, l, SIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
 				return;
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.i, signed char, s, l, src_ll);
-			bt_bitfield_read(target.c, int, s, l, &readval_ll);
+			bt_bitfield_write(target.c, signed char, s, l, src_ll);
+			bt_bitfield_read(target.i, int, s, l, &readval_ll);
 			if (check_result(src_ll, readval_ll, target.c, int,
 					s, l, SIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
 				return;
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.l, signed char, s, l, src_ll);
-			bt_bitfield_read(target.c, long, s, l, &readval_ll);
+			bt_bitfield_write(target.c, signed char, s, l, src_ll);
+			bt_bitfield_read(target.l, long, s, l, &readval_ll);
 			if (check_result(src_ll, readval_ll, target.c, long,
 					s, l, SIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
 				return;
 			}
 
 			init_byte_array(target.c, TEST_LEN, 0xFF);
-			bt_bitfield_write(target.ll, signed char, s, l, src_ll);
-			bt_bitfield_read(target.c, long long, s, l, &readval_ll);
+			bt_bitfield_write(target.c, signed char, s, l, src_ll);
+			bt_bitfield_read(target.ll, long long, s, l, &readval_ll);
 			if (check_result(src_ll, readval_ll, target.c, long long,
 					s, l, SIGNED_LONG_LONG_READ_TEST_DESC_FMT_STR)) {
 				return;
-- 
2.11.0

             reply	other threads:[~2019-05-18 20:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-18 20:25 Mathieu Desnoyers [this message]
     [not found] <20190518202523.23618-1-mathieu.desnoyers@efficios.com>
2019-05-21 20:15 ` [PATCH babeltrace 1/1] Fix: test_bitfield: buffer overrun accesses Jérémie Galarneau

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='20190518202523.23618-1-mathieu.desnoyers__15170.0908363395$1558211488$gmane$org@efficios.com' \
    --to=mathieu.desnoyers@efficios.com \
    --cc=jgalar@efficios.com \
    --cc=lttng-dev@lists.lttng.org \
    --cc=simon.marchi@efficios.com \
    /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).