Commit Graph

2954 Commits

Author SHA1 Message Date
Luiz Augusto von Dentz
34cfee7ed0 test-runner: Fix using removed options
-no-acpi and -no-hpet are not longer available on most recent release
(e.g. fc41).
2024-11-08 13:13:00 -05:00
Iulia Tanasescu
bae6c32940 iso-tester: Add test for Broadcast Receiver Defer sync to 2 BIGs
This adds a new Broadcast Receiver test, for a Broadcast Sink
synchronizing to 2 Broadcasters, using defer setup.

ISO Broadcaster Receiver2 Defer - Success
2024-11-05 09:09:25 -05:00
Iulia Tanasescu
b87c3767f5 iso-tester: Add test for Broadcast Receiver sync to 2 BIGs
This adds a new Broadcast Receiver test, for a Broadcast Sink
synchronizing to 2 Broadcasters.

ISO Broadcaster Receiver2 - Success
2024-11-05 09:09:24 -05:00
Iulia Tanasescu
1a55bac559 iso-tester: Fix memory leaks in iso_accept_cb
This fixes memory leaks that appear in iso_accept_cb because a new io
channel is allocated but never unreferenced at the end of the test.

=================================================================
==20460==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 120 byte(s) in 1 object(s) allocated from:
    #0 0x7dcddc8fbb37 in malloc ../../../../src/libsanitizer/asan/
                                asan_malloc_linux.cpp:69
    #1 0x7dcddc719af9 in g_malloc (/lib/x86_64-linux-gnu/
                                   libglib-2.0.so.0+0x62af9)
    #2 0x7dcddc7722bd in g_io_channel_unix_new
                         (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0xbb2bd
    #3 0x5d3fdfe28262 in iso_accept_cb tools/iso-tester.c:3004

Indirect leak of 6 byte(s) in 1 object(s) allocated from:
    #0 0x7dcddc8fbb37 in malloc ../../../../src/libsanitizer/asan/
                                asan_malloc_linux.cpp:69
    #1 0x7dcddc719af9 in g_malloc (/lib/x86_64-linux-gnu/
                                   libglib-2.0.so.0+0x62af9)
    #2 0x7dcddc70016f in g_io_channel_init
                         (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4916f)
    #3 0x7dcddc7722c8 in g_io_channel_unix_new
                         (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0xbb2c8)
    #4 0x5d3fdfe28262 in iso_accept_cb tools/iso-tester.c:3004

SUMMARY: AddressSanitizer: 126 byte(s) leaked in 2 allocation(s).
2024-11-05 09:09:23 -05:00
Frédéric Danis
b30b1eddb4 tools/obexctl: Add support to connect using PSM port
Since commit 5d7d3ac25b ("obexd: Add PSM support to session create")
obexd supports to connect the session using a L2CAP PSM.
2024-10-17 17:24:40 -04:00
Luiz Augusto von Dentz
ee6f3a837e shared/shell: Fix not handling prompt with color properly
Colors use escape sequence that needs to be enveloped with
RL_PROMPT_START_IGNORE (\001) and RL_PROMPT_END_IGNORE (\002) in order
for readline to properly calculate the prompt length.

Fixes: https://github.com/bluez/bluez/issues/965
2024-10-17 10:00:02 -04:00
Ismael Luceno
cd1c6b666f Fix missing inclusion of <limits.h>
Needed for PATH_MAX.
2024-09-19 13:01:07 -04:00
Frédéric Danis
5cd301e888 player: Add image handle support property
This is part of the metadata when the AVRCP target supports covert
art download and a OBEX BIP session is connected.
The image handle references the cover art associated to the track,
and is valid only during OBEX BIP session.
2024-09-16 13:18:11 -04:00
Khem Raj
690eccbe85 mesh: Provide GNU basename compatible implementation
Call to basename() relies on a GNU extension
to take a const char * vs a char *. Let's define
a trivial helper function to ensure compatibility
with musl.

Fixes: https://github.com/bluez/bluez/issues/843
2024-09-10 13:40:07 -04:00
Guido Günther
daa86e06c3 tools/mpris-proxy: Add systemd user unit
That way it will be started automatically which is convenient on phones.
Distributions can then decide part of which install the unit should be.

Signed-off-by: Guido Günther <agx@sigxcpu.org>
2024-09-09 13:02:38 -04:00
Roman Smirnov
b752f760da tools/rctest: add NULL checks to main()
It is necessary to prevent dereferencing of a NULL pointer.

Found with the SVACE static analysis tool.
2024-08-13 10:33:44 -04:00
Antonio Vázquez Blanco
34aca9a4fb bdaddr: Add cypress manufacturer support 2024-07-09 10:44:41 -04:00
Arjan Opmeer
f00d5546c9 tools/btmgmt: Fix --index option for non-interactive mode
In non-interactive mode the --index option does not work because the
call to mgmt_set_index() is made after bt_shell_attach().

Fixes: https://github.com/bluez/bluez/issues/893
2024-07-09 10:31:09 -04:00
Roman Smirnov
8e495f00cd tools/rctest: limit the maximum possible data_size
It is necessary to prevent the possibility of allocating
a large amount of memory.

Found with the SVACE static analysis tool.
2024-07-08 10:41:48 -04:00
Roman Smirnov
c389209ce4 tools/isotest: limit the maximum possible data_size
It is necessary to prevent the possibility of allocating
a large amount of memory.

Found with the SVACE static analysis tool.
2024-07-08 10:41:12 -04:00
Bastien Nocera
9b346513cc tools/mesh: Fix integer overflow due to cast operation
Error: INTEGER_OVERFLOW (CWE-190): [#def29] [important]
tools/mesh/mesh-db.c:551:3: cast_overflow: Truncation due to cast operation on "ele_cnt" from 32 to 8 bits.
tools/mesh/mesh-db.c:551:3: overflow_sink: "ele_cnt", which might have overflowed, is passed to "remote_add_node((uint8_t const *)uuid, unicast, ele_cnt, key_idx)".
549|			continue;
550|
551|->		remote_add_node((const uint8_t *)uuid, unicast, ele_cnt,
552|								key_idx);
553|		for (j = 1; j < key_cnt; j++) {
2024-07-08 10:39:31 -04:00
Bastien Nocera
8de21f74c5 btsnoop: Fix possible negative memcpy length
Error: INTEGER_OVERFLOW (CWE-190): [#def41] [important]
tools/btsnoop.c:438:2: tainted_data_return: Called function "read(fd, buf, toread)", and a possible return value may be less than zero.
tools/btsnoop.c:438:2: assign: Assigning: "len" = "read(fd, buf, toread)".
tools/btsnoop.c:473:4: overflow: The cast of "len - 9L", which is potentially negative, to an unsigned type could result in an overflow.
471|			/* next 4 bytes are data len and cid */
472|			current_cid = buf[8] << 8 | buf[7];
473|->			memcpy(pdu_buf, buf + 9, len - 9);
474|			pdu_len = len - 9;
475|		} else if (acl_flags & 0x01) {

Error: INTEGER_OVERFLOW (CWE-190): [#def42] [important]
tools/btsnoop.c:438:2: tainted_data_return: Called function "read(fd, buf, toread)", and a possible return value may be less than zero.
tools/btsnoop.c:438:2: assign: Assigning: "len" = "read(fd, buf, toread)".
tools/btsnoop.c:476:4: overflow: The cast of "len - 5L", which is potentially negative, to an unsigned type could result in an overflow.
474|			pdu_len = len - 9;
475|		} else if (acl_flags & 0x01) {
476|->			memcpy(pdu_buf + pdu_len, buf + 5, len - 5);
477|			pdu_len += len - 5;
478|		}
2024-07-08 10:17:40 -04:00
Roman Smirnov
559e40a8b9 rctest: replace sprintf() with snprintf() in recv_mode()
Use snprintf() instead of sprintf() to avoid buffer overflow.

Found with the SVACE static analysis tool.
2024-06-28 11:01:59 -04:00
Roman Smirnov
0bd3d1505e l2test: replace sprintf() with snprintf() in recv_mode()
Use snprintf() instead of sprintf() to avoid buffer overflow.

Found with the SVACE static analysis tool
2024-06-28 11:01:50 -04:00
Luiz Augusto von Dentz
72c3f5bf1c l2cap-tester: Add tests for multiple data packets over LE
This adds the following tests which cover the TX/RX of multiple
packets (up to 32K) over LE credit based flow control:

L2CAP LE Client - Read 32k Success
L2CAP LE Client - Write 32k Success
2024-06-26 15:39:43 -04:00
Luiz Augusto von Dentz
a1e3ac87b5 l2cap-tester: Add tests for multiple data packets
This adds the following tests which cover the TX/RX of multiple
packets (up to 32K):

L2CAP BR/EDR Client - Read 32k Success
L2CAP BR/EDR Client - Write 32k Success
L2CAP BR/EDR Server - Read 32k Success
L2CAP BR/EDR Server - Write 32k Success
2024-06-26 15:39:21 -04:00
Luiz Augusto von Dentz
272d8e8c95 isotest: Fix ISO send data rate
We are sending data to controller at wrong average rate not equal to
1 packet / SDU interval, if Transport_Latency is not an integer multiple
of SDU_Interval.  The calculation currently may also give zero, so no
data gets sent.
2024-06-07 11:12:21 -04:00
Bastien Nocera
ccec5e8ef1 l2test: Add missing error checking
send() might fail and return a negative len, catch that to avoid
advancing the send buffer in the wrong direction and causing all sorts
of problems.

977|->			len = send(sk, buf + sent, buflen, 0);
978|
979|			sent += len;
2024-06-03 15:04:11 -04:00
Bastien Nocera
aa54087f13 mgmt-tester: Fix buffer overrun
Error: OVERRUN (CWE-119): [#def56] [important]
tools/mgmt-tester.c:12674:2: overrun-local:
Overrunning array "buf" of 513 bytes at byte offset 513 using
index "read + 1" (which evaluates to 513).
12672|		}
12673|		/* Make sure buf is nul-terminated */
12674|->	buf[read + 1] = '\0';
12675|
12676|		/* Verify if all devcoredump header fields are present */

Fixes: 49d0656069 ("mgmt-tester: Fix non-nul-terminated string")
2024-06-03 15:02:47 -04:00
Bastien Nocera
24cf049395 rctest: Fix possible overrun
Error: OVERRUN (CWE-119): [#def57] [important]
tools/rctest.c:557:3:
overrun-buffer-arg: Calling "send" with "buf" and "len" is suspicious
because of the very large index, 18446744073709551615.
The index may be due to a negative parameter being interpreted as unsigned.
555|		}
556|		len = read(fd, buf, data_size);
557|->		send(sk, buf, len, 0);
558|		close(fd);
559|		return;
2024-06-03 14:59:20 -04:00
Bastien Nocera
49d0656069 mgmt-tester: Fix non-nul-terminated string
Error: STRING_NULL (CWE-170): [#def59] [important]
tools/mgmt-tester.c:12670:2: string_null_source: Function "vhci_read_devcd" does not terminate string "buf".
tools/mgmt-tester.c:12677:2: string_null: Passing unterminated string "buf" to "strtok_r", which expects a null-terminated string.
12675|
12676|		/* Verify if all devcoredump header fields are present */
12677|->	line = strtok_r(buf, delim, &saveptr);
12678|		while (strlen(test->expect_dump_data[i])) {
12679|			if (!line || strcmp(line, test->expect_dump_data[i])) {
2024-05-16 16:37:35 -04:00
Bastien Nocera
f05e448cf8 isotest: Fix string size expectations
Verify that the peer is a valid bdaddr (and so has the correct length)
before using it.

Error: STRING_SIZE (CWE-120): [#def54] [important]
tools/isotest.c:1198:26: string_size_argv: "argv" contains strings with unknown size.
tools/isotest.c:1459:4: string_size: Passing string "argv[optind + i]" of unknown size to "send_mode", which expects a string of a particular size.

Error: STRING_SIZE (CWE-120): [#def55] [important]
tools/isotest.c:1198:26: string_size_argv: "argv" contains strings with unknown size.
tools/isotest.c:1476:4: var_assign_var: Assigning: "peer" = "argv[optind + i]". Both are now tainted.
tools/isotest.c:1484:5: string_size: Passing string "peer" of unknown size to "bcast_do_connect_mbis", which expects a string of a particular size.

Error: STRING_SIZE (CWE-120): [#def56] [important]
tools/isotest.c:1198:26: string_size_argv: "argv" contains strings with unknown size.
tools/isotest.c:1476:4: var_assign_var: Assigning: "peer" = "argv[optind + i]". Both are now tainted.
tools/isotest.c:1514:5: string_size: Passing string "argv[optind + i]" of unknown size to "do_connect", which expects a string of a particular size.
2024-05-16 16:37:33 -04:00
Bastien Nocera
566af9c2f5 test-runner: Fix fd leak on failure
Error: RESOURCE_LEAK (CWE-772): [#def65] [important]
tools/test-runner.c:877:3: open_fn: Returning handle opened by "attach_proto".
tools/test-runner.c:877:3: var_assign: Assigning: "serial_fd" = handle returned from "attach_proto(node, 0U, basic_flags, extra_flags)".
tools/test-runner.c:955:3: leaked_handle: Handle variable "serial_fd" going out of scope leaks the handle.
953|	if (pid < 0) {
954|		perror("Failed to fork new process");
955|->		return;
956|	}
957|
2024-05-16 16:37:30 -04:00
Bastien Nocera
7a63855704 isotest: Fix bad free
Error: BAD_FREE (CWE-763): [#def58] [important]
tools/isotest.c:1461:5: address: Taking offset from "strchr(filename, 44)".
tools/isotest.c:1461:5: assign: Assigning: "filename" = "strchr(filename, 44) + 1".
tools/isotest.c:1536:2: incorrect_free: "free" frees incorrect pointer "filename".
1534|
1535|   done:
1536|->		free(filename);
1537|
1538|		syslog(LOG_INFO, "Exit");
2024-05-16 16:37:28 -04:00
Bastien Nocera
9672cf410f test-runner: Fix uninitialised variable usage
Error: UNINIT (CWE-457): [#def64] [important]
tools/test-runner.c:701:2: var_decl: Declaring variable "envp" without initializer.
tools/test-runner.c:739:3: uninit_use_in_call: Using uninitialized value "*envp" when calling "execve".
737|
738|	if (pid == 0) {
739|->		execve(argv[0], argv, envp);
740|		exit(EXIT_SUCCESS);
741|	}
2024-05-16 16:37:00 -04:00
Bastien Nocera
0640d99ebf test-runner: Fix uninitialised variable usage
Error: UNINIT (CWE-457): [#def72] [important]
tools/test-runner.c:856:2: var_decl: Declaring variable "argv" without initializer.
tools/test-runner.c:945:2: uninit_use: Using uninitialized value "argv[0]".
943|   	envp[pos] = NULL;
944|
945|-> 	printf("Running command %s\n", cmdname ? cmdname : argv[0]);
946|
947|   	pid = fork();
2024-05-16 16:36:57 -04:00
Bastien Nocera
9f4b2d0287 test-runner: Remove unused envp
Error: UNINIT (CWE-457): [#def70] [important]
tools/test-runner.c:644:2: var_decl: Declaring variable "envp" without initializer.
tools/test-runner.c:682:3: uninit_use_in_call: Using uninitialized value "*envp" when calling "execve".
680|
681|	if (pid == 0) {
682|->		execve(argv[0], argv, envp);
683|		exit(EXIT_SUCCESS);
684|	}

Error: UNINIT (CWE-457): [#def71] [important]
tools/test-runner.c:701:2: var_decl: Declaring variable "envp" without initializer.
tools/test-runner.c:739:3: uninit_use_in_call: Using uninitialized value "*envp" when calling "execve".
737|
738|	if (pid == 0) {
739|->		execve(argv[0], argv, envp);
740|		exit(EXIT_SUCCESS);
741|	}
2024-05-16 16:36:54 -04:00
Bastien Nocera
c63b7b0d73 tools/mesh-cfgclient: Fix uninitialised variable usage
Error: UNINIT (CWE-457): [#def64] [important]
tools/mesh-cfgclient.c:1992:2: var_decl: Declaring variable "result" without initializer.
tools/mesh-cfgclient.c:2041:3: uninit_use: Using uninitialized value "result". Field "result.last_seen" is uninitialized.
2039|							l_queue_length(devices) + 1);
2040|			dev = l_malloc(sizeof(struct unprov_device));
2041|->			*dev = result;
2042|
2043|		} else if (dev->rssi < result.rssi)

Error: UNINIT (CWE-457): [#def65] [important]
tools/mesh-cfgclient.c:1992:2: var_decl: Declaring variable "result" without initializer.
tools/mesh-cfgclient.c:2044:3: uninit_use: Using uninitialized value "result". Field "result.last_seen" is uninitialized.
2042|
2043|		} else if (dev->rssi < result.rssi)
2044|->			*dev = result;
2045|
2046|		dev->last_seen = time(NULL);
2024-05-16 16:36:52 -04:00
Pauli Virtanen
d9de306a28 Revert "mgmt-tester: update for Poll Errqueue experimental fature"
This reverts commit c777c55ab6.

The kernel feature needs further work.
2024-05-15 12:53:46 -04:00
Pauli Virtanen
975d3b1486 tools: disable running TX timestamping tests for now
Disable the TX timestamping related tests for now, as the feature will
need some further work.
2024-05-15 12:53:41 -04:00
Pauli Virtanen
2403924985 tools: fix using too small buffers in test-runner
Fix compiler warning:

tools/test-runner.c:309:57: error: 'sprintf' may write a terminating nul
  past the end of the destination [-Werror=format-overflow=]
2024-05-13 10:02:36 -04:00
Bastien Nocera
c81f932035 iso-tester: Fix fd leak
Error: RESOURCE_LEAK (CWE-772): [#def63] [important]
tools/iso-tester.c:1796:2: open_fn: Returning handle opened by "socket".
tools/iso-tester.c:1796:2: var_assign: Assigning: "sk" = handle returned from "socket(31, 2053, 8)".
tools/iso-tester.c:1807:3: leaked_handle: Handle variable "sk" going out of scope leaks the handle.
1805|		if (!master_bdaddr) {
1806|			tester_warn("No master bdaddr");
1807|->			return -ENODEV;
1808|		}
1809|
2024-05-10 11:29:01 -04:00
Bastien Nocera
3e03788ba8 isotest: Fix fd leak
Error: RESOURCE_LEAK (CWE-772): [#def65] [important]
tools/isotest.c:923:4: open_fn: Returning handle opened by "open_file".
tools/isotest.c:923:4: var_assign: Assigning: "fd" = handle returned from "open_file(altername)".
tools/isotest.c:953:3: leaked_handle: Handle variable "fd" going out of scope leaks the handle.
951|
952|		free(sk_arr);
953|->		return;
954|	}
955|
2024-05-10 11:28:54 -04:00
Bastien Nocera
9a36f191aa isotest: Fix error check after opening file
Consider "0" to be a valid fd.
2024-05-10 11:28:31 -04:00
Bastien Nocera
d30dc38b04 isotest: Consider "0" fd to be valid
Error: RESOURCE_LEAK (CWE-772): [#def79] [important]
tools/isotest.c:923:4: open_fn: Returning handle opened by "open_file".
tools/isotest.c:923:4: var_assign: Assigning: "fd" = handle returned from "open_file(altername)".
tools/isotest.c:925:3: off_by_one: Testing whether handle "fd" is strictly greater than zero is suspicious.  "fd" leaks when it is zero.
tools/isotest.c:925:3: remediation: Did you intend to include equality with zero?
tools/isotest.c:926:4: overwrite_var: Overwriting handle "fd" in "fd = open_file(filename)" leaks the handle.
924|
925|		if (fd <= 0)
926|->			fd = open_file(filename);
927|	}
928|
2024-05-10 11:28:21 -04:00
Pauli Virtanen
141f66411c iso-tester: add test for BT_POLL_ERRQUEUE
Also test BT_POLL_ERRQUEUE is experimental feature.

Add test:

ISO Send - TX No Poll Timestamping
2024-04-10 12:31:47 -04:00
Pauli Virtanen
c777c55ab6 mgmt-tester: update for Poll Errqueue experimental fature
Update Read Exp Feature - Success (Index None) for new experimental
feature Poll Errqueue.
2024-04-10 12:31:47 -04:00
Pauli Virtanen
4fe4fda73b l2cap-tester: add tests for LE Client read/write/tx-timestamping
Add tests:

L2CAP LE Client - Read Success
L2CAP LE Client - Write Success
L2CAP LE Client - TX Timestamping
2024-04-04 14:46:34 -04:00
Pauli Virtanen
9faf6f908f sco-tester: add TX timestamping test
Add test:

SCO CVSD Send - TX Timestamping
2024-04-04 14:46:33 -04:00
Pauli Virtanen
349d7975e6 l2cap-tester: Add test for TX timestamping
Add test

L2CAP BR/EDR Client - TX Timestamping
2024-04-04 14:46:33 -04:00
Pauli Virtanen
5e85956e11 iso-tester: Add tests for TX timestamping
Add TX timestamping test utilities in new tools/tester.h, so that they
can be shared between testers.

Add tests:

ISO Send - TX Timestamping
ISO Send - TX Sched Timestamping
ISO Send - TX Msg Timestamping
2024-04-04 14:46:33 -04:00
Luiz Augusto von Dentz
33af0ce949 iso-tester: Fix Codec Configuration length
The length is actually 16 (0x10) bytes not 17 (0x17).
2024-04-02 16:28:48 -04:00
Iulia Tanasescu
9684bba494 iso-tester: Add test for Broadcast Receiver Get BASE
This adds a new Broadcast Receiver test, to validate that a Broadcast
Sink is able to sync to the PA transmitted by a Source (when no BIG
is active) and is able to successfully detect the BASE:

ISO Broadcaster Receiver Defer Get BASE - Success
2024-04-02 16:28:48 -04:00
Luiz Augusto von Dentz
4520eca3e5 mgmt-tester: Adjust Coded PHY scan interval and window
Coded PHY interval and window recommneded by the core specification are
3x of the 1M.
2024-04-01 14:46:24 -04:00
Iulia Tanasescu
3403f65e26 iso-tester: Separate iso_defer_accept into dedicated functions
This separates the iso_defer_accept function into dedicated ones for
unicast/broadcast, since the flow is different for each scenario:
For unicast, POLLOUT is checked on socket before calling read and
adding a G_IO_OUT watch. Checking for POLLOUT is not necessary for
broadcast, since currently this event is never generated on the
child socket. Instead, G_IO_IN is generated after BIG sync is
established and a BIS socket is ready to be accepted.
2024-03-28 10:29:24 -04:00