Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Tesla’s “cheaper” Cybertruck arrives at $59,990, still far from the $40K promise

    Today’s NYT Connections Hints, Answers and Help for Feb. 21, #986

    Today’s NYT Strands Hints, Answers and Help for Feb. 21 #720

    Facebook X (Twitter) Instagram
    • Artificial Intelligence
    • Business Technology
    • Cryptocurrency
    • Gadgets
    • Gaming
    • Health
    • Software and Apps
    • Technology
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Tech AI Verse
    • Home
    • Artificial Intelligence

      Read the extended transcript: President Donald Trump interviewed by ‘NBC Nightly News’ anchor Tom Llamas

      February 6, 2026

      Stocks and bitcoin sink as investors dump software company shares

      February 4, 2026

      AI, crypto and Trump super PACs stash millions to spend on the midterms

      February 2, 2026

      To avoid accusations of AI cheating, college students are turning to AI

      January 29, 2026

      ChatGPT can embrace authoritarian ideas after just one prompt, researchers say

      January 24, 2026
    • Business

      The HDD brand that brought you the 1.8-inch, 2.5-inch, and 3.5-inch hard drives is now back with a $19 pocket-sized personal cloud for your smartphones

      February 12, 2026

      New VoidLink malware framework targets Linux cloud servers

      January 14, 2026

      Nvidia Rubin’s rack-scale encryption signals a turning point for enterprise AI security

      January 13, 2026

      How KPMG is redefining the future of SAP consulting on a global scale

      January 10, 2026

      Top 10 cloud computing stories of 2025

      December 22, 2025
    • Crypto

      Another European Country Bans Polymarket, Threatens Massive Fine

      February 20, 2026

      Why Is The US Stock Market Up Today?

      February 20, 2026

      Is XRP Price Preparing To Breach Its 2026 Downtrend? Here’s What History Says

      February 20, 2026

      “Disgrace” or “Win for American Wallets”? Supreme Court Tariff Bombshell Sparks Political Meltdown in Washington

      February 20, 2026

      Perle Labs CEO Ahmed Rashad on Why AI Needs Verifiable Data Infrastructure

      February 20, 2026
    • Technology

      Tesla’s “cheaper” Cybertruck arrives at $59,990, still far from the $40K promise

      February 20, 2026

      Today’s NYT Connections Hints, Answers and Help for Feb. 21, #986

      February 20, 2026

      Today’s NYT Strands Hints, Answers and Help for Feb. 21 #720

      February 20, 2026

      Today’s Wordle Hints, Answer and Help for Feb. 21, #1708

      February 20, 2026

      Los Angeles County Sues Roblox Over Ongoing Child-Safety Concerns

      February 20, 2026
    • Others
      • Gadgets
      • Gaming
      • Health
      • Software and Apps
    Check BMI
    Tech AI Verse
    You are at:Home»Technology»Checked-size array parameters in C
    Technology

    Checked-size array parameters in C

    TechAiVerseBy TechAiVerseDecember 3, 2025No Comments5 Mins Read3 Views
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Checked-size array parameters in C
    Share
    Facebook Twitter LinkedIn Pinterest WhatsApp Email

    Checked-size array parameters in C

    Welcome to LWN.net

    The following subscription-only content has been made available to you
    by an LWN subscriber. Thousands of subscribers depend on LWN for the
    best news from the Linux and free software communities. If you enjoy this
    article, please consider subscribing to LWN. Thank you
    for visiting LWN.net!

    By Jonathan Corbet
    December 1, 2025

    There are many possible programmer mistakes that are not caught by the
    minimal checks specified by the C language; among those is passing an array
    of the wrong size to a function. A recent attempt to add some safety
    around array parameters within the crypto layer involved the use of some
    clever tricks, but it turns out that clever tricks are unnecessary in this
    case. There is an obscure C feature that can cause this checking to
    happen, and it is already in use in a few places within the kernel.

    The discussion started when Ard Biesheuvel sought to
    improve the safety of the poetically named function
    xchacha20poly1305_encrypt():

        void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
    			           const u8 *ad, const size_t ad_len,
    			       	   const u8 nonce[XCHACHA20POLY1305_NONCE_SIZE],
    			       	   const u8 key[CHACHA20POLY1305_KEY_SIZE]);
    

    A potential problem with this function is that it takes as parameters
    several pointers to arrays of type u8. As Biesheuvel pointed out,
    the size of the nonce and key arrays is not checked by
    the compiler, even though it is clearly specified in the function
    prototype. That makes it easy to, for example, give the parameters in the
    wrong order. The resulting vulnerabilities are generally not the outcome
    developers have in mind when they write cryptographic code.

    Biesheuvel suggested that it was possible to write the prototype this way
    instead (differences shown in bold):

        void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
    			           const u8 *ad, const size_t ad_len,
    			       	   const u8 (*nonce)[XCHACHA20POLY1305_NONCE_SIZE],
    			       	   const u8 (*key)[CHACHA20POLY1305_KEY_SIZE]);
    

    The types of the last two arguments have changed; there is a new level of
    pointer indirection, with the argument being a pointer to an array of a
    given size. Callers must change their calls by adding an additional
    & operator to obtain the desired pointer type, but the address
    that is passed is the same. In this case, though, the compiler will check
    the sizes of the array passed, and will now catch a reordering of the
    arguments to the function.

    Jason Donenfeld was
    interested
    by the idea, but he knew of an arguably more straightforward
    way to address this problem. It seems that, buried deep within the C
    standard, is a strange usage of the static keyword, making it
    possible to write the prototype as:

        void xchacha20poly1305_encrypt(u8 *dst, const u8 *src, const size_t src_len,
    			           const u8 *ad, const size_t ad_len,
    			       	   const u8 nonce[static XCHACHA20POLY1305_NONCE_SIZE],
    			       	   const u8 key[static CHACHA20POLY1305_KEY_SIZE]);
    

    This, too, will cause the compiler to check the sizes of the arrays, and it
    does not require changes on the caller side. Unlike the pointer trick,
    which requires an exact match on the array size, use of static
    will only generate a warning if the passed-in array is too small. So it
    will not catch all mistakes, though it is sufficient to prevent
    memory-safety and swapped-argument problems.

    Eric Biggers pointed out
    that GCC can often generate “array too small” warnings even without
    static, but that the kernel currently disables those warnings;
    that would suppress them when static is used as well. (The
    warning was disabled in
    6.8
    due to false positives.) But he thought that adding
    static was worthwhile to get the warnings in Clang — if Linus
    Torvalds would be willing to accept use of “this relatively obscure
    feature of C
    “.

    Torvalds, as it turns out, has
    no objection
    to this usage; he likes the feature, if not the way it was
    designed:

    The main issue with the whole ‘static’ thing is just that the
    syntax is such a horrible hack, where people obviously picked an
    existing keyword that made absolutely no sense, but was also
    guaranteed to have no backwards compatibility issues.

    He pointed out that there are a number of places in the kernel that are
    already using it; for a simple example, see getconsxy()
    in the virtual-terminal driver. He suggested perhaps hiding it with a
    macro like min_array_size() just to make the usage more obvious,
    but didn’t seem convinced that it was necessary. Donenfeld followed up with
    a patch to that effect a few days later, but then pivoted to an
    at_least marker
    instead.

    A lot of work has gone into the kernel to make its use of C as safe as
    possible, but that does not mean that the low-hanging fruit has all been
    picked. The language has features, such as static when used to
    define formal array parameters, that can improve safety, but which are not
    generally known and not often used. In this particular case, though, it
    would not be surprising to see this “horrible hack” come into wider
    use in the near future.

    Index entries for this article
    Kernel C language safety
    Kernel Releases/6.19




    Share. Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Telegram Email
    Previous ArticleShow HN: I built a dashboard to compare mortgage rates across 120 credit unions
    Next Article Agentic Development Environment by JetBrains
    TechAiVerse
    • Website

    Jonathan is a tech enthusiast and the mind behind Tech AI Verse. With a passion for artificial intelligence, consumer tech, and emerging innovations, he deliver clear, insightful content to keep readers informed. From cutting-edge gadgets to AI advancements and cryptocurrency trends, Jonathan breaks down complex topics to make technology accessible to all.

    Related Posts

    Tesla’s “cheaper” Cybertruck arrives at $59,990, still far from the $40K promise

    February 20, 2026

    Today’s NYT Connections Hints, Answers and Help for Feb. 21, #986

    February 20, 2026

    Today’s NYT Strands Hints, Answers and Help for Feb. 21 #720

    February 20, 2026
    Leave A Reply Cancel Reply

    Top Posts

    Ping, You’ve Got Whale: AI detection system alerts ships of whales in their path

    April 22, 2025684 Views

    Lumo vs. Duck AI: Which AI is Better for Your Privacy?

    July 31, 2025274 Views

    6.7 Cummins Lifter Failure: What Years Are Affected (And Possible Fixes)

    April 14, 2025158 Views

    6 Best MagSafe Phone Grips (2025), Tested and Reviewed

    April 6, 2025118 Views
    Don't Miss
    Technology February 20, 2026

    Tesla’s “cheaper” Cybertruck arrives at $59,990, still far from the $40K promise

    Tesla’s “cheaper” Cybertruck arrives at $59,990, still far from the $40K promiseTesla’s latest features an…

    Today’s NYT Connections Hints, Answers and Help for Feb. 21, #986

    Today’s NYT Strands Hints, Answers and Help for Feb. 21 #720

    Today’s Wordle Hints, Answer and Help for Feb. 21, #1708

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    About Us
    About Us

    Welcome to Tech AI Verse, your go-to destination for everything technology! We bring you the latest news, trends, and insights from the ever-evolving world of tech. Our coverage spans across global technology industry updates, artificial intelligence advancements, machine learning ethics, and automation innovations. Stay connected with us as we explore the limitless possibilities of technology!

    Facebook X (Twitter) Pinterest YouTube WhatsApp
    Our Picks

    Tesla’s “cheaper” Cybertruck arrives at $59,990, still far from the $40K promise

    February 20, 20260 Views

    Today’s NYT Connections Hints, Answers and Help for Feb. 21, #986

    February 20, 20260 Views

    Today’s NYT Strands Hints, Answers and Help for Feb. 21 #720

    February 20, 20260 Views
    Most Popular

    7 Best Kids Bikes (2025): Mountain, Balance, Pedal, Coaster

    March 13, 20250 Views

    VTOMAN FlashSpeed 1500: Plenty Of Power For All Your Gear

    March 13, 20250 Views

    This new Roomba finally solves the big problem I have with robot vacuums

    March 13, 20250 Views
    © 2026 TechAiVerse. Designed by Divya Tech.
    • Home
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

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