|
|
Log in / Subscribe / Register

Memory-safe C code

Memory-safe C code

Posted Nov 16, 2025 17:49 UTC (Sun) by mb (subscriber, #50428)
In reply to: Memory-safe C code by khim
Parent article: Rust in Android: move fast and fix things (Google Security Blog)

I think we need a combination of everything.

- Improve current compilers and checker tools to catch more cases while keeping the required changes to the code low. This will never bring C safety anywhere near that of safe languages, but it will definitely make it safer.
- Write new code in safe languages only.
- Compile existing code with tools like Fil-C, if performance is less of an issue.
- Rewrite critical parts that directly interact with untrusted data (e.g. complex parsers) in safe languages.

All of this is currently being done or being experimented with.
And I think we need *all* of these things to improve the over all situation without going to unrealistic scenarios like "Rewrite everything in Rust".


to post comments

Memory-safe C code

Posted Nov 16, 2025 18:03 UTC (Sun) by khim (subscriber, #9252) [Link] (20 responses)

> And I think we need *all* of these things to improve the over all situation without going to unrealistic scenarios like "Rewrite everything in Rust".

It's only unrealistic if you try to push it. I'm pretty sure eventually everything would rewritten Rust, but the trick is that if you would try to set a predetermined date when that should happen… people would find a way to fail to upgrade. Just think about the fate of Flash, specifically about The China-specific variant of Flash is still supported, by a company known as Zhongcheng.

Memory-safe C code

Posted Nov 16, 2025 19:50 UTC (Sun) by pizza (subscriber, #46) [Link] (19 responses)

> It's only unrealistic if you try to push it. I'm pretty sure eventually everything would rewritten Rust

...Just like all COBOL would be rewritten in something else, all FORTRAN would be rewritten in something else, etc etc?

Memory-safe C code

Posted Nov 16, 2025 19:55 UTC (Sun) by khim (subscriber, #9252) [Link]

More-or-less. COBOL and FORTRAN are stuck around because behemoths that used them initially are still with us — and, more importantly, behemoth that supports them, IBM, is still with us (and is accessible). With collapse of the unified world order IBM's support would become unavailable and then people would have to rewrite all that.

Rust seems well-poised for such rewrite but because we couldn't predict the exact timeframe of that process we don't know whether it would happen when Rust is the best candidate, or, perhaps, 10 years down the road when something even better would be invented.

But given where things are moving it doesn't look like we'll have 10 years.

Memory-safe C code

Posted Nov 17, 2025 12:11 UTC (Mon) by farnz (subscriber, #17727) [Link] (17 responses)

I think FORTRAN (and Fortran) are a good example of where things can go, yes.

Some people still use Fortran in niches where it's extremely productive, but then link it against other languages (I use, for example, a program that has a mix of Qt/C++ and Fortran, where the Fortran is doing some highly optimized number crunching, and the C++ is doing the UI and system interface).

Similarly, there's plenty of legacy FORTRAN out there that isn't going to get rewritten, because it does its job well, and it's been in use for long enough that all user-visible bugs have been fixed by now. Rewriting this would just risk introducing user-visible bugs for no benefit.

But outside those two categories (niche it excels in, legacy code), it's not really being used much. You'd not normally see a new project started in FORTRAN (or even Fortran 90 or later), and if parts of the code are problematic, they'll probably be replaced with code in a new language (Julia, Python with numpy, or others) instead of putting a lot of time and effort into fixing the FORTRAN codebase, but why expend effort for no gain?

Memory-safe C code

Posted Nov 17, 2025 15:22 UTC (Mon) by ballombe (subscriber, #9523) [Link] (2 responses)

There are new fortran projects created every days, to run on large MPI clusters.
python or julia are not an option there.

Memory-safe C code

Posted Nov 17, 2025 15:23 UTC (Mon) by farnz (subscriber, #17727) [Link]

That qualifies as a niche; large MPI clusters are not a common case, and it's a niche in which Fortran is extremely productive.

Memory-safe C code

Posted Nov 21, 2025 0:03 UTC (Fri) by tialaramex (subscriber, #21167) [Link]

So, it happens that the people who look after at least two of my country's big MPI clusters work upstairs from me and I sometimes have lunch with them. There are Fortran (and even FORTRAN) manuals on their bookshelf - but in fact none of their current team can write Fortran and as I understand it there's no call for that to change.

Thirty years ago, the people who looked after the distant ancestors of those clusters all knew Fortran, which is presumably why we have Fortran books. Twenty years ago, there were definitely still people in their team who knew Fortran. But they were getting old, and in those twenty years they're all gone.

I don't know Julia, but I can tell you that while you obviously shouldn't write the actual bit-banging code in Python there is indeed MPI Python, because if you're comfortable in Python you can write all your high level code that way, and a native library (written in C, Rust, or indeed in principle Fortran) does the bit-banging without you needing to understand how exactly that works.

Memory-safe C code

Posted Nov 18, 2025 8:25 UTC (Tue) by taladar (subscriber, #68407) [Link] (13 responses)

FORTRAN is maybe also not the best example in terms of legacy code bases because it is often used in purely mathematical areas that by their very nature don't change much. Code bases that deal with concerns more closely linked to a changing real world (e.g. regulation, evolving cryptographic algorithms or protocols, parsers of changing file formats or network protocols) would be less likely to be usable unchanged for long enough that people would consider them bug and maintenance free.

Memory-safe C code

Posted Nov 18, 2025 9:46 UTC (Tue) by anselm (subscriber, #2796) [Link] (12 responses)

Code bases that deal with concerns more closely linked to a changing real world (e.g. regulation, evolving cryptographic algorithms or protocols, parsers of changing file formats or network protocols) would be less likely to be usable unchanged for long enough that people would consider them bug and maintenance free.

This is why these days, COBOL programmers get to name their own salaries.

Memory-safe C code

Posted Nov 19, 2025 9:28 UTC (Wed) by taladar (subscriber, #68407) [Link] (11 responses)

Which is a good data point to indicate that the companies still using COBOL did wait too long rewriting their code in something else, especially considering that even those COBOL programmers are dying off now.

Memory-safe C code

Posted Nov 19, 2025 9:37 UTC (Wed) by Wol (subscriber, #4433) [Link] (10 responses)

Or that they're happy to pay megabucks to pinch existing Cobol guys, but too stingy to provide a career path to cross-train people into it.

I can understand computer guys being wary of "learning a dinosaur skill", but if it's treated as "just another language programmers are expected to know", and they don't find themselves exclusively on Cobol? Or they take people from other skills who want to get into that sort of thing, and train them up?

The problem, basically, is that Cobol is no longer "sexy", so people don't come into the workforce knowing it ...

Compared to Fortran, programming is a side-line for scientists, and if a scientist is told "learn Fortran" it's not viewed as a career-defining choice.

Cheers,
Wol

COBOL programmers

Posted Nov 19, 2025 9:55 UTC (Wed) by farnz (subscriber, #17727) [Link] (8 responses)

Nowadays, they pay to train people in COBOL because it is cheaper to train a new programmer to do COBOL well than it is to rewrite the code in a newer language. Most people I know who've gone this route paid off their mortgage, then learnt COBOL as a way to get a low-stress, decent pay job to take them into retirement, although there are a few who learnt it straight out of university as part of working for a contracting firm who does COBOL stuff.

COBOL programmers

Posted Nov 19, 2025 13:21 UTC (Wed) by nijhof (subscriber, #4034) [Link]

When I was a PhD student, 1990-something, I started applying for a Cobol job. A fellow student got rejected because he got all answers right on the test...

COBOL programmers

Posted Nov 20, 2025 9:27 UTC (Thu) by taladar (subscriber, #68407) [Link] (6 responses)

Not sure I would consider a job low-stress that involves exclusively work with legacy projects.

Working on legacy projects can be low stress *if* demand on you is low.

Posted Nov 20, 2025 9:49 UTC (Thu) by farnz (subscriber, #17727) [Link]

It's low-stress if you work directly for a company with a COBOL codebase, because the demands are small. The consultancies charge about the same for a month of COBOL work as it costs to employ a person for a year, and thus organisations that would otherwise have to pay for multiple months per year of consultancy time have a huge incentive to keep their in-house COBOL programmers happy.

As, by and large, the COBOL programmers are willing to accept lower salaries (because of the low stress) than similarly experienced programmers working in modern languages, it's obvious to the usual suspects for causing stress that the COBOL programmers should be left alone - there's lower-hanging fruit than the people who aren't the highest paid programmers, and who are responsible for business-critical systems.

COBOL programmers

Posted Nov 20, 2025 14:44 UTC (Thu) by mathstuf (subscriber, #69389) [Link]

I think there's a difference between working with perpetually legacy code rather than code that *becomes* legacy every 6 months. I think I would prefer the former given the choice between the two. Or, maybe, neither and instead decide to be outside more often ;D .

Legacy projects (was: COBOL programmers)

Posted Nov 20, 2025 15:33 UTC (Thu) by dskoll (subscriber, #1630) [Link] (3 responses)

My last job prior to retirement was working on a large legacy codebase that had some... interesting... architectural decisions and quite a lot of technical debt. I spent much of my time cleaning it up and getting rid of technical debt, as well as adding a few new features.

I really enjoyed it. There's something about my brain that enjoys reverse-engineering and cleaning up old code bases. Additionally, the job was pretty chill, my coworkers were great, and there were no crazy externally-imposed arbitrary deadlines. I felt that I ended my career on a high.

Legacy projects (was: COBOL programmers)

Posted Nov 21, 2025 10:12 UTC (Fri) by taladar (subscriber, #68407) [Link] (2 responses)

It sounds like a large part of that enjoyment was in actually being able to change the legacy code though, so it depends a bit on how hard the legacy project drives the idea that any code change beyond the absolute minimum necessary is bad because it might introduce new bugs.

Legacy projects (was: COBOL programmers)

Posted Nov 21, 2025 12:51 UTC (Fri) by Wol (subscriber, #4433) [Link]

I thoroughly enjoy that sort of work too.

A lot of it is cleaning up technical debt - getting rid of all those repeatedly-invented wheels, turning duplicated code into subroutines, writing utility subroutines/macros/programs to maximise code re-use, eliminating dead code, yadda yadda. Writing a retrospective specification !!!

And it's the pleasure of leaving the code in a much better state for the people who come after you.

Cheers,
Wol

Legacy projects (was: COBOL programmers)

Posted Nov 21, 2025 14:15 UTC (Fri) by farnz (subscriber, #17727) [Link]

In general, the places that employ in-house programmers are very happy for you to refactor the legacy code - they have a certain amount of necessary change they have to do each year (things like complying with new regulations, or fixing bugs that don't show up until you have an end date after 2050), and they want that necessary change to happen quickly.

They recognise that change carries a risk of bugs, but they also recognise that it's better to have a weekly small chance of a bug (whether caused by a refactor, or caused by a required change) than a bigger chance of a bug when a required change is made. And they're hopeful that, by getting test cases written for each bug found when refactoring is done, they'll eventually reach a point where the test suite is big enough to let them rewrite in a new language (Java, Python, Go, TypeScript, whatever) without hitting the same issues previous rewrites have had.

Memory-safe C code

Posted Nov 20, 2025 5:17 UTC (Thu) by rgmoore (✭ supporter ✭, #75) [Link]

Or that they're happy to pay megabucks to pinch existing Cobol guys, but too stingy to provide a career path to cross-train people into it.

Once hiring experienced COBOL programmers away from another company is an accepted strategy, it makes training your own people less viable. It's a general problem with loss of loyalty*. If you can get employees with the skills you need by hiring them away from someone else, there's way less incentive to train people in house. On the one hand, it's faster (and consequently probably cheaper in the short term) to hire someone who already has the skills than to train an existing employee. On the other hand, if a company trains someone in house, the trainee may get hired away as soon as they know enough to be productive in their new skill.

*And I mean that both ways. Companies have to be loyal to their employees if they want loyalty in return.


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds