Consolidated pseudo patches
cover Consolidated pseudo patches
This is the full set of pending changes. Many of which have already been sent to the mailing list. This set matches 'fray/master' branch in the repository.
The new features in this set include:
* Test harness improvements (better display, more robust)
* Realpath POSIX fix from Gauthier HADERER
* Linux path traversal into /proc fixes
* General cleanup
This along with the other changes that have recently gone in should get us to 1.9.3 or even 2.0.0.
Note: the test suite still shows there are problems with parallel rename and symlink operations. These are reported but we don't have any sort of a fix in mind yet.
renameat2 is not implemented, this will require potentially extensive changes to pseudo to allow for atomic exchange (rename). It will return ENOSYS until then.
openat2 is not implemented, a prototype version of this code was created, but does not yet pass testing. This also returns ENOSYS.
Gauthier HADERER (1):
ports/unix/guts/realpath.c: realpath fails if the resolved path
doesn't exist
Mark Hatle (19):
test-syscall: Remove build warning
test: Cleanup test output
test/test-statx.sh: It should be a failure if pseudo prints an error
test-realpath: Verify the realpath behavior matches glibc run_tests.sh: In verbose mode, include pseudo.log in output test/test-statx: Add uutils test case
test/test-nftw: Avoid compile warnings
test-tclsh-fork: Skip test if tclsh is not available test/test-proc-pipe.sh: Add test case for proc pipes pseudo_util.c: Skip realpath like expansion for /proc on Linux ports/unix/guts/realpath.c: Fix indents ports/linux/pseudo_wrappers.c: Reorder the syscall operations ports/linux/pseudo_wrappers.c: Call the wrappers where possible ports/linux: Add additional EFAULTS for Linux functions Update COPYRIGHT files
makewrappers: improve error handling and robustness
pseudo: code quality scan - resolved various potential issues
configure: Minor code quality changes
Makefile.in: Bump version to 1.9.3
ChangeLog.txt | 4 + Makefile.in | 5 +- configure | 19 ++-- guts/COPYRIGHT | 2 + makewrappers | 73 ++++++++------- ports/darwin/guts/COPYRIGHT | 1 + ports/linux/guts/COPYRIGHT | 2 + ports/linux/openat2/wrapfuncs.in | 2 +- ports/linux/pseudo_wrappers.c | 46 ++++++---- ports/linux/wrapfuncs.in | 22 ++--- ports/linux/xattr/wrapfuncs.in | 16 ++-- ports/uids_generic/guts/COPYRIGHT | 1 + ports/unix/guts/COPYRIGHT | 2 + ports/unix/guts/fts_open.c | 5 +- ports/unix/guts/nftw_wrapper_base.c | 11 +-- ports/unix/guts/realpath.c | 23 +++-- pseudo.c | 61 ++++++++----- pseudo_client.c | 4 + pseudo_db.c | 10 +++ pseudo_server.c | 14 +++ pseudo_util.c | 132 +++++++++++++++++++++++----- run_tests.sh | 28 ++++-- test/nftw-test-impl.c | 2 + test/test-acl.sh | 16 ++++ test/test-proc-pipe.sh | 27 ++++++ test/test-realpath.c | 17 ++++ test/test-realpath.sh | 63 +++++++++++++ test/test-statx.sh | 39 +++++++- test/test-syscall.c | 2 +- test/test-tclsh-fork.sh | 5 ++ test/test-xattr.sh | 17 ++++ 31 files changed, 525 insertions(+), 146 deletions(-) create mode 100755 test/test-proc-pipe.sh create mode 100644 test/test-realpath.c create mode 100755 test/test-realpath.sh
Signature · 1 line
2.43.0
PATCH 1/20 test-syscall: Remove build warning
Compiler is warning about argc and argv not being used.
--- test/test-syscall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
test/test-syscall.c +1 -1
@@ -11,7 +11,7 @@#include <string.h> #include <errno.h> -int main (int argc,char *argv[]) { +int main () {long rc =0 ;#ifdef SYS_renameat2
Signature · 1 line
2.43.0
PATCH 2/20 test: Cleanup test output
In reply to Mark HatleChange 'make test' to be simple test results.
Add new 'make test-verbose' for verbose results.
Adjust the run_test.sh to capture logs and only output when in verbose mode. Also capture failure and skip counts. (rc of 255 indicates test was skipped.)
Adjust test cases to indicate skipped tests when a command is unavailable.
--- Makefile.in | 3 +++ run_tests.sh | 24 +++++++++++++++++++----- test/test-acl.sh | 16 ++++++++++++++++ test/test-xattr.sh | 17 +++++++++++++++++ 4 files changed, 55 insertions(+), 5 deletions(-)
Makefile.in +3 -0
@@ -76,6 +76,9 @@ TABLES=table_templates/pseudo_tables.c table_templates/pseudo_tables.h all: $(LIBPSEUDO) $(PSEUDO) $(PSEUDODB) $(PSEUDOLOG) $(PSEUDO_PROFILE) test: all $(TESTS) | $(BIN) $(LIB) + ./run_tests.sh + +test-verbose: all $(TESTS) | $(BIN) $(LIB) ./run_tests.sh -v test/test-%: test/test-%.c
run_tests.sh +19 -5
@@ -31,22 +31,36 @@ export PSEUDO_PREFIX=${PWD} num_tests=0 num_passed_tests=0 +num_skipped_tests=0 +num_failed_tests=0 + +tmplog="$(mktemp pseudo.log.XXXXXXXX)" for file in test/test*.sh do filename=${file#test/} let num_tests++ mkdir -p var/pseudo - ./bin/pseudo $file ${opt_verbose} - if [ "$?" -eq "0" ]; then + ./bin/pseudo $file ${opt_verbose} >${tmplog} 2>&1 + rc=$? + if [ "${opt_verbose}" = "-v" ]; then + echo + cat ${tmplog} + fi + if [ "$rc" -eq "0" ]; then let num_passed_tests++ - if [ "${opt_verbose}" == "-v" ]; then - echo "${filename%.sh}: Passed." - fi + echo "${filename%.sh}: Passed." + elif [ "$rc" -eq "255" ]; then + let num_skipped_tests++ + echo "${filename%.sh}: Skipped." else + let num_failed_tests++ echo "${filename/%.sh}: Failed." fi rm -rf var/pseudo/* done +echo "${num_failed_tests}/${num_tests} test(s) failed." +echo "${num_skipped_tests}/${num_tests} test(s) skipped." echo "${num_passed_tests}/${num_tests} test(s) passed." +rm ${tmplog}
test/test-acl.sh +16 -0
@@ -6,11 +6,27 @@ # Return vals: 2 - Unable to run ACL commands, assertion failure # 1 - Invalid return value # 0 - Pass +# 255 - acl programs unavailable, skip # NOTE: these test exclusively test setfacl -m set -u +rc=0 +which getfacl 2>/dev/null +if [ $? -ne 0 ]; then + echo "getfacl command missing" + rc=255 +fi +which setfacl 2>/dev/null +if [ $? -ne 0 ]; then + echo "setfacl command missing" + rc=255 +fi +if [ $rc -ne 0 ]; then + exit $rc +fi + check_owner () { local file="$1" local expected="$2"
test/test-xattr.sh +17 -0
@@ -7,6 +7,23 @@ # 1 - Invalid return value # 0 - Pass +set -u + +rc=0 +which getfattr 2>/dev/null +if [ $? -ne 0 ]; then + echo "getfattr command missing" + rc=255 +fi +which setfattr 2>/dev/null +if [ $? -ne 0 ]; then + echo "setfattr command missing" + rc=255 +fi +if [ $rc -ne 0 ]; then + exit $rc +fi + touch f1 attrs=`getfattr -d f1 | grep -v '^#'` if [ -n "$attrs" ]
Signature · 1 line
2.43.0
PATCH 3/20 test/test-statx.sh: It should be a failure if pseudo prints an error
In reply to Mark HatleCapture the output and compare to a know error message, error if the null message is present.
This is currently a known failure, reported in Yocto Project bug 16075.
--- test/test-statx.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
test/test-statx.sh +13 -1
@@ -3,4 +3,16 @@ # SPDX-License-Identifier: LGPL-2.1-only # -exec ./test/test-statx +tmplog="$(mktemp pseudo.log.XXXXXXXX)" +./test/test-statx >${tmplog} 2>&1 +rc=$? + +if grep -q "couldn't allocate absolute path for 'null'." ${tmplog} ; then + echo "Unexpected message: \"couldn't allocate absolute path for 'null'.\" found." + rc=1 +fi + +cat ${tmplog} + +rm $tmplog +exit $rc
Signature · 1 line
2.43.0
PATCH 4/20 test-realpath: Verify the realpath behavior matches glibc
In reply to Mark HatleGauthier HADERER reported that the realpath implementation could return the wrong value.
Create a test-case to attempt to verify realpath behavior.
--- test/test-realpath.c | 17 ++++++++++++ test/test-realpath.sh | 63 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 test/test-realpath.c create mode 100755 test/test-realpath.sh
test/test-realpath.c new file +17 -0
@@ -0,0 +1,17 @@ +/* Code contributed by Gauthier HADERER via lists.yoctoproject.org */ + +#include <limits.h> +#include <stdlib.h> +#include <stdio.h> +int main (int argc,char **argv) { +if (argc !=2 ) +return 2 ; +char *rpath =realpath (argv[1 ],NULL ); +if (!rpath) { +perror ("realpath" ); +return 1 ; + } +printf ("%s\n" , rpath); +free (rpath); +return 0 ; +}
test/test-realpath.sh new file +63 -0
63 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 5/20 run_tests.sh: In verbose mode, include pseudo.log in output
In reply to Mark Hatle--- run_tests.sh | 4 ++++ 1 file changed, 4 insertions(+)
run_tests.sh +4 -0
@@ -46,6 +46,10 @@ do if [ "${opt_verbose}" = "-v" ]; then echo cat ${tmplog} + if [ $rc -ne 0 -a $rc -ne 255 ]; then + # Include the contents of the pseudo.log before we delete it + cat var/pseudo/pseudo.log + fi fi if [ "$rc" -eq "0" ]; then let num_passed_tests++
Signature · 1 line
2.43.0
PATCH 6/20 test/test-statx: Add uutils test case
In reply to Mark Hatle--- test/test-statx.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
test/test-statx.sh +25 -0
@@ -3,6 +3,7 @@ # SPDX-License-Identifier: LGPL-2.1-only # +printf "statx null path: " tmplog="$(mktemp pseudo.log.XXXXXXXX)" ./test/test-statx >${tmplog} 2>&1 rc=$?
@@ -10,9 +11,33 @@ rc=$? if grep -q "couldn't allocate absolute path for 'null'." ${tmplog} ; then echo "Unexpected message: \"couldn't allocate absolute path for 'null'.\" found." rc=1 +else + echo "passed" fi cat ${tmplog} rm $tmplog + +printf "uutils date: " +# Try to figure out if we're using rust corutils +if $(date --version 2>&1 | grep -q "uutils") ; then + tmplog="$(mktemp pseudo.log.XXXXXXXX)" + date >${tmplog} 2>&1 + rc=$? + + if grep -q "couldn't allocate absolute path for 'null'." ${tmplog} ; then + echo "Unexpected message: \"couldn't allocate absolute path for 'null'.\" found." + rc=1 + else + echo passed + fi + + cat ${tmplog} + + rm $tmplog +else + echo skipped +fi + exit $rc
Signature · 1 line
2.43.0
PATCH 7/20 test/test-nftw: Avoid compile warnings
In reply to Mark Hatle--- test/nftw-test-impl.c | 2 ++ 1 file changed, 2 insertions(+)
test/nftw-test-impl.c +2 -0
@@ -41,6 +41,8 @@ char* get_absolute_path(const char* fpath) { }static int callback (const char * fpath,const struct NFTW_STAT_STRUCT *sb,int typeflag,struct FTW *ftwbuf){ + (void ) ftwbuf; +if (print_filename) {char * filepath =get_absolute_path (fpath);printf ("%s\n" , filepath);
Signature · 1 line
2.43.0
PATCH 8/20 test-tclsh-fork: Skip test if tclsh is not available
In reply to Mark Hatle--- test/test-tclsh-fork.sh | 5 +++++ 1 file changed, 5 insertions(+)
test/test-tclsh-fork.sh +5 -0
@@ -3,6 +3,11 @@ # SPDX-License-Identifier: LGPL-2.1-only # +which tclsh >/dev/null 2>&1 +if [ $? -ne 0 ]; then + exit 255 +fi + # Check that tclsh doesn't hang. Note that the timeout is not needed to # reproduce the hang in tclsh, it's only there to ensure that this test script # doesn't hang in case of a failing test.
Signature · 1 line
2.43.0
PATCH 9/20 ports/unix/guts/realpath.c: realpath fails if the resolved path doesn't exist
In reply to Mark HatleFrom: Gauthier HADERER <[email protected]>
The pseudo implementation of `realpath()' may return a path which doesn't exist. This is not POSIX compliant and causes troubles with uutils (coreutils in Rust).
For example, the tail commands tries to determine the file path of its standard input file descriptor by calling realpath("/dev/fd/0")'. When the input is a pipe, the GNU C library returns NULL but pseudo returns /proc/<pid>/fd/pipe:[xxxxxx]'. As it got a path, the tail command tries to open it and fails.
--- ports/unix/guts/realpath.c | 9 +++++++++ 1 file changed, 9 insertions(+)
ports/unix/guts/realpath.c +9 -0
@@ -14,6 +14,15 @@ errno =ENAMETOOLONG ;return NULL ; } + +/* We must fail if the target path doesn't exist. */ +PSEUDO_STATBUF buf; + +if (base_lstat (rname, &buf) ==-1 ) { + errno =EINVAL ; +return NULL ; + } + len =strlen (rname);char *ep = rname + len -1 ;while (ep > rname && *ep =='/' ) {
Signature · 1 line
2.43.0
PATCH 10/20 test/test-proc-pipe.sh: Add test case for proc pipes
In reply to Mark HatleFrom: Mark Hatle <[email protected]>
See: Yocto Project bugzilla 16028, comment #23.
This is related to both statx and realpath behavior.
Gauthier HADERER (see comment 23) reported an issue where realpath like behavior of pseudo_fix_path function resulted in a failure of the rust based tail command.
It was determined that the behavior could be emulated by doing:
echo "test" | tail /dev/fd/0
(tail, cat or any other similar command would result in the same failure)
This results in:
/dev/fd/0 -> /proc/self/fd/0
/proc/self/fd/0 -> /proc/1475524/fd/0 /proc/1475524/fd/0 -> /proc/1475524/fd/pipe:[1177004485]
with an eventual failure of unable to open /proc/1475524/fd/pipe:[1177004485]
--- test/test-proc-pipe.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 test/test-proc-pipe.sh
test/test-proc-pipe.sh new file +27 -0
@@ -0,0 +1,27 @@ +#!/bin/bash +# +# SPDX-License-Identifier: LGPL-2.1-only +# +# See Yocto Project bugzilla 16028 +# +# It was determined that a utility that use /dev/fd may fail when run under +# pseudo, while working properly outside. +# +# For example: echo "test" | cat /dev/fd/0 + +# Tests +result=$(echo "test" | cat 2>&1) +rc=$? +if [ $rc -ne 0 -o "$result" != "test" ]; then + echo Failed simple echo pipe test - $rc: + echo $result + exit 1 +fi + +result=$(echo "test" | cat /dev/fd/0 2>&1) +rc=$? +if [ $rc -ne 0 -o "$result" != "test" ]; then + echo Failed /dev/fd/0 echo pipe test - $rc: + echo $result + exit 1 +fi
Signature · 1 line
2.43.0
PATCH 11/20 pseudo_util.c: Skip realpath like expansion for /proc on Linux
In reply to Mark HatleFrom: Mark Hatle <[email protected]>
See: Yocto Project bugzilla 16028
Gauthier HADERER (see comment 23) reported an issue where realpath like behavior of pseudo_fix_path function resulted in a failure of the rust based tail command.
It was determined that the behavior could be emulated by doing:
echo "test" | tail /dev/fd/0
(tail, cat or any other similar command would result in the same failure)
This results in:
/dev/fd/0 -> /proc/self/fd/0
/proc/self/fd/0 -> /proc/1475524/fd/0 /proc/1475524/fd/0 -> /proc/1475524/fd/pipe:[1177004485]
with an eventual failure of unable to open /proc/1475524/fd/pipe:[1177004485]
This change resolves the issue by detecting the path has been resolved into the /proc filesystem and then check link targets until it finds one that does not resolve. It stops at that points. This ensures that special /proc behavior can be maintained.
In the /proc filesystem, on Linux, paths can be opened even if they can't be stated. The 'pipe' appears to be one of these special files, so using lstat to check if it can be opened is an easy way to determine if we have stumbled onto one of these special files.
--- pseudo_util.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+)
pseudo_util.c +68 -0
@@ -614,12 +614,40 @@ pseudo_append_element(char *newpath, char *root, size_t allocated, char **pcurresize_t curlen;int is_dir =S_ISDIR (buf->st_mode);char *current; +#ifdef PSEUDO_PORT_LINUX +int is_proc =0 ; +char *proc_path =NULL ; +#endif if (!newpath || !pcurrent || !*pcurrent || !root || !element) {pseudo_diag ("pseudo_append_element: invalid args.\n" );return -1 ; } + +#ifdef PSEUDO_PORT_LINUX +/* If we end up resolving a path into /proc, it has special meaning. +* For instance, /dev/fd/0 -> /proc/self/fd/0 -> +* /proc/1475524/fd/0 -> /proc/1475524/fd/pipe:[1177004485] +* Trying to access the resolved name "pipe:[....]" may fail. +* +* We verify each link target and only expand if it exists. +*/ +if (strncmp (newpath,"/proc/" ,6 ) ==0 ) { +pseudo_debug (PDBGF_PATH |PDBGF_VERBOSE ,"paes: %s in /proc\n" , + newpath ? newpath :"<nil>" ); +/* Store off the path for later */ + proc_path =strdup (newpath); +/* If memory can't be allocated for newpath, +* fall through and do standard processing +*/ +if (!proc_path) +pseudo_diag ("allocation failed seeking memory for path (%s).\n" , newpath); +else + is_proc =1 ; + } +#endif + current = *pcurrent;pseudo_debug (PDBGF_PATH |PDBGF_VERBOSE ,"pae: '%s', + '%.*s', is_dir %d\n" , newpath, (int ) elen, element, is_dir);
@@ -700,6 +728,33 @@ pseudo_append_element(char *newpath, char *root, size_t allocated, char **pcurreif (*linkbuf =='/' ) { current = root; }else { +#ifdef PSEUDO_PORT_LINUX +if (is_proc) { +/* Check that the link target exists, otherwise stop resolving since /proc is special! */ +PSEUDO_STATBUF statbuf; + +size_t target_link_max =pseudo_path_max (); +char *target_link_path =malloc (pseudo_path_max ()); + +if (!target_link_path) +pseudo_diag ("allocation failed seeking memory for path (%s/%s).\n" , proc_path, linkbuf); +/* Fall through, nothing we can do here */ +else { +snprintf (target_link_path, target_link_max,"%s/%s" , proc_path, linkbuf); + +if (!pseudo_real_lstat || (pseudo_real_lstat (target_link_path, &statbuf) ==-1 )) { +pseudo_debug (PDBGF_PATH ,"proc link (%s) target (%s) does not exist, skipping.\n" , newpath, target_link_path); +free (target_link_path); +free (proc_path); + *pcurrent = current; +return 1 ; + }else +pseudo_debug (PDBGF_PATH ,"proc link (%s) target (%s) exists.\n" , newpath, target_link_path); + +free (target_link_path); + } + } +#endif /* point back at the end of the previous path... */ current -= (elen +1 ); }
@@ -716,13 +771,26 @@ pseudo_append_element(char *newpath, char *root, size_t allocated, char **pcurre ++link_recursion; retval =pseudo_append_elements (newpath, root, allocated, pcurrent, linkbuf, linklen,0 , buf); --link_recursion; + +#ifdef PSEUDO_PORT_LINUX +if (is_proc) +free (proc_path); +#endif +return retval; } } +/* we used to always append a slash here. now we don't; append_elements * handles slashes, so just update the pointer. */ *pcurrent = current; + +#ifdef PSEUDO_PORT_LINUX +/* We must not have used this to get here... */ +if (is_proc) +free (proc_path); +#endif return 1 ; }
Signature · 1 line
2.43.0
PATCH 12/20 ports/unix/guts/realpath.c: Fix indents
In reply to Mark Hatle--- ports/unix/guts/realpath.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
ports/unix/guts/realpath.c +7 -7
@@ -23,14 +23,14 @@return NULL ; } - len =strlen (rname); -char *ep = rname + len -1 ; -while (ep > rname && *ep =='/' ) { - --len; - *(ep--) ='\0' ; - } + len =strlen (rname); +char *ep = rname + len -1 ; +while (ep > rname && *ep =='/' ) { + --len; + *(ep--) ='\0' ; + } -if (len >=pseudo_sys_path_max ()) { +if (len >=pseudo_sys_path_max ()) { errno =ENAMETOOLONG ;return NULL ; }
Signature · 1 line
2.43.0
PATCH 13/20 ports/linux/pseudo_wrappers.c: Reorder the syscall operations
In reply to Mark HatleThe seccomp wrap always takes effect when pseudo is running, this will prevent various behavior, even if pseudo is generally considered to be disabled, but in memory.
The openat2 and renameat2 however should only run if pseudo is enabled.
--- ports/linux/pseudo_wrappers.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
ports/linux/pseudo_wrappers.c +16 -13
@@ -65,19 +65,6 @@ syscall(long number, ...) {return rc; } -#ifdef SYS_renameat2 -/* concerns exist about trying to parse arguments because syscall(2) -* specifies strange ABI behaviors. If we can get better clarity on -* that, it could make sense to redirect to wrap_renameat2(). -*/ -if (number == SYS_renameat2) { - errno =ENOSYS ; -return -1 ; - } -#else - (void ) number; -#endif -#ifdef SYS_seccomp/* pseudo and seccomp are incompatible as pseudo uses different syscalls * so pretend to enable seccomp but really do nothing */
@@ -92,6 +79,10 @@ syscall(long number, ...) { }#endif +if (pseudo_disabled) { + goto call_syscall; + } +#ifdef SYS_openat2/* concerns exist about trying to parse arguments because syscall(2) * specifies strange ABI behaviors. If we can get better clarity on
@@ -105,6 +96,18 @@ syscall(long number, ...) { }#endif +#ifdef SYS_renameat2 +/* concerns exist about trying to parse arguments because syscall(2) +* specifies strange ABI behaviors. If we can get better clarity on +* that, it could make sense to redirect to wrap_renameat2(). +*/ +if (number == SYS_renameat2) { + errno =ENOSYS ; +return -1 ; + } +#endif + +call_syscall:/* gcc magic to attempt to just pass these args to syscall. we have to * guess about the number of args; the docs discuss calling conventions * up to 7, so let's try that?
Signature · 1 line
2.43.0
PATCH 14/20 ports/linux/pseudo_wrappers.c: Call the wrappers where possible
In reply to Mark HatleUsing va args, call the wrapper when the syscall is invoked. This will allow us to implement the renameat2 and openat2 functions in the future while keeping the syscall work unchanged.
The syscall -> wrappers should continue to be sparse into things we know are outliers, as this could result in some maintenance work keeping the argument processing sane.
--- ports/linux/pseudo_wrappers.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
ports/linux/pseudo_wrappers.c +17 -12
@@ -84,26 +84,31 @@ syscall(long number, ...) { }#ifdef SYS_openat2 -/* concerns exist about trying to parse arguments because syscall(2) -* specifies strange ABI behaviors. If we can get better clarity on -* that, it could make sense to redirect to wrap_openat2(). -* There is a CVE patch (CVE-2025-45582) to tar 1.34 in Centos Stream which +/* There is a CVE patch (CVE-2025-45582) to tar 1.34 in Centos Stream which * uses syscall to access openat2() and breaks builds if we don't redirect. */ if (number == SYS_openat2) { - errno =ENOSYS ; -return -1 ; +va_start (ap, number); +int dirfd =va_arg (ap, int); + const char * path = va_arg(ap, const char *); + void *how = va_arg(ap, void *); +size_t size =va_arg (ap, size_t); + +return wrap_openat2 (dirfd, path, how, size); }#endif #ifdef SYS_renameat2 -/* concerns exist about trying to parse arguments because syscall(2) -* specifies strange ABI behaviors. If we can get better clarity on -* that, it could make sense to redirect to wrap_renameat2(). -*/ +/* Call out wrapper, expanding the variable arguments first */ if (number == SYS_renameat2) { - errno =ENOSYS ; -return -1 ; +va_start (ap, number); +int olddirfd =va_arg (ap, int); + const char * oldpath = va_arg(ap, const char *); +int newdirfd =va_arg (ap, int); + const char * newpath = va_arg(ap, const char *); + unsigned int flags = va_arg(ap, unsigned int); + +return wrap_renameat2 (olddirfd, oldpath, newdirfd, newpath, flags); }#endif
Signature · 1 line
2.43.0
PATCH 15/20 ports/linux: Add additional EFAULTS for Linux functions
In reply to Mark HatleNote, other functions claim to return EFAULT when the path element is NULL, however glibc has these parameters tagged as non-null which optimizes out any sort of NULL test by default. Due to this only items that don't error were included.
--- ports/linux/openat2/wrapfuncs.in | 2 +- ports/linux/wrapfuncs.in | 22 +++++++++++----------- ports/linux/xattr/wrapfuncs.in | 16 ++++++++-------- 3 files changed, 20 insertions(+), 20 deletions(-)
ports/linux/openat2/wrapfuncs.in +1 -1
@@ -1 +1 @@ -int openat2(int dirfd, const char *path, struct open_how *how, size_t size); +int openat2(int dirfd, const char *path, struct open_how *how, size_t size); /* efault=path */
ports/linux/wrapfuncs.in +11 -11
@@ -1,17 +1,17 @@ int open(const char *path, int flags, ...{mode_t mode}); /* flags=((flags&O_NOFOLLOW)||((flags&(O_CREAT|O_EXCL))==(O_CREAT|O_EXCL))), noignore_path=1 */ char *get_current_dir_name(void); -int __xstat(int ver, const char *path, struct stat *buf); -int __lxstat(int ver, const char *path, struct stat *buf); /* flags=AT_SYMLINK_NOFOLLOW */ +int __xstat(int ver, const char *path, struct stat *buf); /* efault=path */ +int __lxstat(int ver, const char *path, struct stat *buf); /* flags=AT_SYMLINK_NOFOLLOW, efault=path */ int __fxstat(int ver, int fd, struct stat *buf); int lchmod(const char *path, mode_t mode); /* flags=AT_SYMLINK_NOFOLLOW */ int lchown(const char *path, uid_t owner, gid_t group); /* flags=AT_SYMLINK_NOFOLLOW */ -int __fxstatat(int ver, int dirfd, const char *path, struct stat *buf, int flags); +int __fxstatat(int ver, int dirfd, const char *path, struct stat *buf, int flags); /* efault=path */ int openat(int dirfd, const char *path, int flags, ...{mode_t mode}); /* flags=((flags&O_NOFOLLOW)||((flags&(O_CREAT|O_EXCL))==(O_CREAT|O_EXCL))), noignore_path=1 */ int __openat_2(int dirfd, const char *path, int flags); /* flags=((flags&O_NOFOLLOW)||((flags&(O_CREAT|O_EXCL))==(O_CREAT|O_EXCL))), noignore_path=1 */ int mknod(const char *path, mode_t mode, dev_t dev); /* real_func=pseudo_mknod */ int mknodat(int dirfd, const char *path, mode_t mode, dev_t dev); /* real_func=pseudo_mknodat */ -int __xmknod(int ver, const char *path, mode_t mode, dev_t *dev); /* flags=AT_SYMLINK_NOFOLLOW */ -int __xmknodat(int ver, int dirfd, const char *path, mode_t mode, dev_t *dev); /* flags=AT_SYMLINK_NOFOLLOW */ +int __xmknod(int ver, const char *path, mode_t mode, dev_t *dev); /* flags=AT_SYMLINK_NOFOLLOW, efault=path */ +int __xmknodat(int ver, int dirfd, const char *path, mode_t mode, dev_t *dev); /* flags=AT_SYMLINK_NOFOLLOW, efault=path */ int fcntl(int fd, int cmd, ...{struct flock *lock}); /* noignore_path=1 */ int fcntl64(int fd, int cmd, ...{struct flock *lock}); /* noignore_path=1 */ # just so we know the inums of symlinks
@@ -24,15 +24,15 @@ int creat64(const char *path, mode_t mode); int stat(const char *path, struct stat *buf); /* real_func=pseudo_stat */ int lstat(const char *path, struct stat *buf); /* real_func=pseudo_lstat, flags=AT_SYMLINK_NOFOLLOW */ int fstat(int fd, struct stat *buf); /* real_func=pseudo_fstat */ -int fstatat(int dirfd, const char *path, struct stat *buf, int flags); +int fstatat(int dirfd, const char *path, struct stat *buf, int flags); /* efault=path */ int stat64(const char *path, struct stat64 *buf); /* real_func=pseudo_stat64 */ int lstat64(const char *path, struct stat64 *buf); /* real_func=pseudo_lstat64, flags=AT_SYMLINK_NOFOLLOW */ int fstat64(int fd, struct stat64 *buf); /* real_func=pseudo_fstat64 */ -int fstatat64(int dirfd, const char *path, struct stat64 *buf, int flags); -int __xstat64(int ver, const char *path, struct stat64 *buf); -int __lxstat64(int ver, const char *path, struct stat64 *buf); /* flags=AT_SYMLINK_NOFOLLOW */ +int fstatat64(int dirfd, const char *path, struct stat64 *buf, int flags); /* efault=path */ +int __xstat64(int ver, const char *path, struct stat64 *buf); /* efault=path */ +int __lxstat64(int ver, const char *path, struct stat64 *buf); /* flags=AT_SYMLINK_NOFOLLOW, efault=path */ int __fxstat64(int ver, int fd, struct stat64 *buf); -int __fxstatat64(int ver, int dirfd, const char *path, struct stat64 *buf, int flags); +int __fxstatat64(int ver, int dirfd, const char *path, struct stat64 *buf, int flags); /* efault=path */ FILE *fopen64(const char *path, const char *mode); /* noignore_path=1 */ int nftw64(const char *path, int (*fn)(const char *, const struct stat64 *, int, struct FTW *), int nopenfd, int flag); /* noignore_path=1 */ FILE *freopen64(const char *path, const char *mode, FILE *stream); /* noignore_path=1 */
@@ -61,7 +61,7 @@ int getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **p int getgrent_r(struct group *gbuf, char *buf, size_t buflen, struct group **gbufp); int capset(cap_user_header_t hdrp, const cap_user_data_t datap); /* real_func=pseudo_capset */ long syscall(long nr, ...); /* hand_wrapped=1 */ -int renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags); /* flags=AT_SYMLINK_NOFOLLOW */ +int renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags); /* flags=AT_SYMLINK_NOFOLLOW, efault=oldpath|newpath */ int prctl(int option, ...); /* hand_wrapped=1 */ int close_range(unsigned int lowfd, unsigned int maxfd, int flags); void closefrom(int fd);
ports/linux/xattr/wrapfuncs.in +8 -8
@@ -1,12 +1,12 @@ -ssize_t getxattr(const char *path, const char *name, void *value, size_t size); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +ssize_t getxattr(const char *path, const char *name, void *value, size_t size); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ +ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -int setxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -int lsetxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +int setxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ +int lsetxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ int fsetxattr(int filedes, const char *name, const void *value, size_t size, int xflags); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -ssize_t listxattr(const char *path, char *list, size_t size); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -ssize_t llistxattr(const char *path, char *list, size_t size); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +ssize_t listxattr(const char *path, char *list, size_t size); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ +ssize_t llistxattr(const char *path, char *list, size_t size); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ ssize_t flistxattr(int filedes, char *list, size_t size); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -int removexattr(const char *path, const char *name); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -int lremovexattr(const char *path, const char *name); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +int removexattr(const char *path, const char *name); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ +int lremovexattr(const char *path, const char *name); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ int fremovexattr(int filedes, const char *name); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */
Signature · 1 line
2.43.0
PATCH 16/20 Update COPYRIGHT files
In reply to Mark HatleFrom: Mark Hatle <[email protected]>
--- guts/COPYRIGHT | 2 ++ ports/darwin/guts/COPYRIGHT | 1 + ports/linux/guts/COPYRIGHT | 2 ++ ports/uids_generic/guts/COPYRIGHT | 1 + ports/unix/guts/COPYRIGHT | 2 ++ 5 files changed, 8 insertions(+)
guts/COPYRIGHT +2 -0
@@ -1,5 +1,7 @@ /* * Copyright (c) 2008-2014 Wind River Systems, Inc. + * Copyright (c) 2018 Peter Seebach/Seebs <[email protected]> + * Copyright (c) 2020-2026 Yocto Project Contributors * * SPDX-License-Identifier: LGPL-2.1-only *
ports/darwin/guts/COPYRIGHT +1 -0
@@ -1,5 +1,6 @@ /* * Copyright (c) 2008-2010 Wind River Systems, Inc. + * Copyright (c) 2018 Peter Seebach/Seebs <[email protected]> * * SPDX-License-Identifier: LGPL-2.1-only *
ports/linux/guts/COPYRIGHT +2 -0
@@ -1,5 +1,7 @@ /* * Copyright (c) 2008-2010 Wind River Systems, Inc. + * Copyright (c) 2018-2019 Peter Seebach/Seebs <[email protected]> + * Copyright (c) 2019-2026 Yocto Project Contributors * * SPDX-License-Identifier: LGPL-2.1-only *
ports/uids_generic/guts/COPYRIGHT +1 -0
@@ -1,5 +1,6 @@ /* * Copyright (c) 2008-2010 Wind River Systems, Inc. + * Copyright (c) 2018 Peter Seebach/Seebs <[email protected]> * * SPDX-License-Identifier: LGPL-2.1-only *
ports/unix/guts/COPYRIGHT +2 -0
@@ -1,5 +1,7 @@ /* * Copyright (c) 2008-2010 Wind River Systems, Inc. + * Copyright (c) 2018 Peter Seebach/Seebs <[email protected]> + * Copyright (C) 2020-2026 Yocto Project Contributors * * SPDX-License-Identifier: LGPL-2.1-only *
Signature · 1 line
2.43.0
PATCH 17/20 makewrappers: improve error handling and robustness
In reply to Mark HatleFrom: Mark Hatle <[email protected]>
Add several robustness improvements to the makewrappers Python script:
* Add null checks for self.type and arg.name to prevent AttributeError when processing malformed function declarations
* Add validation for comment format to ensure '=' is present before attempting to parse comments into dictionaries
* Replace incorrect poll() calls with returncode attribute when checking subprocess completion status
* Add proper file error handling with context managers (with statements) and OSError exceptions when reading/writing wrapper files
* Add argument validation to ensure wrapper function arguments are properly specified before generating code
These changes prevent crashes when processing invalid input and improve error reporting when file operations fail.
AI-Generated: Suggested by GitHub Copilot (Claude Sonnet 4.5)
--- makewrappers | 73 ++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 33 deletions(-)
makewrappers +40 -33
@@ -12,7 +12,6 @@ import sys import re import os.path import platform -import string import subprocess from templatefile import TemplateFile
@@ -152,9 +151,11 @@ class Argument: # spacing between type and name, needed if type ends with a character # which could be part of an identifier - if re.match('[_a-zA-Z0-9]', self.type[-1]): + if self.type and re.match('[_a-zA-Z0-9]', self.type[-1]): self.spacer = ' ' + return + def decl(self, comment=False, wrap=False): """Produce the declaration form of this argument.""" if self.function_pointer:
@@ -274,13 +275,13 @@ class Function: # ignore varargs, they never get these special treatments if arg.vararg: pass - elif arg.name.endswith('dirfd'): + elif arg.name and arg.name.endswith('dirfd'): if len(arg.name) > 5: self.specific_dirfds[arg.name[:-5]] = True self.dirfd = 'dirfd' elif arg.name == 'flags': self.flags = '(flags & AT_SYMLINK_NOFOLLOW)' - elif arg.name.endswith('path'): + elif arg.name and arg.name.endswith('path'): self.paths_to_munge.append(arg.name) elif arg.name == 'fd': self.fd_arg = "fd"
@@ -304,6 +305,10 @@ class Function: # handle special comments, such as flags=AT_SYMLINK_NOFOLLOW if self.comments: comments = self.comments.replace('==','<equals>') + # Validate the comments + for mod in comments.split(','): + if '=' not in mod: + raise Exception("Parse error invalid comment '%s'" % (comments)) # Build a dictionary of key=value, key=value pairs modifiers = dict(mod.split("=") for mod in comments.split(',')) # Strip all leading/trailing whitespace
@@ -535,7 +540,8 @@ additional ports to include. if os.path.exists(self.portfile("preports")): subport_proc = subprocess.Popen([self.portfile("preports"), self.name], stdout=subprocess.PIPE) portlist = subport_proc.communicate()[0] - retcode = subport_proc.poll() + portlist = portlist.decode("utf-8") + retcode = subport_proc.returncode if retcode: raise Exception("preports script failed for port %s" % self.name)
@@ -546,7 +552,8 @@ additional ports to include. if os.path.exists(self.portfile("subports")): subport_proc = subprocess.Popen([self.portfile("subports"), self.name], stdout=subprocess.PIPE) portlist = subport_proc.communicate()[0] - retcode = subport_proc.poll() + portlist = portlist.decode("utf-8") + retcode = subport_proc.returncode if retcode: raise Exception("subports script failed for port %s" % self.name)
@@ -622,20 +629,23 @@ def process_wrapfuncs(port): funcs = {} directory = os.path.dirname(filename) sys.stdout.write("%s: " % filename) - funclist = open(filename) - for line in funclist: - line = line.rstrip() - if line.startswith('#') or not line: - continue - try: - func = Function(port, line) - func.directory = directory - funcs[func.name] = func - sys.stdout.write(".") - except Exception as e: - print("Parsing failed:", e) - exit(1) - funclist.close() + try: + with open(filename, "r") as funclist: + for line in funclist: + line = line.rstrip() + if line.startswith('#') or not line: + continue + try: + func = Function(port, line) + func.directory = directory + funcs[func.name] = func + sys.stdout.write(".") + except Exception as e: + print("Parsing failed:", e) + exit(1) + except OSError as e: + print("Unable to open file %s" % filename) + exit(1) print("") return funcs
@@ -645,13 +655,19 @@ def main(argv): sources = [] for arg in argv: + if '=' not in arg: + print("Invalid argument '%s', must be of the form name=value" % arg) + exit(1) name, value = arg.split('=') os.environ["port_" + name] = value # error checking helpfully provided by the exception handler - copyright_file = open('guts/COPYRIGHT') - TemplateFile.copyright = copyright_file.read() - copyright_file.close() + try: + with open('guts/COPYRIGHT') as copyright_file: + TemplateFile.copyright = copyright_file.read() + except OSError as e: + print("Unable to open file guts/COPYRIGHT") + exit(1) for path in glob.glob('templates/*'): try:
@@ -665,16 +681,7 @@ def main(argv): print("Invalid or malformed template %s. Aborting." % path) exit(1) - try: - port = Port('common', sources) - - except KeyError: - print("Unknown uname -s result: '%s'." % uname_s) - print("Known system types are:") - print("%-20s %-10s %s" % ("uname -s", "port name", "description")) - for key in host_ports: - print("%-20s %-10s %s" % (key, host_ports[key], - host_descrs[host_ports[key]])) + port = Port('common', sources) # the per-function stuff print("Writing functions...")
Signature · 1 line
2.43.0
PATCH 18/20 pseudo: code quality scan - resolved various potential issues
In reply to Mark HatleFrom: Mark Hatle <[email protected]>
Memory Management Issues:
* Unchecked malloc/realloc calls in multiple files that could lead to NULL pointer dereferences or memory leaks
* Missing error handling for strdup() calls returning NULL
AI-Generated: Issues identified by GitHub Copilot (Claude Sonnet 4.5)
The actual code changes however are my own, AI only identified potential issues.
--- ports/unix/guts/fts_open.c | 5 ++- ports/unix/guts/nftw_wrapper_base.c | 11 ++--- pseudo.c | 61 ++++++++++++++++----------- pseudo_client.c | 4 ++ pseudo_db.c | 10 +++++ pseudo_server.c | 14 +++++++ pseudo_util.c | 64 +++++++++++++++++++---------- 7 files changed, 117 insertions(+), 52 deletions(-)
ports/unix/guts/fts_open.c +4 -1
@@ -31,8 +31,11 @@ rpath_argv[i] =PSEUDO_ROOT_PATH (AT_FDCWD , path_argv[i],AT_SYMLINK_NOFOLLOW );if (!rpath_argv[i]) errored =1 ; -else +else { rpath_argv[i] =strdup (rpath_argv[i]); +if (!rpath_argv[i]) + errored =1 ; + } }if (errored) {
ports/unix/guts/nftw_wrapper_base.c +6 -5
@@ -38,7 +38,8 @@ static pthread_mutex_t NFTW_MUTEX_NAME = PTHREAD_MUTEX_INITIALIZER;static void NFTW_APPEND_FN_NAME (struct NFTW_STORAGE_STRUCT_NAME *data_to_append){NFTW_STORAGE_ARRAY_NAME =realloc (NFTW_STORAGE_ARRAY_NAME , ++NFTW_STORAGE_ARRAY_SIZE *sizeof (*data_to_append)); -memcpy (&NFTW_STORAGE_ARRAY_NAME [NFTW_STORAGE_ARRAY_SIZE -1 ], data_to_append,sizeof (*data_to_append)); +if (NFTW_STORAGE_ARRAY_NAME ) +memcpy (&NFTW_STORAGE_ARRAY_NAME [NFTW_STORAGE_ARRAY_SIZE -1 ], data_to_append,sizeof (*data_to_append)); }int NFTW_FIND_FN_NAME (struct NFTW_STORAGE_STRUCT_NAME * target) {
@@ -46,7 +47,7 @@ int NFTW_FIND_FN_NAME(struct NFTW_STORAGE_STRUCT_NAME* target) {// return the last one, not the first for (ssize_t i =NFTW_STORAGE_ARRAY_SIZE -1 ; i >=0 ; --i){ -if (NFTW_STORAGE_ARRAY_NAME [i].tid == tid){ +if ((NFTW_STORAGE_ARRAY_NAME ) && (NFTW_STORAGE_ARRAY_NAME [i].tid == tid)){// need to dereference it, as next time this array // may be realloc'd, making the original pointer // invalid
@@ -62,7 +63,7 @@ static void NFTW_DELETE_FN_NAME() {pthread_t tid =pthread_self ();if (NFTW_STORAGE_ARRAY_SIZE ==1 ) { -if (NFTW_STORAGE_ARRAY_NAME [0 ].tid == tid) { +if ((NFTW_STORAGE_ARRAY_NAME ) && (NFTW_STORAGE_ARRAY_NAME [0 ].tid == tid)) {free (NFTW_STORAGE_ARRAY_NAME );NFTW_STORAGE_ARRAY_NAME =NULL ; --NFTW_STORAGE_ARRAY_SIZE ;
@@ -73,7 +74,7 @@ static void NFTW_DELETE_FN_NAME() { }int found_idx =-1 ; -for (ssize_t i =NFTW_STORAGE_ARRAY_SIZE -1 ; i >=0 ; --i) { +for (ssize_t i =NFTW_STORAGE_ARRAY_SIZE -1 ; (NFTW_STORAGE_ARRAY_NAME ) && i >=0 ; --i) {if (NFTW_STORAGE_ARRAY_NAME [i].tid == tid) { found_idx = i;break ;
@@ -86,7 +87,7 @@ static void NFTW_DELETE_FN_NAME() { }// delete the item we just found -for (size_t i = found_idx +1 ; i <NFTW_STORAGE_ARRAY_SIZE ; ++i) +for (size_t i = found_idx +1 ; (NFTW_STORAGE_ARRAY_NAME ) && i <NFTW_STORAGE_ARRAY_SIZE ; ++i)NFTW_STORAGE_ARRAY_NAME [i -1 ] =NFTW_STORAGE_ARRAY_NAME [i];NFTW_STORAGE_ARRAY_NAME =realloc (NFTW_STORAGE_ARRAY_NAME , --NFTW_STORAGE_ARRAY_SIZE *sizeof (struct NFTW_STORAGE_STRUCT_NAME ));
pseudo.c +37 -24
87 lines not on this page · raw message
pseudo_client.c +4 -0
@@ -900,6 +900,10 @@ pseudo_client_path_set(int fd, const char *path, char ***patharray, int *len) {pseudo_debug (PDBGF_CLIENT ,"expanding fds from %d to %d\n" , *len, fd +1 ); (*patharray) =realloc ((*patharray), (fd +1 ) *sizeof (char *)); +if (!*patharray) { +pseudo_diag ("couldn't realloc fd path array to %ld entries\n" , (fd +1 ) *sizeof (char *)); +exit (1 ); + }for (i = *len; i < fd +1 ; ++i) (*patharray)[i] =0 ; *len = fd +1 ;
pseudo_db.c +10 -0
@@ -2165,6 +2165,10 @@ pdb_update_inode(pseudo_msg_t *msg) {if (!oldmsg) { oldmsg =malloc (sizeof (*msg) +pseudo_path_max ()); +if (!oldmsg) { +pseudo_diag ("%s: out of memory\n" , __func__); +return 1 ; + } }char *sql ="UPDATE files "
@@ -2516,6 +2520,12 @@ pdb_get_xattr(pseudo_msg_t *msg, char **value, size_t *len) {* arbitrary bytes. */ *value =malloc (length); +if (!*value) { +pseudo_diag ("%s: out of memory\n" , __func__); +sqlite3_reset (select); +sqlite3_clear_bindings (select); +return 1 ; + }memcpy (*value, response, length); *len = length; rc =0 ;
pseudo_server.c +14 -0
@@ -558,6 +558,12 @@ serve_client(int i) {char *s; response_path =malloc (8 * active_clients); +if (!response_path) { +pseudo_diag ("out of memory allocating shutdown response\n" ); +exit (PSEUDO_EXIT_GENERAL ); + }else { +memset (response_path,0 ,8 * active_clients); + } in->type =PSEUDO_MSG_NAK ; in->fd = active_clients -2 ; s = response_path;
@@ -626,6 +632,10 @@ static void pseudo_server_loop_epoll(void) }; clients =malloc (16 *sizeof (*clients)); +if (!clients) { +pseudo_diag ("out of memory allocating client table.\n" ); +exit (PSEUDO_EXIT_LISTEN_FD ); + }sigaction (SIGUSR2 , &eat_usr2,NULL );
@@ -796,6 +806,10 @@ pseudo_server_loop(void) {int hitmaxfiles; clients =malloc (16 *sizeof (*clients)); +if (!clients) { +pseudo_diag ("out of memory allocating client table.\n" ); +exit (PSEUDO_EXIT_LISTEN_FD ); + }sigaction (SIGUSR2 , &eat_usr2,NULL );
pseudo_util.c +42 -22
122 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH 19/20 configure: Minor code quality changes
In reply to Mark HatleFrom: Mark Hatle <[email protected]>
AI-Generated: Suggested by GitHub Copilot (Claude Sonnet 4.5)
--- configure | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
configure +12 -7
@@ -56,17 +56,17 @@ use_maybe_rpath=true for arg do - case $arg in + case "$arg" in --disable-*) arg="--enable-${arg%--disable-}=no" ;; esac - case $arg in + case "$arg" in --) shift; break ;; --prefix=*) opt_prefix=${arg#--prefix=} if [ -d "$opt_prefix" ]; then - maybe_prefix=$(cd "$opt_prefix"; pwd) + maybe_prefix=$(cd "$opt_prefix" && pwd) else maybe_prefix=$opt_prefix fi
@@ -169,7 +169,7 @@ do esac done -case $opt_arch in +case "$opt_arch" in '' | x86 | arm ) ;; *) echo >&2 "Untested arch $opt_arch."
@@ -178,7 +178,7 @@ esac if [ -z "$opt_bits" ]; then printf >&2 "Bit width unspecified;" - case $(file -L /bin/sh 2>/dev/null) in + case "$(file -L /bin/sh 2>/dev/null)" in *64-bit*) opt_bits=64;; *32-bit*) opt_bits=32;; esac
@@ -241,6 +241,10 @@ read t1 t2 SQLITE3_VERSION << EOF `grep "#define SQLITE_VERSION_NUMBER " ${opt_sqlite}/include/sqlite3.h` EOF +if [ -z "${SQLITE3_VERSION}" ]; then + echo >&2 "Could not determine SQLite version from header." + exit 1 +fi echo "SQLite header for version ${SQLITE3_VERSION} found in ${opt_sqlite}." if [ "${SQLITE3_VERSION}" -lt "03006000" ]; then
@@ -292,7 +296,7 @@ fi if $opt_xattr || $opt_xattrdb; then if ! $xattr_runs; then - echo >&2 "WARNING: getfattr doesn't work, but xattr-related features requestd." + echo >&2 "WARNING: getfattr doesn't work, but xattr-related features requested." fi fi
@@ -327,6 +331,7 @@ fi touch port_deps.mk touch func_deps.mk +rm -f Makefile sed -e ' s,@PREFIX@,'"$opt_prefix"',g s,@EPOLL@,'"$EPOLL"',g
@@ -350,4 +355,4 @@ sed -e ' s,@BITS@,'"$opt_bits"',g ' < Makefile.in > Makefile -sed -i -e 's/\-[f]*pie//g' Makefile +sed Makefile -e 's/\-[f]*pie//g' > Makefile.tmp && mv Makefile.tmp Makefile
Signature · 1 line
2.43.0
PATCH 20/20 Makefile.in: Bump version to 1.9.3
In reply to Mark HatleUpdate the ChangeLog.txt to indicate it's obsolete.
--- ChangeLog.txt | 4 ++++ Makefile.in | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-)
ChangeLog.txt +4 -0
@@ -1,3 +1,7 @@ +This changelog is obsolete, it stopped being updated as of commit +097ca3e245200c4a4333964af59a106c42ff3bca. See the git log for up to +date changes. + 2019-08-02: * (seebs) Pass flags & O_NOFOLLOW, also use that to influence stat types. Note. &. Not |.
Makefile.in +1 -1
@@ -34,7 +34,7 @@ BITS=@BITS@ ARCH_FLAGS=@ARCH_FLAGS@ MARK64=@MARK64@ RPATH=@RPATH@ -VERSION=1.9.2 +VERSION=1.9.3 LIB=@LIB@ BIN=bin
Signature · 1 line
2.43.0
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [yocto-patches] [pseudo][PATCH 13/20] ports/linux/pseudo_wrappers.c: Reorder the syscall operations
Quoted 52 lines · Mark Hatle
The seccomp wrap always takes effect when pseudo is running, this will prevent various behavior, even if pseudo is generally considered to be disabled, but in memory.
The openat2 and renameat2 however should only run if pseudo is enabled.
Signed-off-by Mark Hatle <[email protected]>--- ports/linux/pseudo_wrappers.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)ports/linux/pseudo_wrappers.c +6
-13@@ -65,19 +65,6 @@ syscall(long number, ...) {return rc; } -#ifdef SYS_renameat2 -/* concerns exist about trying to parse arguments because syscall(2) -* specifies strange ABI behaviors. If we can get better clarity on -* that, it could make sense to redirect to wrap_renameat2(). -*/ -if (number == SYS_renameat2) { - errno =ENOSYS ; -return -1 ; - } -#else - (void ) number; -#endif -#ifdef SYS_seccomp/* pseudo and seccomp are incompatible as pseudo uses different syscalls * so pretend to enable seccomp but really do nothing */ @@ -92,6 +79,10 @@ syscall(long number, ...) { }#endif +if (pseudo_disabled) { + goto call_syscall; + } +#ifdef SYS_openat2/* concerns exist about trying to parse arguments because syscall(2) * specifies strange ABI behaviors. If we can get better clarity on @@ -105,6 +96,18 @@ syscall(long number, ...) { }#endif +#ifdef SYS_renameat2 +/* concerns exist about trying to parse arguments because syscall(2)
ports/linux/pseudo_wrappers.c syscall(long number, ...) { · line 110
Quoted 10 lines
ports/linux/pseudo_wrappers.c +10
-0+* specifies strange ABI behaviors. If we can get better clarity on +* that, it could make sense to redirect to wrap_renameat2(). +*/ +if (number == SYS_renameat2) { + errno =ENOSYS ; +return -1 ; + } +#endif + +call_syscall:
On Debian 11 this fails to compile. I had to add a patch to workaround what I suspect is a compiler bug:
call_syscall:
+ /* On Debian 11 - gcc (Debian 10.2.1-6) this results in:
+ * error: a label can only be part of a statement and a declaration + * is not a statement + * + * adding a ; here resolves this + */
+ ;
+
Quoted 3 lines
ports/linux/pseudo_wrappers.c +0
-0/* gcc magic to attempt to just pass these args to syscall. we have to * guess about the number of args; the docs discuss calling conventions * up to 7, so let's try that?
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [yocto-patches] [pseudo][PATCH 15/20] ports/linux: Add additional EFAULTS for Linux functions
I'm dropping this patch. Debian 11 glibc has set more functions as path nonnull, so the compiler complains about the EFAULT check of path.
The original issue is still resolved, but if this nonnull behavior continues at some point it's going to show what rust is doing to check for xstat is indeed sketchy.
--Mark
Quoted 101 lines · Mark Hatle
Note, other functions claim to return EFAULT when the path element is NULL, however glibc has these parameters tagged as non-null which optimizes out any sort of NULL test by default. Due to this only items that don't error were included.
Signed-off-by Mark Hatle <[email protected]>--- ports/linux/openat2/wrapfuncs.in | 2 +- ports/linux/wrapfuncs.in | 22 +++++++++++----------- ports/linux/xattr/wrapfuncs.in | 16 ++++++++-------- 3 files changed, 20 insertions(+), 20 deletions(-)ports/linux/openat2/wrapfuncs.in +1
-1@@ -1 +1 @@ -int openat2(int dirfd, const char *path, struct open_how *how, size_t size); +int openat2(int dirfd, const char *path, struct open_how *how, size_t size); /* efault=path */ports/linux/wrapfuncs.in +11
-11@@ -1,17 +1,17 @@ int open(const char *path, int flags, ...{mode_t mode}); /* flags=((flags&O_NOFOLLOW)||((flags&(O_CREAT|O_EXCL))==(O_CREAT|O_EXCL))), noignore_path=1 */ char *get_current_dir_name(void); -int __xstat(int ver, const char *path, struct stat *buf); -int __lxstat(int ver, const char *path, struct stat *buf); /* flags=AT_SYMLINK_NOFOLLOW */ +int __xstat(int ver, const char *path, struct stat *buf); /* efault=path */ +int __lxstat(int ver, const char *path, struct stat *buf); /* flags=AT_SYMLINK_NOFOLLOW, efault=path */ int __fxstat(int ver, int fd, struct stat *buf); int lchmod(const char *path, mode_t mode); /* flags=AT_SYMLINK_NOFOLLOW */ int lchown(const char *path, uid_t owner, gid_t group); /* flags=AT_SYMLINK_NOFOLLOW */ -int __fxstatat(int ver, int dirfd, const char *path, struct stat *buf, int flags); +int __fxstatat(int ver, int dirfd, const char *path, struct stat *buf, int flags); /* efault=path */ int openat(int dirfd, const char *path, int flags, ...{mode_t mode}); /* flags=((flags&O_NOFOLLOW)||((flags&(O_CREAT|O_EXCL))==(O_CREAT|O_EXCL))), noignore_path=1 */ int __openat_2(int dirfd, const char *path, int flags); /* flags=((flags&O_NOFOLLOW)||((flags&(O_CREAT|O_EXCL))==(O_CREAT|O_EXCL))), noignore_path=1 */ int mknod(const char *path, mode_t mode, dev_t dev); /* real_func=pseudo_mknod */ int mknodat(int dirfd, const char *path, mode_t mode, dev_t dev); /* real_func=pseudo_mknodat */ -int __xmknod(int ver, const char *path, mode_t mode, dev_t *dev); /* flags=AT_SYMLINK_NOFOLLOW */ -int __xmknodat(int ver, int dirfd, const char *path, mode_t mode, dev_t *dev); /* flags=AT_SYMLINK_NOFOLLOW */ +int __xmknod(int ver, const char *path, mode_t mode, dev_t *dev); /* flags=AT_SYMLINK_NOFOLLOW, efault=path */ +int __xmknodat(int ver, int dirfd, const char *path, mode_t mode, dev_t *dev); /* flags=AT_SYMLINK_NOFOLLOW, efault=path */ int fcntl(int fd, int cmd, ...{struct flock *lock}); /* noignore_path=1 */ int fcntl64(int fd, int cmd, ...{struct flock *lock}); /* noignore_path=1 */ # just so we know the inums of symlinks@@ -24,15 +24,15 @@ int creat64(const char *path, mode_t mode); int stat(const char *path, struct stat *buf); /* real_func=pseudo_stat */ int lstat(const char *path, struct stat *buf); /* real_func=pseudo_lstat, flags=AT_SYMLINK_NOFOLLOW */ int fstat(int fd, struct stat *buf); /* real_func=pseudo_fstat */ -int fstatat(int dirfd, const char *path, struct stat *buf, int flags); +int fstatat(int dirfd, const char *path, struct stat *buf, int flags); /* efault=path */ int stat64(const char *path, struct stat64 *buf); /* real_func=pseudo_stat64 */ int lstat64(const char *path, struct stat64 *buf); /* real_func=pseudo_lstat64, flags=AT_SYMLINK_NOFOLLOW */ int fstat64(int fd, struct stat64 *buf); /* real_func=pseudo_fstat64 */ -int fstatat64(int dirfd, const char *path, struct stat64 *buf, int flags); -int __xstat64(int ver, const char *path, struct stat64 *buf); -int __lxstat64(int ver, const char *path, struct stat64 *buf); /* flags=AT_SYMLINK_NOFOLLOW */ +int fstatat64(int dirfd, const char *path, struct stat64 *buf, int flags); /* efault=path */ +int __xstat64(int ver, const char *path, struct stat64 *buf); /* efault=path */ +int __lxstat64(int ver, const char *path, struct stat64 *buf); /* flags=AT_SYMLINK_NOFOLLOW, efault=path */ int __fxstat64(int ver, int fd, struct stat64 *buf); -int __fxstatat64(int ver, int dirfd, const char *path, struct stat64 *buf, int flags); +int __fxstatat64(int ver, int dirfd, const char *path, struct stat64 *buf, int flags); /* efault=path */ FILE *fopen64(const char *path, const char *mode); /* noignore_path=1 */ int nftw64(const char *path, int (*fn)(const char *, const struct stat64 *, int, struct FTW *), int nopenfd, int flag); /* noignore_path=1 */ FILE *freopen64(const char *path, const char *mode, FILE *stream); /* noignore_path=1 */@@ -61,7 +61,7 @@ int getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **p int getgrent_r(struct group *gbuf, char *buf, size_t buflen, struct group **gbufp); int capset(cap_user_header_t hdrp, const cap_user_data_t datap); /* real_func=pseudo_capset */ long syscall(long nr, ...); /* hand_wrapped=1 */ -int renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags); /* flags=AT_SYMLINK_NOFOLLOW */ +int renameat2(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, unsigned int flags); /* flags=AT_SYMLINK_NOFOLLOW, efault=oldpath|newpath */ int prctl(int option, ...); /* hand_wrapped=1 */ int close_range(unsigned int lowfd, unsigned int maxfd, int flags); void closefrom(int fd);ports/linux/xattr/wrapfuncs.in +8
-8@@ -1,12 +1,12 @@ -ssize_t getxattr(const char *path, const char *name, void *value, size_t size); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +ssize_t getxattr(const char *path, const char *name, void *value, size_t size); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ +ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -int setxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -int lsetxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +int setxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ +int lsetxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ int fsetxattr(int filedes, const char *name, const void *value, size_t size, int xflags); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -ssize_t listxattr(const char *path, char *list, size_t size); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -ssize_t llistxattr(const char *path, char *list, size_t size); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +ssize_t listxattr(const char *path, char *list, size_t size); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ +ssize_t llistxattr(const char *path, char *list, size_t size); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ ssize_t flistxattr(int filedes, char *list, size_t size); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -int removexattr(const char *path, const char *name); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ -int lremovexattr(const char *path, const char *name); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */ +int removexattr(const char *path, const char *name); /* flags=0, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ +int lremovexattr(const char *path, const char *name); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3", version-aarch64="GLIBC_2.17", efault=path */ int fremovexattr(int filedes, const char *name); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */