Skip to content

Fix FLS FiberManager writing last_error to a dead attribute#1646

Open
w1tcher wants to merge 1 commit into
qilingframework:devfrom
w1tcher:fix/fiber-manager-last-error
Open

Fix FLS FiberManager writing last_error to a dead attribute#1646
w1tcher wants to merge 1 commit into
qilingframework:devfrom
w1tcher:fix/fiber-manager-last-error

Conversation

@w1tcher

@w1tcher w1tcher commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

FiberManager (qiling/os/windows/fiber.py) reports ERROR_INVALID_PARAMETER
for an invalid FLS index by writing self.last_error in free(), set() and
get(). But self.last_error is a plain attribute on the FiberManager
instance that nothing ever reads — it is written in three places and read
in none.

The Windows last-error that GetLastError returns lives on ql.os.last_error
(hook_GetLastError returns it, hook_SetLastError writes it, and every other
kernel32 hook sets errors via ql.os.last_error = ...). Because the FLS code
wrote the wrong object, FlsFree / FlsSetValue / FlsGetValue never actually
surfaced ERROR_INVALID_PARAMETER to the emulated program: a guest calling one
of these with a bad index, then GetLastError() to disambiguate the result,
would see a stale/zero error code.

Fix

Route the three writes to self.ql.os.last_error (the FiberManager already
holds self.ql), making the FLS error path consistent with the rest of
kernel32. No API surface or signature changes; 3 lines in one file.

This is independent of #1637 (which adds FlsGetValue2/get_noerr). It is worth
noting the two interact: only once the last-error actually lands on
ql.os.last_error does the intended FlsGetValue (sets error on bad index) vs
FlsGetValue2 (does not) distinction become observable to the guest.

Checklist

Which kind of PR do you create?

  • This PR only contains minor fixes.
  • This PR contains major feature update.
  • This PR introduces a new function/api for Qiling Framework.

Coding convention?

  • The new code conforms to Qiling Framework naming convention.
  • The imports are arranged properly.
  • Essential comments are added.
  • The reference of the new code is pointed out.

Extra tests?

  • No extra tests are needed for this PR.
  • I have added enough tests for this PR.
  • Tests will be added after some discussion and review.

Changelog?

  • This PR doesn't need to update Changelog.
  • Changelog will be updated after some proper review.
  • Changelog has been updated in my PR.

Target branch?

  • The target branch is dev branch.

One last thing

FiberManager.free/set/get set `self.last_error` on the FiberManager
instance, but nothing ever reads that attribute. The Windows last-error
that GetLastError returns lives on `ql.os.last_error`, so FlsFree,
FlsSetValue and FlsGetValue never actually reported ERROR_INVALID_PARAMETER
for an invalid FLS index. Route the three writes to `self.ql.os.last_error`,
consistent with every other kernel32 hook.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant