ash: in tryexec(), ensure we don't try to run embedded scripts as applets
[oweals/busybox.git] / procps / lsof.c
index 7e0ffa4e5ecb6035ee0bbaec973b5f93eed5b145..4917cf8999759a4fb6f3b22b59074d9fd645681e 100644 (file)
@@ -6,13 +6,12 @@
  *
  * Licensed under GPLv2, see file LICENSE in this source tree.
  */
-
 //config:config LSOF
-//config:      bool "lsof"
+//config:      bool "lsof (3.6 kb)"
 //config:      default y
 //config:      help
-//config:        Show open files in the format of:
-//config:        PID <TAB> /path/to/executable <TAB> /path/to/opened/file
+//config:      Show open files in the format of:
+//config:      PID <TAB> /path/to/executable <TAB> /path/to/opened/file
 
 //applet:IF_LSOF(APPLET(lsof, BB_DIR_USR_BIN, BB_SUID_DROP))
 
@@ -61,9 +60,12 @@ int lsof_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
                d_fd = opendir(name);
                if (d_fd) {
                        while ((entry = readdir(d_fd)) != NULL) {
-                               if (entry->d_type == DT_LNK) {
-                                       safe_strncpy(name + baseofs, entry->d_name, 10);
-                                       fdlink = xmalloc_readlink(name);
+                               /* Skip entries '.' and '..' (and any hidden file) */
+                               if (entry->d_name[0] == '.')
+                                       continue;
+
+                               safe_strncpy(name + baseofs, entry->d_name, 10);
+                               if ((fdlink = xmalloc_readlink(name)) != NULL) {
                                        printf("%d\t%s\t%s\n", proc->pid, proc->exe, fdlink);
                                        free(fdlink);
                                }