Page MenuHomeFreeBSD

libc: Add getenv_r() function.
ClosedPublic

Authored by des on Apr 23 2025, 12:23 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Aug 13, 2:36 AM
Unknown Object (File)
Sat, Aug 9, 9:06 AM
Unknown Object (File)
Wed, Aug 6, 10:04 PM
Unknown Object (File)
Sat, Aug 2, 1:49 AM
Unknown Object (File)
Sat, Jul 26, 9:33 PM
Unknown Object (File)
Jul 6 2025, 9:40 AM
Unknown Object (File)
Jul 5 2025, 10:40 AM
Unknown Object (File)
Jul 4 2025, 12:09 PM

Details

Summary

This is a calque of the NetBSD function of the same name.

MFC after: never
Relontes: yes
Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 63668
Build 60552: arc lint + arc unit

Event Timeline

des requested review of this revision.Apr 23 2025, 12:23 PM
kevans added a subscriber: kevans.

If you're up for it, adding _FORTIFY_SOURCE support for this would be nearly trivial. The __ssp_redirect pattern for arc4random_buf in include/ssp/stdlib.h can be copied for this (the __buf and __len names are significant and used in the implementation for size-checking, other names are fair game) and tests added easily by copying arc4random_buf again in lib/libc/tests/secure/generate-fortify-tests.lua (regeneration requires devel/lua-luacheck for make generate-tests).

This revision is now accepted and ready to land.Apr 23 2025, 12:52 PM
markj added inline comments.
lib/libc/stdlib/getenv.c
475

Wouldn't it be more useful to somehow return the actual size of the variable? Userspace effectively has to guess and just double the size until getenv_r() succeeds.

lib/libc/stdlib/getenv.c
475

Worse, we copy to the buffer and return an error....

lib/libc/stdlib/getenv.c
475

I'm afraid there's 20 years of precedent for this. I'm loath to break that, even if we're the first outside NetBSD to adopt it.

This revision now requires review to proceed.Apr 24 2025, 12:33 PM
This revision is now accepted and ready to land.Apr 24 2025, 6:22 PM
This revision was automatically updated to reflect the committed changes.