johnmehr / gitup

A minimalist, dependency-free FreeBSD program to clone/pull Git repositories.
BSD 2-Clause "Simplified" License
51 stars 9 forks source link

Bus error #79

Closed nunotexbsd closed 2 years ago

nunotexbsd commented 2 years ago

Hello,

Recently I've received a PR with a patch from Eugene Grosbein:

"fix SIGBUS

This commit changed contrib/bc/configure from regular file to the symlink to configure.sh

https://cgit.freebsd.org/src/commit/contrib/bc/configure?h=stable/12&id=e32b8140f4e7de93eb7d571e7fcb2bf9db6c97a3

gitup-0.96 crashes with SIGBUS trying to repair or update local repository copy when old (pre-commit) tree is present:

1) The function save_repairs() contains logic error calling calculate_file_hash() function to calculate hash of local file passing file mode of an object from the repository. The function calculate_file_hash() assumes that mode describes local file, calls readlink() for supposed symlink, but readlink() returns -1 with errno=EINVAL. This returned value ("uint32_t bytes_read" assigned with -1) is used in a statement:

temp_path[bytes_read] = '\0';

SIGBUS is imminent.

2) With this bug fixed by passing real mode of local file to calculate_file_hash(), the function save_file() still does not handle the situation because it halts on any error on symlink creation including EEXIST. Instead, it should remove old file preventing symlink creation and retry.

The patch solving the problem is attached. "

Patch and more details available at PR 261307

Could you take a look at this?

Thanks,

Nuno Teixeira

johnmehr commented 2 years ago

I just committed his patch. Thank you!

nunotexbsd commented 2 years ago

Thank you .)

grahamperrin commented 2 years ago

Ah, I also encountered a bus error. Can't recall whether it was on the same machine as #82, but I (lazily) removed the contents of /usr/src and /var/db/gitup.