https://spectrum.ieee.org/memory-safe-programming-languages [ ] IEEE.orgIEEE Xplore Digital LibraryIEEE StandardsMore Sites Sign InJoin IEEE The Move to Memory-Safe Programming Share FOR THE TECHNOLOGY INSIDER Search: [ ] Explore by topic AerospaceArtificial IntelligenceBiomedicalComputingConsumer ElectronicsEnergyHistory of TechnologyRoboticsSemiconductorsSensors TelecommunicationsTransportation IEEE Spectrum FOR THE TECHNOLOGY INSIDER Topics AerospaceArtificial IntelligenceBiomedicalComputingConsumer ElectronicsEnergyHistory of TechnologyRoboticsSemiconductorsSensors TelecommunicationsTransportation Sections FeaturesNewsOpinionCareersDIYThe Big PictureEngineering Resources More Special ReportsCollectionsExplainersPodcastsVideosNewslettersTop Programming LanguagesRobots Guide For IEEE Members Current IssueMagazine ArchiveThe InstituteTI Archive For IEEE Members Current IssueMagazine ArchiveThe InstituteTI Archive IEEE Spectrum About UsContact UsReprints & PermissionsAdvertising Follow IEEE Spectrum Support IEEE Spectrum IEEE Spectrum is the flagship publication of the IEEE -- the world's largest professional organization devoted to engineering and applied sciences. Our articles, podcasts, and infographics inform our readers about developments in technology, engineering, and science. Join IEEE Subscribe About IEEEContact & SupportAccessibilityNondiscrimination PolicyTerms IEEE Privacy Policy (c) Copyright 2023 IEEE -- All rights reserved. A not-for-profit organization, IEEE is the world's largest technical professional organization dedicated to advancing technology for the benefit of humanity. IEEE websites place cookies on your device to give you the best user experience. By using our websites, you agree to the placement of these cookies. To learn more, read our Privacy Policy. view privacy policy accept & close Enjoy more free content and benefits by creating an account Saving articles to read later requires an IEEE Spectrum account The Institute content is only available for members Downloading full PDF issues is exclusive for IEEE Members Access to Spectrum's Digital Edition is exclusive for IEEE Members Following topics is a feature exclusive for IEEE Members Adding your response to an article requires an IEEE Spectrum account Create an account to access more content and features on IEEE Spectrum, including the ability to save articles to read later, download Spectrum Collections, and participate in conversations with readers and editors. For more exclusive content and features, consider Joining IEEE. Join the world's largest professional organization devoted to engineering and applied sciences and get access to all of Spectrum's articles, archives, PDF downloads, and other benefits. Learn more - CREATE AN ACCOUNTSIGN IN JOIN IEEESIGN IN Close Special offer: Join IEEE now for 2023 and save 50%! IEEE Members receive 12 print issues of IEEE Spectrum and enjoy PDF downloads, full access to our archive with thousands of in-depth articles, and other exclusive content and features. Join IEEE today for 2023 and save 50%! JOIN IEEE ComputingTopicNewsType The Move to Memory-Safe Programming Shifting from C and C++ to memory-safe programming languages like Rust is gaining ground Rina Diane Caballar 6h 3 min read zeros and ones in a random sequence, a few brighter to look like an outline of a brain iStock Rustcodingprogramming languagesmemory Memory safety is in the spotlight. In November 2022, the National Security Agency recommended the use of memory-safe programming languages to protect against software-memory safety issues. Earlier this year, Consumer Reports encouraged the use of memory-safe languages in its "Future of Memory Safety" report. "One of the key reasons why memory-safe languages are gaining popularity now is the prevalence of security issues, one of the main causes of which are memory-safety vulnerabilities," says Azalea Raad, a senior lecturer in the Department of Computing at Imperial College London. Memory safety is a feature of programming languages that prevents certain types of memory-access bugs, such as out-of-bounds reads and writes, and use-after-free bugs. In an app that manages a list of to-do items, for example, an out-of-bounds read could involve accessing the nonexistent sixth item in a list of five, while a use-after-free bug could involve accessing one of the items on an already deleted to-do list. These bugs could lead to accessing private data, corrupting data, or even executing code that isn't part of a program. "For instance, an out-of-bounds read can result in reading from adjacent blocks in memory that may contain sensitive data," Raad says. "Similarly, an out-of-bounds write can overwrite sensitive information in memory and lead to hijacking the control flow of the program and executing privileged or malicious code." In memory-safe languages, these bugs are caught during compile time or runtime. At compile time, they're flagged as errors which can then be fixed. When detected at runtime, they result in crashes instead of allowing unchecked access to memory, thereby limiting the potential damage and preventing security vulnerabilities. Most programming languages are considered memory-safe--except for C, C++, and assembly. "Until the last few years, almost all systems software was written in C or C++, which are notoriously not memory-safe," says Dan Grossman, a professor and vice director of the Paul G. Allen School of Computer Science & Engineering at the University of Washington. Some tech companies responsible for systems software--such as operating systems and other low-level systems--are beginning to realize the importance of memory safety. In 2019, Google and Microsoft reported that a majority of vulnerabilities in their products have been memory-safety issues, and a similar study on Apple's operating systems found the same. These companies are taking action by adopting more memory-safe languages. For example, Meta is embracing Rust and Linux is adding support for the language in its kernel. In Google's Android 13 OS, about one-fifth of all new native code is in Rust, with the search giant seeing a significant drop in both the number and severity of memory-safety vulnerabilities. "We're now understanding that memory-safety vulnerabilities aren't some esoteric computer science concept," says Josh Aas, executive director of the Internet Security Research Group, whose Prossimo project is promoting the move toward memory safety. "They are a real consumer-safety issue. They are a national cybersecurity issue." Rust--ranked 20th in IEEE Spectrum's top programming languages of 2022 --is a memory-safe alternative to C and C++ and can be used to write low-level system code or develop an OS kernel, according to Raad. She also suggests software developers switch to Swift when developing for iOS and macOS; Kotlin when developing for Android as it offers interoperability with Java, the primary language Android was written in; and Go when writing network code for servers. To make the move to new programming languages more manageable--especially for software developers working on large code bases--Raad recommends starting with a new code base instead of an existing one, as it would involve no code rewriting "but would still require adapting and extending the existing infrastructure for testing and deployment to support the new language." The next step is to target new modules of existing code bases, which also doesn't warrant any code rewrites but "has a higher overhead as it would require building abstractions such as data structures for exchanging data that crosses the boundary between the two languages," says Raad. Finally, programmers could look into rewriting an existing module in a memory-safe language. "Ideally, this should be a module with a small scope to minimize the inherent risks of code rewrites and where there is a clear performance or security advantage in switching to a memory-safe language," says Raad. To further simplify the shift, coders could take advantage of application programming interfaces (APIs). "A lot of Rust components come with a C API, so you can benefit from that and you don't have to learn a whole new language," Aas says. He adds that testing is also vital when adopting memory-safe languages. "If you're worried about the idea that rewriting code might cause bugs, it's good to recognize that investments in writing tests for your existing code are going to pay off here," Aas says. "If you have really good tests for your current code, then those tests are going to help you verify that any rewriting in a memory-safe language is correct." Moreover, companies themselves could facilitate programming in memory-safe languages by providing training opportunities and engaging senior software engineers as language champions, which could make "a significant difference as they can provide code review and train developers new to the language," says Raad. The shift to a new programming language usually entails a learning curve, but "in the case of memory safety, the payoff is typically worth it," says Grossman. "The world of 'one bug can make the entire system inherently insecure' is simply too dangerous." From Your Site Articles * How the Boeing 737 Max Disaster Looks to a Software Developer > * More Worries over the Security of Web Assembly > Related Articles Around the Web * Memory safe programming languages are on the rise. Here's how ... > * We need a safer systems programming language - Microsoft ... > Rustcodingprogramming languagesmemory Rina Diane Caballar Rina Diane Caballar is a journalist and former software engineer based in Wellington, New Zealand. The Conversation (0) a green hand covered with a memory board pattern and holding a computer chip and a blue-ish human hand form a circle with each other Artificial IntelligenceTopicTypeSemiconductorsNews Human-AI Team Ups Could Slash Chip-Development Costs 6h 4 min read An illustration of a pink sheet of data over a man's head. BiomedicalTopicMagazineTypeFeature How an Electrical Engineer Solved Australia's Most Famous Cold Case 7h 11 min read A photo of two bipedal robots moving grey plastic bins around a model warehouse RoboticsTopicTypeNews Agility's Latest Digit Robot Prepares for Its First Job 8h 4 min read Related Stories History of TechnologyTopicMagazineTypeFeatureFebruary 2023 Who Really Invented the Thumb Drive? ComputingTopicMagazineTypeNewsJanuary 2023 Ownership of AI-Generated Code Hotly Disputed History of TechnologyTopicTypeComputingGuest Article Celebrating the Art of Code