News for hackers. Stuff that matters.
Re:Don't setenv in multi-threaded code on glibc by pjmlp on Tuesday January 31, 2017 @06:13AM (#13529604)
Because as anyone doing POSIX development across multiple OS learns, that is an implementation detail.

POSIX like any other paper standard implies write once debug everywhere.

Re:Don't setenv in multi-threaded code on glibc by masklinn on Tuesday January 31, 2017 @09:35AM (#13530830)
> Because as anyone doing POSIX development across multiple OS learns, that is an implementation detail.

The problem is the interface is naturally unsafe. Much like e.g. strcpy, the interface means it's nigh impossible to use it safely.

Re:Don't setenv in multi-threaded code on glibc by pjmlp on Tuesday January 31, 2017 @01:04PM (#13533314)
Which is the reason that even if we would write an UNIX OS in something like Ada or Rust instead of C, we wouldn't get away from security exploits caused by the UNIX API.

Hence why in parallel with better systems languages, we really need tagged architectures for pointers, like what SPARC V8, Intel MPX, Cherry offer, to become widespread, for better security.

Re:Don't setenv in multi-threaded code on glibc by quotemstr on Tuesday January 31, 2017 @01:11PM (#13533392)
Upthread, I pointed out a sane and safe alternative to POSIX getenv interface, one that works fine with regular C, and here, you're claiming that we need exotic features to achieve safety? What?
Re:Don't setenv in multi-threaded code on glibc by pjmlp on Tuesday January 31, 2017 @03:08PM (#13534712)
Because you only focused on getenv.

I was replying about the whole UNIX API surface, regarding functions like strcpy.

You need exotic features to guarantee that the memory doesn't get corrupted.

Re:Don't setenv in multi-threaded code on glibc by tedunangst on Tuesday January 31, 2017 @10:36AM (#13531401)
The posix standard explicitly says setenv is not thread safe. This shouldn't be a mystery.
Re:Don't setenv in multi-threaded code on glibc by masklinn on Tuesday January 31, 2017 @01:45PM (#13533793)
Isn't the issue here that setenv breaks getenv rather than setenv "not being thread-safe"?
Re:Don't setenv in multi-threaded code on glibc by quotemstr on Tuesday January 31, 2017 @02:44PM (#13534478)
The issue is that getenv's API is fundamentally unsafe. setenv is fine.
Re:Don't setenv in multi-threaded code on glibc by quotemstr on Tuesday January 31, 2017 @01:12PM (#13533406)
But it should be. And we can make it thread safe very easily. Why the hell should we be limited by POSIX? Why can't we provide features beyond it?

It's access to the environ global that's inherently unsafe. setenv and a modified getenv can be accommodated just fine.

Re:Don't setenv in multi-threaded code on glibc by pjmlp on Tuesday January 31, 2017 @03:09PM (#13534720)
Portability across UNIX platforms.
Re:Don't setenv in multi-threaded code on glibc by quotemstr on Tuesday January 31, 2017 @03:36PM (#13534946)
So portability to you, means that the platform can't add features? I reject portability then.
Re:Don't setenv in multi-threaded code on glibc by pjmlp on Tuesday January 31, 2017 @05:05PM (#13535715)
To me? No, to everyone.

Lets say GNU/Linux does that, what you would do for other UNIX flavours, #ifdef soup?

The goal of standards is exactly to minimize that.

Re:Don't setenv in multi-threaded code on glibc by quotemstr on Tuesday January 31, 2017 @05:25PM (#13535901)
Ifdefs would be required. Or some kind of wrapper in gnulib. Or, like systemd, just non-portability. Your philosophy means stagnation forever. I reject that. Programs that use getenv today will not break. Objection to the existence of a getenv_s is absurd.

The only way we move forward is by trying new things, and we can't possibly get everyone to try a new thing all at once. If the thing ends up being useful, we standardize it.

Re:Don't setenv in multi-threaded code on glibc by pjmlp on Tuesday January 31, 2017 @12:56PM (#13533219)
Back when I cared about POSIX (early 2000's) the difference between what POSIX stated and what UNIX systems offered wasn't always the same.

I guess the situation might have improved.

Re:Don't setenv in multi-threaded code on glibc by JdeBP on Wednesday February 01, 2017 @06:24AM (#13539864)
Actually, it says that it need not be thread-safe. It does not prohibit a good implementation from making it thread-safe anyway.