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

      The Ultimate Guide to Node.js Development Pricing for Enterprises

      July 29, 2025

      Stack Overflow: Developers’ trust in AI outputs is worsening year over year

      July 29, 2025

      Web Components: Working With Shadow DOM

      July 28, 2025

      Google’s new Opal tool allows users to create mini AI apps with no coding required

      July 28, 2025

      I replaced my Samsung OLED TV with this Sony Mini LED model for a week – and didn’t regret it

      July 29, 2025

      I tested the most popular robot mower on the market – and it was a $5,000 crash out

      July 29, 2025

      5 gadgets and accessories that leveled up my gaming setup (including a surprise console)

      July 29, 2025

      Why I’m patiently waiting for the Samsung Z Fold 8 next year (even though the foldable is already great)

      July 29, 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

      Performance Analysis with Laravel’s Measurement Tools

      July 29, 2025
      Recent

      Performance Analysis with Laravel’s Measurement Tools

      July 29, 2025

      Memoization and Function Caching with this PHP Package

      July 29, 2025

      Laracon US 2025 Livestream

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

      Microsoft mysteriously offered a Windows 11 upgrade to this unsupported Windows 10 PC — despite it failing to meet the “non-negotiable” TPM 2.0 requirement

      July 29, 2025
      Recent

      Microsoft mysteriously offered a Windows 11 upgrade to this unsupported Windows 10 PC — despite it failing to meet the “non-negotiable” TPM 2.0 requirement

      July 29, 2025

      With Windows 10’s fast-approaching demise, this Linux migration tool could let you ditch Microsoft’s ecosystem with your data and apps intact — but it’s limited to one distro

      July 29, 2025

      Windows 10 is 10 years old today — let’s look back at 10 controversial and defining moments in its history

      July 29, 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

    I replaced my Samsung OLED TV with this Sony Mini LED model for a week – and didn’t regret it

    July 29, 2025
    News & Updates

    I tested the most popular robot mower on the market – and it was a $5,000 crash out

    July 29, 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

    Rilasciato Fastfetch 2.42: lo strumento per le informazioni di sistema si aggiorna e migliora il supporto BSD

    Linux

    CVE-2025-6218: WinRAR Directory Traversal Bug Opens the Door to Remote Code Execution

    Security

    Commvault back-upserver via kritiek path traversal-lek over te nemen

    Security

    CVE-2025-38174 – “Thunderbolt: Double Dequeue Vulnerability”

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    CVE-2024-57394 – Qi-ANXIN Tianqing Endpoint Security Management System DLL Hijacking Vulnerability

    April 21, 2025

    CVE ID : CVE-2024-57394

    Published : April 21, 2025, 6:15 p.m. | 47 minutes ago

    Description : The quarantine – restore function in Qi-ANXIN Tianqing Endpoint Security Management System v10.0 allows user to restore a malicious file to an arbitrary file path. Attackers can write malicious DLL to system path and perform privilege escalation by leveraging Windows DLL hijacking vulnerabilities.

    Severity: 0.0 | NA

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    Critical WordPress Plugin Vulnerability Exposes 600,000+ Sites to Remote Takeover

    July 2, 2025

    CVE-2025-6645 – PDF-XChange Editor U3D File Parsing Use-After-Free Remote Code Execution Vulnerability

    June 25, 2025

    The AI Fix #48: AI Jesus, and is the AI Singularity almost upon us?

    April 29, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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