Skip to content

libvncserver: avoid deferUpdateTime overflow#706

Open
marcofortina wants to merge 1 commit into
LibVNC:masterfrom
marcofortina:fix/defer-update-time-overflow
Open

libvncserver: avoid deferUpdateTime overflow#706
marcofortina wants to merge 1 commit into
LibVNC:masterfrom
marcofortina:fix/defer-update-time-overflow

Conversation

@marcofortina
Copy link
Copy Markdown
Contributor

@marcofortina marcofortina commented May 15, 2026

Summary

Fixes a potential integer overflow in the deferred update timeout calculation.

The server stores deferUpdateTime as milliseconds, but the event loop converts it to microseconds with an int * int expression before passing it to select(). Large values, for example from -deferupdate, can overflow before the value is widened.

Changes

  • Add a small helper to convert deferUpdateTime from milliseconds to microseconds safely.
  • Treat non-positive values as a zero timeout, preserving the existing immediate-processing behavior.
  • Clamp excessively large values to avoid overflow before passing the timeout to the socket wait helper.
  • Reuse the helper in both rfbProcessEvents() and rfbRunEventLoop().

Validation

Tested with a minimal local CMake configuration:

cmake -S . -B build-701-patch \
  -DWITH_EXAMPLES=OFF \
  -DWITH_TESTS=ON \
  -DWITH_OPENSSL=OFF \
  -DWITH_GNUTLS=OFF \
  -DWITH_GCRYPT=OFF \
  -DWITH_SDL=OFF \
  -DWITH_GTK=OFF \
  -DWITH_QT=OFF \
  -DWITH_FFMPEG=OFF \
  -DWITH_XCB=OFF \
  -DWITH_LIBSSHTUNNEL=OFF \
  -DWITH_SYSTEMD=OFF \
  -DCMAKE_BUILD_TYPE=Debug
cmake --build build-701-patch --parallel 1
ctest --test-dir build-701-patch --output-on-failure

Result:

100% tests passed, 0 tests failed out of 5

Notes

Closes #701.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarification on deferUpdateTime practical range (integer overflow warning in libvncserver/main.c lines 1270, 1372)

2 participants