On Sun, Feb 02, 2020 at 04:20:13PM -0700, Theo de Raadt wrote: Hello Theo,
> What is the difference between storage and contents You can't free() the backing memory *and* (according to GNU's man page, at least) you can't safely change the string contents either on some OSs. I've tried something slightly lengthier in the patch below. > (actually contents could change. As long as there is always a terminating > NUL, for the purpose of traversal. But that's not something someone should > code to) > > You still didn't say how you ran into this. While writing a daemon in Rust, I discovered that, AFAICT, one doesn't have sensible access to __progname and has to figure out the executable name dynamically (AFAICT), so it ends up in malloc'd storage. When I passed that to openlog, and later called syslog, well, I was confused. I then distilled the example down to C. The Debian & GNU man pages suggest that I'm not the first person to try doing this. Laurie Index: syslog.3 =================================================================== RCS file: /cvs/src/lib/libc/gen/syslog.3,v retrieving revision 1.35 diff -u -r1.35 syslog.3 --- syslog.3 30 Aug 2019 20:27:25 -0000 1.35 +++ syslog.3 2 Feb 2020 23:32:50 -0000 @@ -216,7 +216,9 @@ .Fn vsyslog . The parameter .Fa ident -is a string that will be prepended to every message. +is a string that will be prepended to every message; the memory pointed to +must remain valid, and the string's contents unchanged, until +.Fn closelog . The .Fa logopt argument