commit:     09f9b61bdfa488d78bdba4562eb208bd1f062eaf
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Tue Jan 24 02:45:11 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jan 24 03:03:23 2023 +0000
URL:        https://gitweb.gentoo.org/proj/elfix.git/commit/?id=09f9b61b

install-xattr: fix chdir arg when OLDPWD is nulL

Fix core.NonNullParamChecker with chdir().

Clang's scan-build says:
```
install-xattr.c:331:9: warning: Null pointer passed to 1st parameter expecting 
'nonnull' [core.NonNullParamChecker]
    if (chdir(oldpwd) != 0)
        ^~~~~~~~~~~~~
```

It's right - oldpwd could easily have been null:
```
$ env -u OLDPWD __PORTAGE_HELPER_PATH=foo ./install-xattr --version
```

Signed-off-by: Sam James <sam <AT> gentoo.org>

 misc/install-xattr/install-xattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/misc/install-xattr/install-xattr.c 
b/misc/install-xattr/install-xattr.c
index 2966af4..33b9fe1 100644
--- a/misc/install-xattr/install-xattr.c
+++ b/misc/install-xattr/install-xattr.c
@@ -345,7 +345,7 @@ main(int argc, char* argv[])
        char *portage_helper_path = getenv("__PORTAGE_HELPER_PATH");
        char *portage_helper_canpath = NULL;
        if (portage_helper_path)
-               if (chdir(oldpwd) != 0)
+               if (!oldpwd || chdir(oldpwd) != 0)
                        err(1, "failed to chdir %s", oldpwd);
 
        switch (fork()) {

Reply via email to