Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      CodeSOD: A Unique Way to Primary Key

      July 22, 2025

      BrowserStack launches Figma plugin for detecting accessibility issues in design phase

      July 22, 2025

      Parasoft brings agentic AI to service virtualization in latest release

      July 22, 2025

      Node.js vs. Python for Backend: 7 Reasons C-Level Leaders Choose Node.js Talent

      July 21, 2025

      The best CRM software with email marketing in 2025: Expert tested and reviewed

      July 22, 2025

      This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

      July 22, 2025

      I’m a wearables editor and here are the 7 Pixel Watch 4 rumors I’m most curious about

      July 22, 2025

      8 ways I quickly leveled up my Linux skills – and you can too

      July 22, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025
      Recent

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025

      Zero Trust & Cybersecurity Mesh: Your Org’s Survival Guide

      July 22, 2025

      Execute Ping Commands and Get Back Structured Data in PHP

      July 22, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025
      Recent

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025

      “I don’t think I changed his mind” — NVIDIA CEO comments on H20 AI GPU sales resuming in China following a meeting with President Trump

      July 22, 2025

      Galaxy Z Fold 7 review: Six years later — Samsung finally cracks the foldable code

      July 22, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: The Wrong Kind of Character

    CodeSOD: The Wrong Kind of Character

    April 29, 2025

    Today’s code, at first, just looks like using literals instead of constants. Austin sends us this C#, from an older Windows Forms application:

    if (e.KeyChar == (char)4) {   // is it a ^D?
            e.Handled = true;
            DoStuff();
    }
    else if (e.KeyChar == (char)7) {   // is it a ^g?
            e.Handled = true;
            DoOtherStuff();
    }
    else if (e.KeyChar == (char)Keys.Home) {
            e.Handled = true;
            SpecialGoToStart();
    }
    else if (e.KeyChar == (char)Keys.End) {
            e.Handled = true;
            SpecialGoToEnd();
    } 
    

    Austin discovered this code when looking for a bug where some keyboard shortcuts didn’t work. He made some incorrect assumptions about the code- first, that they were checking for a KeyDown or KeyUp event, a pretty normal way to check for keyboard shortcuts. Under that assumption, a developer would compare the KeyEventArgs.KeyCode property against an enum- something like e.KeyCode == Keys.D && Keys.Control, for a CTRL+D. That’s clearly not what’s happening here.

    No, here, they used the KeyPressEvent, which is meant to represent the act of typing. That gives you a KeyPressEventArgs with a KeyChar property- because again, it’s meant to represent typing text not keyboard shortcuts. They used the wrong event type, as it won’t tell them about modifier keys in use, or gracefully handle the home or end keys. KeyChar is the ASCII character code of the key press: which, in this case, CTRL+D is the “end of transmit” character in ASCII (4), and CTRL+G is the goddamn bell character (7). So those two branches work.

    But home and end don’t have ASCII code points. They’re not characters that show up in text. They get key codes, which represent the physical key pressed, not the character of text. So (char)Keys.Home isn’t really a meaningful operation. But the enum is still a numeric value, so you can still turn it into a character- it just turns into a character that emphatically isn’t the home key. It’s the “$”. And Keys.End turns into a “#”.

    It wasn’t very much work for Austin to move the event handler to the correct event type, and switch to using KeyCodes, which were both more correct and more readable.

    [Advertisement]
    Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleFog Ransomware Directory With Active Directory Exploitation Tools & Scripts Uncovered
    Next Article Oshin OS is an Arch Linux distribution

    Related Posts

    News & Updates

    The best CRM software with email marketing in 2025: Expert tested and reviewed

    July 22, 2025
    News & Updates

    This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

    July 22, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    CVE-2025-7506 – Tenda FH451 HTTP POST Request Handler Stack-Based Buffer Overflow

    Common Vulnerabilities and Exposures (CVEs)

    Community News: Latest PECL Releases (04.29.2025)

    Development

    CVE-2025-49182 – Citrix Application Credentials Disclosure

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-6911 – PHPGurukul Student Record System SQL Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Community News: Latest PECL Releases (04.22.2025)

    April 22, 2025

    Latest PECL Releases: brotli 0.16.0 – change: brotli.state resource in brotli_uncompress_{init,add}() to BtorliUnCompressContext class change:…

    CVE-2025-48062 – Discourse HTML Injection Vulnerability

    June 9, 2025
    Implement human-in-the-loop confirmation with Amazon Bedrock Agents

    Implement human-in-the-loop confirmation with Amazon Bedrock Agents

    April 9, 2025

    CVE-2025-4384 – PcVue MQTT Certificate Validation Bypass

    May 6, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.