Skip to content

Correct passthrough sequences after refactor - #4125

Merged
8 commits merged into
masterfrom
dev/miniksa/4116
Jan 8, 2020
Merged

8 commits merged into
masterfrom
dev/miniksa/4116

Conversation

@miniksa

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

When refactoring the StateMachine::ProcessString algorithm to use safer structures, I made an off-by-one error when attempting to simplify the loop.

References

PR Checklist

Detailed Description of the Pull Request / Additional comments

The algorithm in use exploited holding onto some pointers and sizes as it rotated around the loop to call back as member variables in the pass-through function FlushToTerminal.

As a part of the refactor, I adjusted to persisting a std::wstring_view of the currently processing string instead of pointer/size. I also attempted to simplify the loop at the same time as both the individual and group branches were performing some redundant operations in respect to updating the "run" length.

Turns out, I made a mistake here. I wrote it so it worked correctly for the bottom half where we transition from bulk printing to an escape but then I messed up the top case.

Validation Steps Performed

  • Manual validation of the exact command given in the bug report.
  • Wrote automated tests to validate both paths through the ProcessString loop that work with the _run variable.

@zadjii-msft Mike Griese (zadjii-msft) added Area-VT Virtual Terminal sequence support Product-Conhost For issues in the Console codebase labels Jan 7, 2020
@DHowett-MSFT

Copy link
Copy Markdown
Contributor

Nit: reword title to be imperative

@miniksa Michael Niksa (miniksa) changed the title Corrects passthrough sequences after refactor Correct passthrough sequences after refactor Jan 7, 2020
@miniksa

Copy link
Copy Markdown
Contributor Author

Checked x86 conparser.unit.tests.dll locally

  • Debug passed
  • Release passed

So I'm going to re-run the x86 failed job.

@miniksa Michael Niksa (miniksa) removed the Needs-Second It's a PR that needs another sign-off label Jan 7, 2020
@zadjii-msft

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@zadjii-msft Mike Griese (zadjii-msft) added the AutoMerge Marked for automatic merge by the bot when requirements are met label Jan 7, 2020
@ghost

Copy link
Copy Markdown

Hello Mike Griese (@zadjii-msft)!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost
ghost merged commit 913c5ec into master Jan 8, 2020
@ghost
ghost deleted the dev/miniksa/4116 branch January 8, 2020 19:16
ghost pushed a commit that referenced this pull request Jan 14, 2020
## Summary of the Pull Request
Perform checking on `std::basic_string_view<T>.substr()` calls to
prevent running out of bounds and sporadic Privileged Instruction throws
during x86 tests.

## PR Checklist
* [x] Closes the x86 tests failing all over the place since #4125 for no
  apparent reason
* [x] I work here
* [x] Tests pass 

## Detailed Description of the Pull Request / Additional comments
It appears that not all `std::basic_string_view<T>.substr()` calls are
created equally. I rooted around for other versions of the code in our
source tree and found several versions that were less careful about
checking the start position and the size than the one that appears when
building locally on dev machines. 

My theory is that one of these older versions is deployed somewhere in
the CI. Instead of clamping down the size parameter appropriately or
throwing correctly when the position is out of bounds, I believe that
it's just creating a substring with a bad range over an
invalid/uninitialized memory region. Then when the test operates on
that, sometimes it turns out to trigger the privileged instruction
NTSTATUS error we are seeing in CI.

## Test Procedure
1. Fixed the thing
2. Ran the CI and it worked
3. Reverted everything and turned off all of the CI build except just
   the parser tests (and supporting libraries)
4. Ran CI and it failed
5. Put the fix back on top (cherry-pick)
6. It worked.
7. Ran it again.
8. It worked.
9. Turn all the rest of the CI build back on
Dustin L. Howett (MSFT) (DHowett-MSFT) pushed a commit that referenced this pull request Jan 24, 2020
## Summary of the Pull Request
Perform checking on `std::basic_string_view<T>.substr()` calls to
prevent running out of bounds and sporadic Privileged Instruction throws
during x86 tests.

## PR Checklist
* [x] Closes the x86 tests failing all over the place since #4125 for no
  apparent reason
* [x] I work here
* [x] Tests pass

## Detailed Description of the Pull Request / Additional comments
It appears that not all `std::basic_string_view<T>.substr()` calls are
created equally. I rooted around for other versions of the code in our
source tree and found several versions that were less careful about
checking the start position and the size than the one that appears when
building locally on dev machines.

My theory is that one of these older versions is deployed somewhere in
the CI. Instead of clamping down the size parameter appropriately or
throwing correctly when the position is out of bounds, I believe that
it's just creating a substring with a bad range over an
invalid/uninitialized memory region. Then when the test operates on
that, sometimes it turns out to trigger the privileged instruction
NTSTATUS error we are seeing in CI.

## Test Procedure
1. Fixed the thing
2. Ran the CI and it worked
3. Reverted everything and turned off all of the CI build except just
   the parser tests (and supporting libraries)
4. Ran CI and it failed
5. Put the fix back on top (cherry-pick)
6. It worked.
7. Ran it again.
8. It worked.
9. Turn all the rest of the CI build back on

(cherry picked from commit 4129ceb)
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-VT Virtual Terminal sequence support AutoMerge Marked for automatic merge by the bot when requirements are met Product-Conhost For issues in the Console codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConPTY pass-through sequences are being truncated

3 participants