ldd equivalent which fail when library not found

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












Assume I perform ldd /bin/ls with the pthread library removed. I obtain



linux-vdso.so.1 (0x00007ffcc3563000)

libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f87e5459000)
libcap.so.2 => /lib64/libcap.so.2 (0x00007f87e5254000)
libc.so.6 => /lib64/libc.so.6 (0x00007f87e4e92000)
libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f87e4c22000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f87e4a1e000)
/lib64/ld-linux-x86-64.so.2 (0x00005574bf12e000)
libattr.so.1 => /lib64/libattr.so.1 (0x00007f87e4817000)
libpthread.so.0 => not found


The return code is zero. Is there a command returning an error in this case? Something similar to



#!/bin/bash
if [[ ! -z $(ldd $target | grep 'not found') ]]; then
exit 1
fi









share|improve this question









New contributor




UmNyobe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    1
    down vote

    favorite












    Assume I perform ldd /bin/ls with the pthread library removed. I obtain



    linux-vdso.so.1 (0x00007ffcc3563000)

    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f87e5459000)
    libcap.so.2 => /lib64/libcap.so.2 (0x00007f87e5254000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f87e4e92000)
    libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f87e4c22000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f87e4a1e000)
    /lib64/ld-linux-x86-64.so.2 (0x00005574bf12e000)
    libattr.so.1 => /lib64/libattr.so.1 (0x00007f87e4817000)
    libpthread.so.0 => not found


    The return code is zero. Is there a command returning an error in this case? Something similar to



    #!/bin/bash
    if [[ ! -z $(ldd $target | grep 'not found') ]]; then
    exit 1
    fi









    share|improve this question









    New contributor




    UmNyobe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      Assume I perform ldd /bin/ls with the pthread library removed. I obtain



      linux-vdso.so.1 (0x00007ffcc3563000)

      libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f87e5459000)
      libcap.so.2 => /lib64/libcap.so.2 (0x00007f87e5254000)
      libc.so.6 => /lib64/libc.so.6 (0x00007f87e4e92000)
      libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f87e4c22000)
      libdl.so.2 => /lib64/libdl.so.2 (0x00007f87e4a1e000)
      /lib64/ld-linux-x86-64.so.2 (0x00005574bf12e000)
      libattr.so.1 => /lib64/libattr.so.1 (0x00007f87e4817000)
      libpthread.so.0 => not found


      The return code is zero. Is there a command returning an error in this case? Something similar to



      #!/bin/bash
      if [[ ! -z $(ldd $target | grep 'not found') ]]; then
      exit 1
      fi









      share|improve this question









      New contributor




      UmNyobe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      Assume I perform ldd /bin/ls with the pthread library removed. I obtain



      linux-vdso.so.1 (0x00007ffcc3563000)

      libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f87e5459000)
      libcap.so.2 => /lib64/libcap.so.2 (0x00007f87e5254000)
      libc.so.6 => /lib64/libc.so.6 (0x00007f87e4e92000)
      libpcre.so.1 => /lib64/libpcre.so.1 (0x00007f87e4c22000)
      libdl.so.2 => /lib64/libdl.so.2 (0x00007f87e4a1e000)
      /lib64/ld-linux-x86-64.so.2 (0x00005574bf12e000)
      libattr.so.1 => /lib64/libattr.so.1 (0x00007f87e4817000)
      libpthread.so.0 => not found


      The return code is zero. Is there a command returning an error in this case? Something similar to



      #!/bin/bash
      if [[ ! -z $(ldd $target | grep 'not found') ]]; then
      exit 1
      fi






      dynamic-linking return-status






      share|improve this question









      New contributor




      UmNyobe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      UmNyobe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 10 hours ago









      Jeff Schaller

      35.7k952119




      35.7k952119






      New contributor




      UmNyobe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 10 hours ago









      UmNyobe

      1063




      1063




      New contributor




      UmNyobe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      UmNyobe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      UmNyobe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          Take care with ldd on linux; it's just a bash script which, at least on older systems, will run the given program with LD_TRACE_LOADED_OBJECTS=1 in its environment.



          This means that if the program has other interpreter than /lib64,32/ld-*, that program will be run with your target as its first argument, even if you didn't mean to do it. If you run ldd on an executable owned by some other user, that user will own you instead.



          You can check what interpreter is defined in the ELF headers with readelf -l "$target" | grep interpreter.



          On newer systems, ldd has been changed to pass the target as argument to an interpreter taken from a list of 'good' interpreters (eg. /lib64/ld-linux.so.2 target); I don't find that convincing, but it's up to you to make the determination if that's safe enough.



          If you find all that acceptable, the simplest way to do it is:



          if ldd "$target" | grep -q 'not found'; then
          echo >&2 "$target is missing dependencies"
          exit 1
          fi


          If called in 'trace mode' (as from ldd), the default dynamic loader on linux will always exit with a 0 status, and there's no way to change that via command line switches or environment variables; you'll have to change its source code.






          share|improve this answer






















          • See also CVE-2009-5064.
            – Stephen Kitt
            9 hours ago










          • Just out of curiosity, what would it take for you to find “that” convincing?
            – Stephen Kitt
            8 hours ago










          • Nothing -- ld.so is complex enough so that's no safe way to run in 'dry' mode with unknown binaries. Of course you won't find spectacular exploits against it, because it wasn't a real security issue in the first place, so it's not worth bothering with; no sysadmin worth their two bits would use ldd against random binaries.
            – qubert
            8 hours ago











          • From the ldd man page ... safer to use objdump -p /path/to/program |grep NEEDED instead.
            – RubberStamp
            1 hour ago










          • @RubberStamp compare the output of objdump -p /usr/bin/xeyes | grep NEEDED to ldd /usr/bin/xeyes. Shared objects depend on other shared objects.
            – qubert
            1 hour ago










          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          UmNyobe is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481250%2fldd-equivalent-which-fail-when-library-not-found%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote













          Take care with ldd on linux; it's just a bash script which, at least on older systems, will run the given program with LD_TRACE_LOADED_OBJECTS=1 in its environment.



          This means that if the program has other interpreter than /lib64,32/ld-*, that program will be run with your target as its first argument, even if you didn't mean to do it. If you run ldd on an executable owned by some other user, that user will own you instead.



          You can check what interpreter is defined in the ELF headers with readelf -l "$target" | grep interpreter.



          On newer systems, ldd has been changed to pass the target as argument to an interpreter taken from a list of 'good' interpreters (eg. /lib64/ld-linux.so.2 target); I don't find that convincing, but it's up to you to make the determination if that's safe enough.



          If you find all that acceptable, the simplest way to do it is:



          if ldd "$target" | grep -q 'not found'; then
          echo >&2 "$target is missing dependencies"
          exit 1
          fi


          If called in 'trace mode' (as from ldd), the default dynamic loader on linux will always exit with a 0 status, and there's no way to change that via command line switches or environment variables; you'll have to change its source code.






          share|improve this answer






















          • See also CVE-2009-5064.
            – Stephen Kitt
            9 hours ago










          • Just out of curiosity, what would it take for you to find “that” convincing?
            – Stephen Kitt
            8 hours ago










          • Nothing -- ld.so is complex enough so that's no safe way to run in 'dry' mode with unknown binaries. Of course you won't find spectacular exploits against it, because it wasn't a real security issue in the first place, so it's not worth bothering with; no sysadmin worth their two bits would use ldd against random binaries.
            – qubert
            8 hours ago











          • From the ldd man page ... safer to use objdump -p /path/to/program |grep NEEDED instead.
            – RubberStamp
            1 hour ago










          • @RubberStamp compare the output of objdump -p /usr/bin/xeyes | grep NEEDED to ldd /usr/bin/xeyes. Shared objects depend on other shared objects.
            – qubert
            1 hour ago














          up vote
          1
          down vote













          Take care with ldd on linux; it's just a bash script which, at least on older systems, will run the given program with LD_TRACE_LOADED_OBJECTS=1 in its environment.



          This means that if the program has other interpreter than /lib64,32/ld-*, that program will be run with your target as its first argument, even if you didn't mean to do it. If you run ldd on an executable owned by some other user, that user will own you instead.



          You can check what interpreter is defined in the ELF headers with readelf -l "$target" | grep interpreter.



          On newer systems, ldd has been changed to pass the target as argument to an interpreter taken from a list of 'good' interpreters (eg. /lib64/ld-linux.so.2 target); I don't find that convincing, but it's up to you to make the determination if that's safe enough.



          If you find all that acceptable, the simplest way to do it is:



          if ldd "$target" | grep -q 'not found'; then
          echo >&2 "$target is missing dependencies"
          exit 1
          fi


          If called in 'trace mode' (as from ldd), the default dynamic loader on linux will always exit with a 0 status, and there's no way to change that via command line switches or environment variables; you'll have to change its source code.






          share|improve this answer






















          • See also CVE-2009-5064.
            – Stephen Kitt
            9 hours ago










          • Just out of curiosity, what would it take for you to find “that” convincing?
            – Stephen Kitt
            8 hours ago










          • Nothing -- ld.so is complex enough so that's no safe way to run in 'dry' mode with unknown binaries. Of course you won't find spectacular exploits against it, because it wasn't a real security issue in the first place, so it's not worth bothering with; no sysadmin worth their two bits would use ldd against random binaries.
            – qubert
            8 hours ago











          • From the ldd man page ... safer to use objdump -p /path/to/program |grep NEEDED instead.
            – RubberStamp
            1 hour ago










          • @RubberStamp compare the output of objdump -p /usr/bin/xeyes | grep NEEDED to ldd /usr/bin/xeyes. Shared objects depend on other shared objects.
            – qubert
            1 hour ago












          up vote
          1
          down vote










          up vote
          1
          down vote









          Take care with ldd on linux; it's just a bash script which, at least on older systems, will run the given program with LD_TRACE_LOADED_OBJECTS=1 in its environment.



          This means that if the program has other interpreter than /lib64,32/ld-*, that program will be run with your target as its first argument, even if you didn't mean to do it. If you run ldd on an executable owned by some other user, that user will own you instead.



          You can check what interpreter is defined in the ELF headers with readelf -l "$target" | grep interpreter.



          On newer systems, ldd has been changed to pass the target as argument to an interpreter taken from a list of 'good' interpreters (eg. /lib64/ld-linux.so.2 target); I don't find that convincing, but it's up to you to make the determination if that's safe enough.



          If you find all that acceptable, the simplest way to do it is:



          if ldd "$target" | grep -q 'not found'; then
          echo >&2 "$target is missing dependencies"
          exit 1
          fi


          If called in 'trace mode' (as from ldd), the default dynamic loader on linux will always exit with a 0 status, and there's no way to change that via command line switches or environment variables; you'll have to change its source code.






          share|improve this answer














          Take care with ldd on linux; it's just a bash script which, at least on older systems, will run the given program with LD_TRACE_LOADED_OBJECTS=1 in its environment.



          This means that if the program has other interpreter than /lib64,32/ld-*, that program will be run with your target as its first argument, even if you didn't mean to do it. If you run ldd on an executable owned by some other user, that user will own you instead.



          You can check what interpreter is defined in the ELF headers with readelf -l "$target" | grep interpreter.



          On newer systems, ldd has been changed to pass the target as argument to an interpreter taken from a list of 'good' interpreters (eg. /lib64/ld-linux.so.2 target); I don't find that convincing, but it's up to you to make the determination if that's safe enough.



          If you find all that acceptable, the simplest way to do it is:



          if ldd "$target" | grep -q 'not found'; then
          echo >&2 "$target is missing dependencies"
          exit 1
          fi


          If called in 'trace mode' (as from ldd), the default dynamic loader on linux will always exit with a 0 status, and there's no way to change that via command line switches or environment variables; you'll have to change its source code.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 8 hours ago

























          answered 9 hours ago









          qubert

          5566




          5566











          • See also CVE-2009-5064.
            – Stephen Kitt
            9 hours ago










          • Just out of curiosity, what would it take for you to find “that” convincing?
            – Stephen Kitt
            8 hours ago










          • Nothing -- ld.so is complex enough so that's no safe way to run in 'dry' mode with unknown binaries. Of course you won't find spectacular exploits against it, because it wasn't a real security issue in the first place, so it's not worth bothering with; no sysadmin worth their two bits would use ldd against random binaries.
            – qubert
            8 hours ago











          • From the ldd man page ... safer to use objdump -p /path/to/program |grep NEEDED instead.
            – RubberStamp
            1 hour ago










          • @RubberStamp compare the output of objdump -p /usr/bin/xeyes | grep NEEDED to ldd /usr/bin/xeyes. Shared objects depend on other shared objects.
            – qubert
            1 hour ago
















          • See also CVE-2009-5064.
            – Stephen Kitt
            9 hours ago










          • Just out of curiosity, what would it take for you to find “that” convincing?
            – Stephen Kitt
            8 hours ago










          • Nothing -- ld.so is complex enough so that's no safe way to run in 'dry' mode with unknown binaries. Of course you won't find spectacular exploits against it, because it wasn't a real security issue in the first place, so it's not worth bothering with; no sysadmin worth their two bits would use ldd against random binaries.
            – qubert
            8 hours ago











          • From the ldd man page ... safer to use objdump -p /path/to/program |grep NEEDED instead.
            – RubberStamp
            1 hour ago










          • @RubberStamp compare the output of objdump -p /usr/bin/xeyes | grep NEEDED to ldd /usr/bin/xeyes. Shared objects depend on other shared objects.
            – qubert
            1 hour ago















          See also CVE-2009-5064.
          – Stephen Kitt
          9 hours ago




          See also CVE-2009-5064.
          – Stephen Kitt
          9 hours ago












          Just out of curiosity, what would it take for you to find “that” convincing?
          – Stephen Kitt
          8 hours ago




          Just out of curiosity, what would it take for you to find “that” convincing?
          – Stephen Kitt
          8 hours ago












          Nothing -- ld.so is complex enough so that's no safe way to run in 'dry' mode with unknown binaries. Of course you won't find spectacular exploits against it, because it wasn't a real security issue in the first place, so it's not worth bothering with; no sysadmin worth their two bits would use ldd against random binaries.
          – qubert
          8 hours ago





          Nothing -- ld.so is complex enough so that's no safe way to run in 'dry' mode with unknown binaries. Of course you won't find spectacular exploits against it, because it wasn't a real security issue in the first place, so it's not worth bothering with; no sysadmin worth their two bits would use ldd against random binaries.
          – qubert
          8 hours ago













          From the ldd man page ... safer to use objdump -p /path/to/program |grep NEEDED instead.
          – RubberStamp
          1 hour ago




          From the ldd man page ... safer to use objdump -p /path/to/program |grep NEEDED instead.
          – RubberStamp
          1 hour ago












          @RubberStamp compare the output of objdump -p /usr/bin/xeyes | grep NEEDED to ldd /usr/bin/xeyes. Shared objects depend on other shared objects.
          – qubert
          1 hour ago




          @RubberStamp compare the output of objdump -p /usr/bin/xeyes | grep NEEDED to ldd /usr/bin/xeyes. Shared objects depend on other shared objects.
          – qubert
          1 hour ago










          UmNyobe is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          UmNyobe is a new contributor. Be nice, and check out our Code of Conduct.












          UmNyobe is a new contributor. Be nice, and check out our Code of Conduct.











          UmNyobe is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481250%2fldd-equivalent-which-fail-when-library-not-found%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)