Skip to content

SetConsoleMode with an invalid mode leaves it tainted #13738

Closed

Description

Windows Terminal version

1.15.2002.0

Windows build number

10.0.19044.0

Other Software

No response

Steps to reproduce

#include <stdio.h>
#include <windows.h>

int main() {
	DWORD initial_mode = 0;
	HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
	if (!GetConsoleMode(in, &initial_mode)) {
		puts("GetConsoleMode failed");
		return 1;
	}
	printf("0x%x\n", initial_mode);
	if (!SetConsoleMode(in, -1)) {
		puts("SetConsoleMode failed");
	};
	DWORD new_mode = 0;
	if (!GetConsoleMode(in, &new_mode)) {
		puts("GetConsoleMode failed");
		return 1;
	}
	printf("0x%x\n", new_mode);
	return new_mode != initial_mode;
}

Expected Behavior

Trying to set the console mode to an invalid value should fail and not change it.

Actual Behavior

Setting the console mode with an unsupported flag reports failure but still sets it.
This is unfortunate as it will cause all subsequent calls to SetConsoleMode with a value from GetConsoleMode to report failure.

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

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIt either shouldn't be doing this or needs an investigation.Needs-Tag-FixDoesn't match tag requirementsResolution-By-DesignIt's supposed to be this way. Sometimes for compatibility reasons.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions