Skip to content

Commit 4d4a01c

Browse files
committed
[freebsd] fix segfault
- FreeBSD bug#267760 - Author Ronald Klop
1 parent 55deb7c commit 4d4a01c

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

00DIST

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5578,6 +5578,8 @@ Supplement Regenerated the 4.04 distribution to correct a non-
55785578
of liblsof. (@subnut, #300)
55795579

55805580
4.9?.? ????????? ??, ????
5581+
5582+
[freebsd] fix segfault from fs info (FreeBSD bug 267760)
55815583

55825584
Vic Abell <abe@purdue.edu>
55835585
July 14, 2018

docs/credits.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ provided test systems where I was able to do development work.
255255
Steve Kirsch
256256
Philip Kizer
257257
Thomas Klausner
258+
Ronald Klop
258259
Roger Klorese
259260
Peter Klosky
260261
Przemek Klosowski

lib/dialects/freebsd/dnode.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)