pseudo_util: don't overrun strings when looking for keys
PATCH 1/7 pseudo_util: don't overrun strings when looking for keys
Use strcmp() insead of memcmp() when searching for keys as otherwise the comparison will run off the end of the NULL-terminated string.
--- pseudo_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
pseudo_util.c +2 -2
@@ -159,7 +159,7 @@ pseudo_get_value(const char *key) {if (pseudo_util_initted ==-1 )pseudo_init_util (); -for (i =0 ; pseudo_env[i].key &&memcmp (pseudo_env[i].key, key, pseudo_env[i].key_len +1 ); i++) +for (i =0 ; pseudo_env[i].key &&strcmp (pseudo_env[i].key, key); i++) ;/* Check if the environment has it and we don't ...
@@ -188,7 +188,7 @@ pseudo_set_value(const char *key, const char *value) {if (pseudo_util_initted ==-1 )pseudo_init_util (); -for (i =0 ; pseudo_env[i].key &&memcmp (pseudo_env[i].key, key, pseudo_env[i].key_len +1 ); i++) +for (i =0 ; pseudo_env[i].key &&strcmp (pseudo_env[i].key, key); i++) ;if (pseudo_env[i].key) {
Signature · 1 line
2.25.1
PATCH 2/7 Silence switch block warnings
Slightly alter a fallthrough comment so that GCC recognises it, and add a default: case to a switch which explicitly only handles a few values.
--- pseudo.c | 2 ++ pseudo_client.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-)
pseudo.c +2 -0
@@ -1036,6 +1036,8 @@ pseudo_op(pseudo_msg_t *msg, const char *program, const char *tag, char **responpdb_may_unlink_file (msg, msg->client); }break ; +default : +break ; } op_exit:
pseudo_client.c +2 -1
@@ -1860,7 +1860,8 @@ pseudo_client_op(pseudo_op_t op, int access, int fd, int dirfd, const char *pathbreak ;case OP_OPEN :pseudo_client_path (fd, path); -case OP_EXEC :/* fallthrough */ +/* fallthrough */ +case OP_EXEC : do_request = pseudo_client_logging;break ;case OP_CLOSE :
Signature · 1 line
2.25.1
PATCH 3/7 Disable deprecated function warnings
In reply to Ross BurtonPseudo has to call deprecated functions because it is wrapping them, so disable deprecation warnings.
--- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile.in +1 -1
@@ -42,7 +42,7 @@ LOCALSTATE=var/pseudo BINDIR=$(PREFIX)/$(BIN) LOCALSTATEDIR=$(PREFIX)/$(LOCALSTATE) -CFLAGS_BASE=-pipe -std=gnu99 -Wall -W -Wextra +CFLAGS_BASE=-pipe -std=gnu99 -Wall -W -Wextra -Wno-deprecated-declarations CFLAGS_CODE=-fPIC -D_LARGEFILE64_SOURCE -D_ATFILE_SOURCE $(ARCH_FLAGS) CFLAGS_DEFS=-DPSEUDO_PREFIX='"$(PREFIX)"' -DPSEUDO_SUFFIX='"$(SUFFIX)"' -DPSEUDO_BINDIR='"$(BIN)"' -DPSEUDO_LIBDIR='"$(LIB)"' -DPSEUDO_LOCALSTATEDIR='"$(LOCALSTATE)"' -DPSEUDO_VERSION='"$(VERSION)"' $(SQLITE_MEMORY) $(FORCE_ASYNC) -DPSEUDO_PASSWD_FALLBACK='$(PASSWD_FALLBACK)' $(OPTDEFS) $(EPOLL) CFLAGS_DEBUG=-O2 -g
Signature · 1 line
2.25.1
PATCH 4/7 Fix some memory leaks
In reply to Ross Burtonpseudo_get_value() returns newly allocated memory that the caller must free, so add some free() calls.
--- pseudo.c | 4 +++- pseudo_client.c | 9 +++++++++ pseudo_util.c | 2 ++ 3 files changed, 14 insertions(+), 1 deletion(-)
pseudo.c +3 -1
@@ -245,10 +245,12 @@ main(int argc, char *argv[]) {/* Options are processed, preserve them... */ pseudo_set_value ("PSEUDO_OPTS" , opts); -if (!pseudo_get_prefix (argv[0 ])) { + s =pseudo_get_prefix (argv[0 ]); +if (!s) {pseudo_diag ("Can't figure out prefix. Set PSEUDO_PREFIX or invoke with full path.\n" );exit (PSEUDO_EXIT_PSEUDO_PREFIX ); } +free (s);/* move database */ if (opt_m || opt_M) {
pseudo_client.c +9 -0
@@ -431,6 +431,7 @@ pseudo_profile_report(void) {void pseudo_init_client (void ) {char *env; +int need_free =0 ;pseudo_antimagic ();pseudo_new_pid ();
@@ -450,9 +451,11 @@ pseudo_init_client(void) {* or it may have gone away, in which case we'd enable * pseudo (and cause it to reinit the defaults). */ + need_free =0 ; env =getenv ("PSEUDO_DISABLED" );if (!env) { env =pseudo_get_value ("PSEUDO_DISABLED" ); + need_free =1 ; }if (env) {int actually_disabled =1 ;
@@ -487,15 +490,19 @@ pseudo_init_client(void) { }else {pseudo_set_value ("PSEUDO_DISABLED" ,"0" ); } +if (need_free) +free (env);/* ALLOW_FSYNC is here because some crazy hosts will otherwise * report incorrect values for st_size/st_blocks. I can sort of * understand st_blocks, but bogus values for st_size? Not cool, * dudes, not cool. */ + need_free =0 ; env =getenv ("PSEUDO_ALLOW_FSYNC" );if (!env) { env =pseudo_get_value ("PSEUDO_ALLOW_FSYNC" ); + need_free =1 ; }else {pseudo_set_value ("PSEUDO_ALLOW_FSYNC" , env); }
@@ -504,6 +511,8 @@ pseudo_init_client(void) { }else { pseudo_allow_fsync =0 ; } +if (need_free) +free (env);/* in child processes, PSEUDO_UNLOAD may become set to * some truthy value, in which case we're being asked to
pseudo_util.c +2 -0
@@ -967,6 +967,7 @@ pseudo_setupenv() { }snprintf (newenv, len,"%s:%s64" , libdir_path, libdir_path);SETENV (PRELINK_PATH , newenv,1 ); +free (newenv); }else if (!strstr (ld_library_path, libdir_path)) {size_t len =strlen (ld_library_path) +1 +strlen (libdir_path) +1 + (strlen (libdir_path) +2 ) +1 ;char *newenv =malloc (len);
@@ -975,6 +976,7 @@ pseudo_setupenv() { }snprintf (newenv, len,"%s:%s:%s64" , ld_library_path, libdir_path, libdir_path);SETENV (PRELINK_PATH , newenv,1 ); +free (newenv); }else {/* nothing to do, ld_library_path exists and contains * our preferred path */
Signature · 1 line
2.25.1
Re: [OE-core] [PATCH][pseudo 4/7] Fix some memory leaks
For reference, I believe the rationale on these originally was "none of these functions happen repeatedly, in general, and the extra complexity and potential to get the logic wrong isn't appealing", but I don't think I object to these.
-s
PATCH 5/7 makewrappers: fix Python 2 hangover
In reply to Ross BurtonAn except statement was still using Python 2 syntax so caused SyntaxErrors if the exception was raised.
--- makewrappers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
makewrappers +1 -1
@@ -593,7 +593,7 @@ def process_wrapfuncs(port): func.directory = directory funcs[func.name] = func sys.stdout.write(".") - except Exception(e): + except Exception as e: print("Parsing failed:", e) exit(1) funclist.close()
Signature · 1 line
2.25.1
PATCH 6/7 makewrappers: support architecture-overrides in wrapper modifiers
In reply to Ross BurtonPseudo allows wrappers to define special comments in the wrapper lists to pass extra arguments such as version=GLIBC_2.3 to control which symbol version to search for. However, these arguments can be architecture-specific.
When parsing the arguments, check for flags that end in the architecture name (as returned by platform.machine()) and use those values instead.
--- makewrappers | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
makewrappers +13 -4
@@ -11,6 +11,7 @@ import glob import sys import re import os.path +import platform import string import subprocess from templatefile import TemplateFile
@@ -290,10 +291,18 @@ class Function: # handle special comments, such as flags=AT_SYMLINK_NOFOLLOW if self.comments: - modifiers = self.comments.split(', ') - for mod in modifiers: - key, value = mod.split('=') - value = value.rstrip() + # Build a dictionary of key=value, key=value pairs + modifiers = dict(mod.split("=") for mod in self.comments.split(',')) + # Strip all leading/trailing whitespace + modifiers = {k.strip():v.strip() for k, v in modifiers.items()} + + arch = "-" + platform.machine() + # Sorted so that versions-foo appear after versions, so overrides are easy + for key in sorted(modifiers): + value = modifiers[key] + # If the key is version-arm64 and we're on arm64 then rename this to version + if key.endswith(arch): + key = key.replace(arch, "") setattr(self, key, value) def maybe_inode64(self):
Signature · 1 line
2.25.1
PATCH 7/7 ports/linux/xattr: add arm64 versions for xattr calls
In reply to Ross BurtonThe xattr functions need to use a specific version of the symbols to avoid calling into libattr.so, which on Tumbleweed causes failures[1].
However on arm64 systems the glibc version is different. This means that searching for llistattr(GLIBC_2.3) fails to initially match the symbol in libc.so, and instead if libattr.so is linked then the symbol in that library is used. This is simply a wrapper that is intended to call the symbol in libc.so but instead calls the symbol in pseudo, so infinite loops.
Using the just-added architecture overrides, add the right versions for arm64 systems so the correct symbols in libc.so are found.
[ YOCTO #14133 ]
[1] b94fa2fc81cde25865ee223ca437d07377229a53
--- ports/linux/xattr/wrapfuncs.in | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
ports/linux/xattr/wrapfuncs.in +12 -12
@@ -1,12 +1,12 @@ -ssize_t getxattr(const char *path, const char *name, void *value, size_t size); /* flags=0, version="GLIBC_2.3" */ -ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3" */ -ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size); /* version="GLIBC_2.3" */ -int setxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=0, version="GLIBC_2.3" */ -int lsetxattr(const char *path, const char *name, const void *value, size_t size, int xflags); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3" */ -int fsetxattr(int filedes, const char *name, const void *value, size_t size, int xflags); /* version="GLIBC_2.3" */ -ssize_t listxattr(const char *path, char *list, size_t size); /* flags=0, version="GLIBC_2.3" */ -ssize_t llistxattr(const char *path, char *list, size_t size); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3" */ -ssize_t flistxattr(int filedes, char *list, size_t size); /* version="GLIBC_2.3" */ -int removexattr(const char *path, const char *name); /* flags=0, version="GLIBC_2.3" */ -int lremovexattr(const char *path, const char *name); /* flags=AT_SYMLINK_NOFOLLOW, version="GLIBC_2.3" */ -int fremovexattr(int filedes, const char *name); /* version="GLIBC_2.3" */ +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 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 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 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 fremovexattr(int filedes, const char *name); /* version="GLIBC_2.3", version-aarch64="GLIBC_2.17" */
Signature · 1 line
2.25.1