linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ v2 1/2] build: Enable -Wstringop-overflow and -D_FORTIFY_SOURCE=3
@ 2025-02-04 20:19 Luiz Augusto von Dentz
  2025-02-04 20:19 ` [PATCH BlueZ v2 2/2] emulator: Fix Werror=stringop-overflow Luiz Augusto von Dentz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2025-02-04 20:19 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This enables -Wstringop-overflow compiler warnings:

  'Warn for calls to string manipulation functions such as "memcpy" and
  "strcpy" that are determined to overflow the destination buffer.'

Along with -D_FORTIFY_SOURCE=3 so the errors like the following can be
captured:

In function ‘read’,
    inlined from ‘serial_read_callback’ at emulator/serial.c:90:8:
/usr/include/bits/unistd.h:32:10: error: ‘__read_alias’ specified size between 18446744073709490177 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
   32 |   return __glibc_fortify (read, __nbytes, sizeof (char),
      |          ^~~~~~~~~~~~~~~
---
 acinclude.m4 | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/acinclude.m4 b/acinclude.m4
index 4b73a5bfc38f..9f2dc302e7bc 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -61,9 +61,11 @@ AC_DEFUN([COMPILER_FLAGS], [
 		with_cflags="$with_cflags -Wcast-align"
 		with_cflags="$with_cflags -Wswitch-enum"
 		with_cflags="$with_cflags -Wformat -Wformat-security"
+		with_cflags="$with_cflags -Wstringop-overflow"
 		with_cflags="$with_cflags -DG_DISABLE_DEPRECATED"
 		with_cflags="$with_cflags -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28"
 		with_cflags="$with_cflags -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_32"
+		with_cflags="$with_cflags -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3"
 	fi
 	AC_SUBST([WARNING_CFLAGS], $with_cflags)
 ])
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH BlueZ v2 2/2] emulator: Fix Werror=stringop-overflow
  2025-02-04 20:19 [PATCH BlueZ v2 1/2] build: Enable -Wstringop-overflow and -D_FORTIFY_SOURCE=3 Luiz Augusto von Dentz
@ 2025-02-04 20:19 ` Luiz Augusto von Dentz
  2025-02-04 21:30 ` [BlueZ,v2,1/2] build: Enable -Wstringop-overflow and -D_FORTIFY_SOURCE=3 bluez.test.bot
  2025-02-04 21:40 ` [PATCH BlueZ v2 1/2] " patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2025-02-04 20:19 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This fixes the following build errors caused by buf being used as a
static from tracking progress of a packet when it is not necessary since
pkt_data exists for the same reason:

/usr/include/bits/unistd.h:32:10: error: ‘__read_alias’ specified size between 18446744073709490177 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
   32 |   return __glibc_fortify (read, __nbytes, sizeof (char),
      |          ^~~~~~~~~~~~~~~
emulator/serial.c: In function ‘serial_read_callback’:
emulator/serial.c:78:24: note: destination object allocated here
   78 |         static uint8_t buf[4096];
      |                        ^~~
/usr/include/bits/unistd-decl.h:29:16: note: in a call to function ‘__read_alias’ declared with attribute ‘access (write_only, 2, 3)’
   29 | extern ssize_t __REDIRECT_FORTIFY (__read_alias, (int __fd, void *__buf,
      |                ^~~~~~~~~~~~~~~~~~

Fixes: https://github.com/bluez/bluez/issues/1049
---
 emulator/serial.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/emulator/serial.c b/emulator/serial.c
index b74556b13547..f8062ae5eac3 100644
--- a/emulator/serial.c
+++ b/emulator/serial.c
@@ -75,7 +75,7 @@ static void serial_write_callback(const struct iovec *iov, int iovlen,
 static void serial_read_callback(int fd, uint32_t events, void *user_data)
 {
 	struct serial *serial = user_data;
-	static uint8_t buf[4096];
+	uint8_t buf[4096];
 	uint8_t *ptr = buf;
 	ssize_t len;
 	uint16_t count;
@@ -87,8 +87,7 @@ static void serial_read_callback(int fd, uint32_t events, void *user_data)
 	}
 
 again:
-	len = read(serial->fd, buf + serial->pkt_offset,
-			sizeof(buf) - serial->pkt_offset);
+	len = read(serial->fd, buf, sizeof(buf));
 	if (len < 0) {
 		if (errno == EAGAIN)
 			goto again;
@@ -98,7 +97,7 @@ again:
 	if (!serial->btdev)
 		return;
 
-	count = serial->pkt_offset + len;
+	count = len;
 
 	while (count > 0) {
 		hci_command_hdr *cmd_hdr;
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [BlueZ,v2,1/2] build: Enable -Wstringop-overflow and -D_FORTIFY_SOURCE=3
  2025-02-04 20:19 [PATCH BlueZ v2 1/2] build: Enable -Wstringop-overflow and -D_FORTIFY_SOURCE=3 Luiz Augusto von Dentz
  2025-02-04 20:19 ` [PATCH BlueZ v2 2/2] emulator: Fix Werror=stringop-overflow Luiz Augusto von Dentz
@ 2025-02-04 21:30 ` bluez.test.bot
  2025-02-04 21:40 ` [PATCH BlueZ v2 1/2] " patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2025-02-04 21:30 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 1260 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=930572

---Test result---

Test Summary:
CheckPatch                    PENDING   0.22 seconds
GitLint                       PENDING   0.17 seconds
BuildEll                      PASS      20.48 seconds
BluezMake                     PASS      1493.53 seconds
MakeCheck                     PASS      12.73 seconds
MakeDistcheck                 PASS      156.64 seconds
CheckValgrind                 PASS      212.23 seconds
CheckSmatch                   PASS      281.84 seconds
bluezmakeextell               PASS      97.57 seconds
IncrementalBuild              PENDING   0.27 seconds
ScanBuild                     PASS      847.66 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH BlueZ v2 1/2] build: Enable -Wstringop-overflow and -D_FORTIFY_SOURCE=3
  2025-02-04 20:19 [PATCH BlueZ v2 1/2] build: Enable -Wstringop-overflow and -D_FORTIFY_SOURCE=3 Luiz Augusto von Dentz
  2025-02-04 20:19 ` [PATCH BlueZ v2 2/2] emulator: Fix Werror=stringop-overflow Luiz Augusto von Dentz
  2025-02-04 21:30 ` [BlueZ,v2,1/2] build: Enable -Wstringop-overflow and -D_FORTIFY_SOURCE=3 bluez.test.bot
@ 2025-02-04 21:40 ` patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+bluetooth @ 2025-02-04 21:40 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Tue,  4 Feb 2025 15:19:47 -0500 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> This enables -Wstringop-overflow compiler warnings:
> 
>   'Warn for calls to string manipulation functions such as "memcpy" and
>   "strcpy" that are determined to overflow the destination buffer.'
> 
> [...]

Here is the summary with links:
  - [BlueZ,v2,1/2] build: Enable -Wstringop-overflow and -D_FORTIFY_SOURCE=3
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=26ef5a951e81
  - [BlueZ,v2,2/2] emulator: Fix Werror=stringop-overflow
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=de2773b659d0

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-04 21:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-04 20:19 [PATCH BlueZ v2 1/2] build: Enable -Wstringop-overflow and -D_FORTIFY_SOURCE=3 Luiz Augusto von Dentz
2025-02-04 20:19 ` [PATCH BlueZ v2 2/2] emulator: Fix Werror=stringop-overflow Luiz Augusto von Dentz
2025-02-04 21:30 ` [BlueZ,v2,1/2] build: Enable -Wstringop-overflow and -D_FORTIFY_SOURCE=3 bluez.test.bot
2025-02-04 21:40 ` [PATCH BlueZ v2 1/2] " patchwork-bot+bluetooth

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).