@@ -294,6 +294,7 @@ void process_vnode(struct lsof_context *ctx, struct kinfo_file *kf,
294294 char * dp , * np , tbuf [1024 ];
295295 struct null_node nu ;
296296 int sc = 0 ;
297+ size_t vfs_fsname_len , vfs_dir_len , vfs_path_len ;
297298#endif /* defined(HASNULLFS) */
298299
299300 int proc_pid = 0 ;
@@ -441,10 +442,15 @@ void process_vnode(struct lsof_context *ctx, struct kinfo_file *kf,
441442 * /original_mountpoint/path/to/file
442443 * ------fsname--------
443444 */
444- memmove (& vfs_path [strlen (vfs -> fsname ) + 1 ],
445- & vfs_path [strlen (vfs -> dir ) + 1 ],
446- strlen (vfs_path ) - strlen (vfs -> dir ) + 1 );
447- memcpy (vfs_path , vfs -> fsname , strlen (vfs -> fsname ));
445+ vfs_fsname_len = strlen (vfs -> fsname );
446+ vfs_dir_len = strlen (vfs -> dir );
447+ vfs_path_len = strlen (vfs_path );
448+
449+ if (vfs_path_len >= vfs_dir_len ) {
450+ memmove (& vfs_path [vfs_fsname_len ], & vfs_path [vfs_dir_len ],
451+ vfs_path_len - vfs_dir_len + 1 );
452+ memcpy (vfs_path , vfs -> fsname , vfs_fsname_len );
453+ }
448454 goto process_overlaid_node ;
449455#endif /* defined(HASNULLFS) */
450456 }
0 commit comments