Page MenuHomeFreeBSD

libc: Add getenv_r() function.
AcceptedPublic

Authored by des on Wed, Apr 23, 12:23 PM.
Tags
None
Referenced Files
F115509669: D49979.diff
Thu, Apr 24, 3:42 PM
F115449757: D49979.id.diff
Wed, Apr 23, 11:27 PM
Unknown Object (File)
Wed, Apr 23, 5:16 PM
Unknown Object (File)
Wed, Apr 23, 4:41 PM
Unknown Object (File)
Wed, Apr 23, 4:39 PM
Unknown Object (File)
Wed, Apr 23, 4:09 PM
Unknown Object (File)
Wed, Apr 23, 4:08 PM

Details

Reviewers
kevans
Group Reviewers
Klara
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 63697
Build 60581: arc lint + arc unit

Event Timeline

des requested review of this revision.Wed, Apr 23, 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.Wed, Apr 23, 12:52 PM
markj added inline comments.
lib/libc/stdlib/getenv.c
476

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
476

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

lib/libc/stdlib/getenv.c
476

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.Thu, Apr 24, 12:33 PM
This revision is now accepted and ready to land.Thu, Apr 24, 6:22 PM