libc: rewrite putenv and getenv.

These new implementations

- do several validity check on input parameters
- allow a bit larger variable names (127 bytes, aka sizeof(Proc.genbuf)-1)
- preserve nulls in the content (the original version used to replace
  '\0' with ' '). I can't see why they did, actually.
  See also http://marc.info/?l=9fans&m=148475801229908&w=2

Should also fix CID 155718
This commit is contained in:
2017-01-19 00:58:43 +01:00
parent d43be3861b
commit 65cdad4317
6 changed files with 118 additions and 58 deletions

View File

@@ -8,6 +8,9 @@
"-std=gnu11"
],
"Install": "/arch/$ARCH/qa/lib/c",
"Post": [
"cp *.rc $JEHANNE/arch/$ARCH/qa/lib/c/"
],
"SourceFilesCmd": [
"asmscall.c",
"cleanname.c",

28
qa/lib/c/env.rc Executable file
View File

@@ -0,0 +1,28 @@
#!/cmd/rc
# verify that environment variables can have names 127 byte long
# why 127? because it's the size of genbuf in the kernel's Proc structure
# minus the ending \0
abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef012345678=10
if ( ! ~ $abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef012345678 10 ) {
echo FAIL: cannot read an environment variable with a long name
exit FAIL
}
# verify that rc lists work
list=(How now brown cow)
string=$"list
if( ! ~ $#list 4 ) {
echo FAIL: list count does not work on a 4 elements list
exit FAIL
}
if( ! ~ $#string 1 ) {
echo FAIL: list count does not work on a single string
exit FAIL
}
echo PASS
exit PASS