Skip to content

Potential fix for code scanning alert no. 1901: Unsigned difference expression compared to zero#25

Open
HaplessIdiot wants to merge 438 commits into
masterfrom
alert-autofix-1901
Open

Potential fix for code scanning alert no. 1901: Unsigned difference expression compared to zero#25
HaplessIdiot wants to merge 438 commits into
masterfrom
alert-autofix-1901

Conversation

@HaplessIdiot

Copy link
Copy Markdown
Contributor

Potential fix for https://github.com/supersonic-xserver/ssX/security/code-scanning/1901

In general, to fix this kind of issue, make sure that any relational comparison involving the result of an unsigned subtraction is done in a signed type, or re-express the logic without subtracting unsigned values. In this specific case, we want to check whether there is a positive microsecond remainder after converting a time delta d (in microseconds) to milliseconds, and use that to decide whether to add a bit of extra delay. The current code does this using (CARD32) d and subtracting d_ms * 1000, which causes unsigned underflow and makes the comparison unreliable.

The best fix is to keep all of this “remainder” computation in a signed 64-bit type, consistent with d, and only cast to CARD32 at the final assignment to d_ms. Concretely:

  • Compute d_ms as d / 1000 in an int64_t temporary (e.g., int64_t d_ms64), then clamp it to the CARD32 range when assigning to d_ms if needed.
  • Compute the remainder as d - (int64_t)d_ms * 1000 in signed arithmetic, and compare that to zero.
  • Alternatively, compute the remainder as d % 1000 on the signed int64_t, which is even clearer.

Because we must avoid changing global behavior, we should preserve the high-level logic: if there is a positive microsecond remainder, add 2 ms; otherwise, add 1 ms. We’ll therefore:

  • Introduce an int64_t d_ms64 variable.
  • Replace d_ms = (CARD32) d / 1000; with computing d_ms64 = d / 1000; and then d_ms = (CARD32)d_ms64; (assuming the existing code implicitly assumes d fits; if needed, we could clamp but that would be a behavioral change, so we’ll mirror the existing assumption).
  • Replace (CARD32) d - d_ms * 1000 > 0 with (d - (int64_t)d_ms * 1000) > 0, so the subtraction is done in signed 64-bit arithmetic.

All changes are confined to the shown function in hw/xfree86/drivers/amdgpu/amdgpu_dri2.c; no new headers or external libraries are needed.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

jmcneill and others added 30 commits February 9, 2020 11:40
…aki.

I've finally contacted with Yamasaki-san and he kindly answered
"no objection to change them to 2 clause license" in private mail.
Diffs to be committed have also been confirmed by him.
We appreciate all his contribution to early NetBSD/x68k.
https://mail-index.netbsd.org/source-changes/2020/07/18/msg119473.html
> Use AllocDevicePair() to initialize input devices in InitInput().

Untested, but I'll re-visit on migrating to HAVE_XORG_SERVER_VER=120.
As per upstream commits for Xnest:
 https://cgit.freedesktop.org/xorg/xserver/commit/?id=67c303fff303f94b62f03a76de97116c6ebcfda9

Note GLXEXT is defined as 1 in xorg-server/include/xorg-server.h
(i.e. /usr/X11R7/include/xorg/xorg-server.h) so no proper way to
disable it on building MD servers per ${MACHINE} basis.
https://mail-index.netbsd.org/source-changes/2020/07/18/msg119488.html
> Fix 1bpp Xservers on "whitePixel=0, blackPixel=1" VRAMs.
>
> - Don't override pScreen->blackPixel and pScreen->whitePixel
>   (set in MD server Init functions per -filpPixels option)
>   on 1bpp servers in merged fbSetupScreen() (merged one
>   from cfbSetupScrenn and mfbSetupScreen() in old xsrc/xfree)
> - Pull mfbCreateColormap() function from old xsrc/xfree tree
>   and use it on 1bpp servers

Confirmed on luna68k 1bpp Xorg 1.20 server using xf86-video-wsfb
with "-flipPixels" option.
This is based on 1.10 version imported into xorg-server.old and
all upstream API changes between xorg-server 1.10 and 1.20 are
applied almost mechanically.
 https://github.com/tsutsui/xorg-server-Xsun/commits/xorg-server-1.20

Xsun and XsunMono servers are also confirmed working with bwtwo on
3/60 and tme, and cgtwo on tme. XKB stuff is still to be resolved.
Fixes build error on sparc64.  No binary change on sun3.
Now CapsLock and NumLock LEDs work correctly.
XXX: No ScrollLock LED
…ball.

From aac28e1 Mon Sep 17 00:00:00 2001
From: Matthieu Herrb <matthieu@herrb.eu>
Date: Sat, 25 Jul 2020 19:33:50 +0200
Subject: [PATCH] fix for ZDI-11426

Avoid leaking un-initalized memory to clients by zeroing the
whole pixmap on initial allocation.

This vulnerability was discovered by:
Jan-Niklas Sohn working with Trend Micro Zero Day Initiative

Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
…tings.

Now all modifier keys (CTRL, SHIFT, and NumLock) work as expected.

It seems XkbApplyMappingChange() doesn't update some XKB modifier
settings even if new modmap data is specified.
HaplessIdiot and others added 28 commits March 14, 2026 11:35
Potential fix for code scanning alert no. 62: Non-constant format string
…pr-1780

Revert "glamor/glamor_egl.c: Check if at least one (format, modifier) pair is supported"
…pr-1780

Revert "glamor/glamor_egl.c: Check if at least one (format, modifier) pair is supported"
Make IgnoreABI configurable through config files
Unify intel video driver and evdev input inside source tree
…xpression compared to zero

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@HaplessIdiot HaplessIdiot marked this pull request as ready for review March 14, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants