Skip to content

Commit

Permalink
Add range check to keyboard backlight commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparronator9999 committed Dec 4, 2024
1 parent 9348b22 commit cf6dba2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions YAMDCC.GUI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,14 @@ private void IPC_MessageReceived(object sender, PipeMessageEventArgs<ServiceResp
{
if (int.TryParse(args[0], out int value))
{
// value received from service should be valid,
// but let's check anyway to avoid potential crashes
// from non-official YAMDCC services
if (value < 0 || value > Config.KeyLightConf.MaxVal - Config.KeyLightConf.MinVal)
{
break;
}

tbKeyLight.Invoke(new Action(delegate
{
tbKeyLight.Maximum = Config.KeyLightConf.MaxVal - Config.KeyLightConf.MinVal;
Expand Down
5 changes: 4 additions & 1 deletion YAMDCC.Service/FanControlService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,10 @@ private int GetKeyLightBright(int clientId)
if (success)
{
int brightness = value - Config.KeyLightConf.MinVal;
response = new(Response.KeyLightBright, $"{brightness}");

response = value < Config.KeyLightConf.MinVal || value > Config.KeyLightConf.MaxVal
? new(Response.Error, $"{(int)Command.GetKeyLightBright}")
: new(Response.KeyLightBright, $"{brightness}");
}
else
{
Expand Down

0 comments on commit cf6dba2

Please sign in to comment.