Bug 480296 - UB in plasma-workspace's ksmserver/legacy.cpp (-Wrestrict with ::select)
Summary: UB in plasma-workspace's ksmserver/legacy.cpp (-Wrestrict with ::select)
Status: CONFIRMED
Alias: None
Product: plasmashell
Classification: Plasma
Component: Session Management (show other bugs)
Version: master
Platform: Other Other
: NOR normal
Target Milestone: 1.0
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-01-25 01:31 UTC by Sam James
Modified: 2024-02-29 07:54 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James 2024-01-25 01:31:28 UTC
SUMMARY

See https://invent.kde.org/plasma/plasma-workspace/-/blob/034205dd9dc667f6abcf8fb8a53baa6094bb4449/ksmserver/legacy.cpp#L179 where ::select is called as:
>::select(fd + 1, &fds, nullptr, &fds, &tmwait);

This triggers a warning
```
 * /var/tmp/portage/kde-plasma/plasma-workspace-6.0.49.9999/work/plasma-workspace-6.0.49.9999/ksmserver/legacy.cpp:179:30: warning: passing argument 2 to ‘restrict’-qualified parameter aliases with argument 4 [-Wrestrict]
```

with gcc version 14.0.1 20240121 (experimental) (Gentoo Hardened 14.0.1_pre20240121 p16) at least, and it looks right.

From `select(3p`):
```
       int select(int nfds, fd_set *restrict readfds,
           fd_set *restrict writefds, fd_set *restrict errorfds,
           struct timeval *restrict timeout);
```

&fds is passed as both `readfds` and `errorfds` which is forbidden.
Comment 1 Nate Graham 2024-02-15 18:10:09 UTC
Thanks. Would you like to submit a patch to fix it?
Comment 2 Sam James 2024-02-29 07:54:19 UTC
I'll put it on the list and will hopefully remember ;)