Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include libgen.h for BSD builds #481

Merged
merged 1 commit into from
Mar 13, 2019
Merged

Conversation

msbit
Copy link
Contributor

@msbit msbit commented Mar 9, 2019

Under Linux/glibc one of two implementations of basename can be selected, the GNU one provided by:

#define _GNU_SOURCE
#include <string.h>

and the POSIX one by:

#include <libgen.h>

However, BSDs only have the POSIX implementation, so conditionally include the header if BSD related definitions exist.

This fixes segfaults when displaying usage (lpass --help) under (at least) macOS and OpenBSD.

Signed-off-by: Tom Sullivan <tom@msbit.com.au>
@GPaulovics
Copy link
Contributor

Hey @msbit,
Did you experience segfaults on macOS when calling lpass --help?

I just tested it with the current master, and it works fine.

Thank You

@msbit
Copy link
Contributor Author

msbit commented Mar 13, 2019

Hey @GPaulovics, I did have this happen for me under macOS, building 5943be9 from scratch:

$ make
mkdir -p build && cd build && cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_INSTALL_MANDIR:PATH=/usr/share/man ..
-- The C compiler identification is AppleClang 10.0.0.10001145
-- The CXX compiler identification is AppleClang 10.0.0.10001145
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2") 
-- Found LibXml2: /usr/lib/libxml2.dylib (found version "2.9.4") 
-- Found OpenSSL: /usr/local/opt/openssl/lib/libcrypto.dylib (found version "1.0.2q")  
-- Found CURL: /usr/lib/libcurl.dylib (found version "7.54.0") 
Package bash-completion was not found in the pkg-config search path.
Perhaps you should add the directory containing `bash-completion.pc'
to the PKG_CONFIG_PATH environment variable
No package 'bash-completion' found
-- Configuring done
-- Generating done
-- Build files have been written to: /Volumes/Suffragette/Development/third_party/lastpass-cli/build
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C build all
Scanning dependencies of target lpass
[  2%] Building C object CMakeFiles/lpass.dir/agent.c.o
[  4%] Building C object CMakeFiles/lpass.dir/blob.c.o
[  7%] Building C object CMakeFiles/lpass.dir/cipher.c.o
[  9%] Building C object CMakeFiles/lpass.dir/clipboard.c.o
[ 11%] Building C object CMakeFiles/lpass.dir/cmd-add.c.o
[ 14%] Building C object CMakeFiles/lpass.dir/cmd-duplicate.c.o
[ 16%] Building C object CMakeFiles/lpass.dir/cmd-edit.c.o
[ 19%] Building C object CMakeFiles/lpass.dir/cmd-export.c.o
[ 21%] Building C object CMakeFiles/lpass.dir/cmd-generate.c.o
[ 23%] Building C object CMakeFiles/lpass.dir/cmd-import.c.o
[ 26%] Building C object CMakeFiles/lpass.dir/cmd-login.c.o
[ 28%] Building C object CMakeFiles/lpass.dir/cmd-logout.c.o
[ 30%] Building C object CMakeFiles/lpass.dir/cmd-ls.c.o
[ 33%] Building C object CMakeFiles/lpass.dir/cmd-mv.c.o
[ 35%] Building C object CMakeFiles/lpass.dir/cmd-passwd.c.o
[ 38%] Building C object CMakeFiles/lpass.dir/cmd-rm.c.o
[ 40%] Building C object CMakeFiles/lpass.dir/cmd-share.c.o
[ 42%] Building C object CMakeFiles/lpass.dir/cmd-show.c.o
[ 45%] Building C object CMakeFiles/lpass.dir/cmd-status.c.o
[ 47%] Building C object CMakeFiles/lpass.dir/cmd-sync.c.o
[ 50%] Building C object CMakeFiles/lpass.dir/cmd.c.o
[ 52%] Building C object CMakeFiles/lpass.dir/config.c.o
[ 54%] Building C object CMakeFiles/lpass.dir/edit.c.o
[ 57%] Building C object CMakeFiles/lpass.dir/endpoints-login.c.o
[ 59%] Building C object CMakeFiles/lpass.dir/endpoints-share.c.o
[ 61%] Building C object CMakeFiles/lpass.dir/endpoints.c.o
[ 64%] Building C object CMakeFiles/lpass.dir/format.c.o
[ 66%] Building C object CMakeFiles/lpass.dir/http.c.o
[ 69%] Building C object CMakeFiles/lpass.dir/json-format.c.o
[ 71%] Building C object CMakeFiles/lpass.dir/kdf.c.o
[ 73%] Building C object CMakeFiles/lpass.dir/log.c.o
[ 76%] Building C object CMakeFiles/lpass.dir/lpass.c.o
/Volumes/Suffragette/Development/third_party/lastpass-cli/lpass.c:84:23: warning: implicit declaration of function 'basename' is invalid in C99 [-Wimplicit-function-declaration]
                printf("  %s %s\n", basename(ARGV[0]), commands[i].usage);
                                    ^
/Volumes/Suffragette/Development/third_party/lastpass-cli/lpass.c:84:23: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
                printf("  %s %s\n", basename(ARGV[0]), commands[i].usage);
                          ~~        ^~~~~~~~~~~~~~~~~
                          %d
2 warnings generated.
[ 78%] Building C object CMakeFiles/lpass.dir/notes.c.o
[ 80%] Building C object CMakeFiles/lpass.dir/password.c.o
[ 83%] Building C object CMakeFiles/lpass.dir/pbkdf2.c.o
[ 85%] Building C object CMakeFiles/lpass.dir/process.c.o
[ 88%] Building C object CMakeFiles/lpass.dir/session.c.o
[ 90%] Building C object CMakeFiles/lpass.dir/terminal.c.o
[ 92%] Building C object CMakeFiles/lpass.dir/upload-queue.c.o
[ 95%] Building C object CMakeFiles/lpass.dir/util.c.o
[ 97%] Building C object CMakeFiles/lpass.dir/xml.c.o
[100%] Linking C executable lpass
[100%] Built target lpass
$ ./build/lpass 
Usage:
  ./build/lpass {--help|--version}
Segmentation fault: 11

Versions:

$ sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.13.6
BuildVersion:	17G5019
$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

I'll double check on my other laptop running 10.14 too.

@msbit
Copy link
Contributor Author

msbit commented Mar 13, 2019

Yep, same with latest macOS:

$ sw_vers 
ProductName:	Mac OS X
ProductVersion:	10.14.3
BuildVersion:	18D109
$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
$ g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

@GPaulovics
Copy link
Contributor

Now this is weird. With the latest master I can reproduce the issue as well. But if I go back to https://github.com/lastpass/lastpass-cli/tree/f0f4e83c43ef793c40da57cc746052573a96d914 lpass --help works just fine. Did I introduce something that could have broken the build? I don't see any code change besides the folder creation in config. And I'm pretty sure that does not cause issues like this.

@msbit
Copy link
Contributor Author

msbit commented Mar 13, 2019

And same output under OpenBSD:

$ make
mkdir -p build && cd build && cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr -DCMAKE_INSTALL_MANDIR:PATH=/usr/share/man ..
-- The C compiler identification is Clang 6.0.0
-- The CXX compiler identification is Clang 6.0.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.27.1") 
-- Found LibXml2: /usr/local/lib/libxml2.so.16.1 (found version "2.9.8") 
-- Found OpenSSL: /usr/lib/libcrypto.so.44.1 (found version "2.0.0") 
-- Found CURL: /usr/local/lib/libcurl.so.25.17 (found version "7.61.1") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/tom/lastpass-cli/build
make -C build all
Scanning dependencies of target lpass
[  2%] Building C object CMakeFiles/lpass.dir/agent.c.o
[  4%] Building C object CMakeFiles/lpass.dir/blob.c.o
[  7%] Building C object CMakeFiles/lpass.dir/cipher.c.o
[  9%] Building C object CMakeFiles/lpass.dir/clipboard.c.o
[ 11%] Building C object CMakeFiles/lpass.dir/cmd-add.c.o
[ 14%] Building C object CMakeFiles/lpass.dir/cmd-duplicate.c.o
[ 16%] Building C object CMakeFiles/lpass.dir/cmd-edit.c.o
[ 19%] Building C object CMakeFiles/lpass.dir/cmd-export.c.o
[ 21%] Building C object CMakeFiles/lpass.dir/cmd-generate.c.o
[ 23%] Building C object CMakeFiles/lpass.dir/cmd-import.c.o
[ 26%] Building C object CMakeFiles/lpass.dir/cmd-login.c.o
[ 28%] Building C object CMakeFiles/lpass.dir/cmd-logout.c.o
[ 30%] Building C object CMakeFiles/lpass.dir/cmd-ls.c.o
[ 33%] Building C object CMakeFiles/lpass.dir/cmd-mv.c.o
[ 35%] Building C object CMakeFiles/lpass.dir/cmd-passwd.c.o
[ 38%] Building C object CMakeFiles/lpass.dir/cmd-rm.c.o
[ 40%] Building C object CMakeFiles/lpass.dir/cmd-share.c.o
[ 42%] Building C object CMakeFiles/lpass.dir/cmd-show.c.o
[ 45%] Building C object CMakeFiles/lpass.dir/cmd-status.c.o
[ 47%] Building C object CMakeFiles/lpass.dir/cmd-sync.c.o
[ 50%] Building C object CMakeFiles/lpass.dir/cmd.c.o
[ 52%] Building C object CMakeFiles/lpass.dir/config.c.o
[ 54%] Building C object CMakeFiles/lpass.dir/edit.c.o
[ 57%] Building C object CMakeFiles/lpass.dir/endpoints-login.c.o
[ 59%] Building C object CMakeFiles/lpass.dir/endpoints-share.c.o
[ 61%] Building C object CMakeFiles/lpass.dir/endpoints.c.o
[ 64%] Building C object CMakeFiles/lpass.dir/format.c.o
[ 66%] Building C object CMakeFiles/lpass.dir/http.c.o
[ 69%] Building C object CMakeFiles/lpass.dir/json-format.c.o
[ 71%] Building C object CMakeFiles/lpass.dir/kdf.c.o
[ 73%] Building C object CMakeFiles/lpass.dir/log.c.o
[ 76%] Building C object CMakeFiles/lpass.dir/lpass.c.o
/home/tom/lastpass-cli/lpass.c:84:23: warning: implicit declaration of function 'basename' is invalid in C99 [-Wimplicit-function-declaration]
                printf("  %s %s\n", basename(ARGV[0]), commands[i].usage);
                                    ^
/home/tom/lastpass-cli/lpass.c:84:23: warning: format specifies type 'char *' but the argument has type 'int' [-Wformat]
                printf("  %s %s\n", basename(ARGV[0]), commands[i].usage);
                          ~~        ^~~~~~~~~~~~~~~~~
                          %d
2 warnings generated.
[ 78%] Building C object CMakeFiles/lpass.dir/notes.c.o
[ 80%] Building C object CMakeFiles/lpass.dir/password.c.o
[ 83%] Building C object CMakeFiles/lpass.dir/pbkdf2.c.o
[ 85%] Building C object CMakeFiles/lpass.dir/process.c.o
[ 88%] Building C object CMakeFiles/lpass.dir/session.c.o
[ 90%] Building C object CMakeFiles/lpass.dir/terminal.c.o
[ 92%] Building C object CMakeFiles/lpass.dir/upload-queue.c.o
/home/tom/lastpass-cli/upload-queue.c:89:45: warning: format specifies type 'unsigned long' but the argument has type 'time_t' (aka 'long long') [-Wformat]
                xasprintf(&name, "upload-queue/%lu%04lu", time(NULL), serial);
                                               ~~~        ^~~~~~~~~~
                                               %lld
1 warning generated.
[ 95%] Building C object CMakeFiles/lpass.dir/util.c.o
[ 97%] Building C object CMakeFiles/lpass.dir/xml.c.o
[100%] Linking C executable lpass
/usr/local/lib/libxml2.so.16.1: warning: strcpy() is almost always misused, please use strlcpy()
/usr/local/lib/libxml2.so.16.1: warning: sprintf() is often misused, please use snprintf()
/usr/local/lib/libxml2.so.16.1: warning: strcat() is almost always misused, please use strlcat()
[100%] Built target lpass
$ ./build/lpass                                                                                                                                                                                     
Usage:
  ./build/lpass {--help|--version}
Segmentation fault (core dumped)

Versions:

$ uname -a
OpenBSD openbsd.my.domain 6.4 GENERIC#349 amd64
$ gcc -v
Reading specs from /usr/lib/gcc-lib/amd64-unknown-openbsd6.4/4.2.1/specs
Target: amd64-unknown-openbsd6.4
Configured with: OpenBSD/amd64 system compiler
Thread model: posix
gcc version 4.2.1 20070719 
$ g++ -v
Reading specs from /usr/lib/gcc-lib/amd64-unknown-openbsd6.4/4.2.1/specs
Target: amd64-unknown-openbsd6.4
Configured with: OpenBSD/amd64 system compiler
Thread model: posix
gcc version 4.2.1 20070719

@msbit
Copy link
Contributor Author

msbit commented Mar 13, 2019

Ah sorry @GPaulovics, I missed your comment.

Looks like 4161de9 introduced using basename, and building df182dd (last master commit before) doesn't cause the issue, so it's probably that.

@GPaulovics
Copy link
Contributor

Yeah, you are totally right.
Thank you again for your help.

@GPaulovics GPaulovics merged commit 858db57 into lastpass:master Mar 13, 2019
waterkip added a commit to waterkip/lastpass-cli that referenced this pull request Mar 14, 2019
In order to prevent weird version discussions (see lastpass#481 for such an
example) this changeset tries to do versioning the same way as the git
project does this.

Some caveats apply:

  1) Maintainers *must* use annotated tags. Release 1.3.1 is not
     annotated for example.

  2) Maintainers *must* can use a `version` file in the repo to override
     any logic. This will generate a "static" version.

  3) Maintainers *must* bump the version in `LASTPASS-VERSION-GEN` after
     a release.

Some benefits apply too:

  1) We can see clearly at which version the client was build
  2) We can see if it was a "dirty" build

   ```
   $ lpass --version
   LastPass CLI v1.3.0.34.g5bf38bc.dirty
   ```

Signed-off-by: Wesley Schwengle <wesley@schwengle.net>
@waterkip waterkip mentioned this pull request Mar 14, 2019
@msbit msbit deleted the bsd-basename branch March 15, 2019 03:20
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants