public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH bluez v3] monitor: fix buffer overflow when terminal width > 255
@ 2024-09-17  6:30 Celeste Liu
  2024-09-17  8:09 ` [bluez,v3] " bluez.test.bot
  2024-09-17 14:20 ` [PATCH bluez v3] " patchwork-bot+bluetooth
  0 siblings, 2 replies; 3+ messages in thread
From: Celeste Liu @ 2024-09-17  6:30 UTC (permalink / raw)
  To: Bluez; +Cc: Celeste Liu

In current code, we create line buffer with size 256, which can contains
255 ASCII characters. But in modern system, terminal can have larger
width. It may cause buffer overflow in snprintf() text.

limits.h provides constant LINE_MAX.

    {LINE_MAX}
        Unless otherwise noted, the maximum length, in bytes, of a
        utility's input line (either standard input or another
        file), when the utility is described as processing text
        files. The length includes room for the trailing <newline>.
        Minimum Acceptable Value: {_POSIX2_LINE_MAX}

Signed-off-by: Celeste Liu <CoelacanthusHex@gmail.com>
---
Changes in v3:
- Use constant LINE_MAX in limits.h instead dynamic heap allocation.
- Link to v2: https://lore.kernel.org/r/20240915-fix-log-buffer-overflow-v2-1-fb6b52a7d4b2@gmail.com

Changes in v2:
- Add free() forgot in v1.
- Link to v1: https://patch.msgid.link/20240914-fix-log-buffer-overflow-v1-1-733cb4fff673@gmail.com
---
 monitor/packet.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/monitor/packet.c b/monitor/packet.c
index c2599fe6864ab44d657c121fcc3ceecc1ebc52a6..32a440bbea6888ab6321e973dbb23d9728864557 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -26,6 +26,7 @@
 #include <time.h>
 #include <sys/time.h>
 #include <sys/socket.h>
+#include <limits.h>
 
 #include "lib/bluetooth.h"
 #include "lib/uuid.h"
@@ -376,7 +377,7 @@ static void print_packet(struct timeval *tv, struct ucred *cred, char ident,
 					const char *text, const char *extra)
 {
 	int col = num_columns();
-	char line[256], ts_str[96], pid_str[140];
+	char line[LINE_MAX], ts_str[96], pid_str[140];
 	int n, ts_len = 0, ts_pos = 0, len = 0, pos = 0;
 	static size_t last_frame;
 

---
base-commit: 41f943630d9a03c40e95057b2ac3d96470b9c71e
change-id: 20240914-fix-log-buffer-overflow-9aa5e61ee5b8

Best regards,
-- 
Celeste Liu <CoelacanthusHex@gmail.com>


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

* RE: [bluez,v3] monitor: fix buffer overflow when terminal width > 255
  2024-09-17  6:30 [PATCH bluez v3] monitor: fix buffer overflow when terminal width > 255 Celeste Liu
@ 2024-09-17  8:09 ` bluez.test.bot
  2024-09-17 14:20 ` [PATCH bluez v3] " patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2024-09-17  8:09 UTC (permalink / raw)
  To: linux-bluetooth, coelacanthushex

[-- Attachment #1: Type: text/plain, Size: 2178 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=890823

---Test result---

Test Summary:
CheckPatch                    PASS      0.28 seconds
GitLint                       FAIL      0.45 seconds
BuildEll                      PASS      24.54 seconds
BluezMake                     PASS      1727.17 seconds
MakeCheck                     PASS      13.74 seconds
MakeDistcheck                 PASS      181.34 seconds
CheckValgrind                 PASS      259.09 seconds
CheckSmatch                   WARNING   363.88 seconds
bluezmakeextell               PASS      120.05 seconds
IncrementalBuild              PASS      1423.05 seconds
ScanBuild                     PASS      992.04 seconds

Details
##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[bluez,v3] monitor: fix buffer overflow when terminal width > 255

WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search
20: B1 Line exceeds max length (100>80): "- Link to v2: https://lore.kernel.org/r/20240915-fix-log-buffer-overflow-v2-1-fb6b52a7d4b2@gmail.com"
24: B1 Line exceeds max length (99>80): "- Link to v1: https://patch.msgid.link/20240914-fix-log-buffer-overflow-v1-1-733cb4fff673@gmail.com"
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
monitor/packet.c: note: in included file:monitor/display.h:82:26: warning: Variable length array is used.monitor/packet.c:1868:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3606:52: warning: array of flexible structuresmonitor/bt.h:3594:40: warning: array of flexible structures


---
Regards,
Linux Bluetooth


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

* Re: [PATCH bluez v3] monitor: fix buffer overflow when terminal width > 255
  2024-09-17  6:30 [PATCH bluez v3] monitor: fix buffer overflow when terminal width > 255 Celeste Liu
  2024-09-17  8:09 ` [bluez,v3] " bluez.test.bot
@ 2024-09-17 14:20 ` patchwork-bot+bluetooth
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2024-09-17 14:20 UTC (permalink / raw)
  To: Celeste Liu; +Cc: linux-bluetooth, CoelacanthusHex

Hello:

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

On Tue, 17 Sep 2024 14:30:46 +0800 you wrote:
> In current code, we create line buffer with size 256, which can contains
> 255 ASCII characters. But in modern system, terminal can have larger
> width. It may cause buffer overflow in snprintf() text.
> 
> limits.h provides constant LINE_MAX.
> 
>     {LINE_MAX}
>         Unless otherwise noted, the maximum length, in bytes, of a
>         utility's input line (either standard input or another
>         file), when the utility is described as processing text
>         files. The length includes room for the trailing <newline>.
>         Minimum Acceptable Value: {_POSIX2_LINE_MAX}
> 
> [...]

Here is the summary with links:
  - [bluez,v3] monitor: fix buffer overflow when terminal width > 255
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=2908491c7efe

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] 3+ messages in thread

end of thread, other threads:[~2024-09-17 14:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-17  6:30 [PATCH bluez v3] monitor: fix buffer overflow when terminal width > 255 Celeste Liu
2024-09-17  8:09 ` [bluez,v3] " bluez.test.bot
2024-09-17 14:20 ` [PATCH bluez v3] " 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