commit 66c889b39514153efd49214703ef06a538eb2ee4 from: James Cook via: Thomas Adam date: Sat Apr 19 18:23:10 2025 UTC Explicitly test S_ISREG in parse_ref_file parse_ref_file previously detected directories in the refs directory by trying to read and checking for EISDIR. This doesn't work on NetBSD, and the S_ISREG should exclude other kinds of non-regular files. ok stsp@ commit - b46517d07b921397f37d269bb82fb62912df177d commit + 66c889b39514153efd49214703ef06a538eb2ee4 blob - 5d1c2e817373f8450d2af8dc48ea04aeada52476 blob + 053e136878b01169876161b848bd4dc87fd8ac43 --- lib/reference.c +++ lib/reference.c @@ -204,6 +204,12 @@ parse_ref_file(struct got_reference **ref, const char } if (fstat(fileno(f), &sb) == -1) { err = got_error_from_errno2("fstat", abspath); + goto done; + } + if (!S_ISREG(sb.st_mode)) { + err = got_error(GOT_ERR_NOT_REF); + if (lock) + got_lockfile_unlock(lf, -1); goto done; } @@ -212,9 +218,7 @@ parse_ref_file(struct got_reference **ref, const char if (feof(f)) err = NULL; /* ignore empty files (could be locks) */ else { - if (errno == EISDIR) - err = got_error(GOT_ERR_NOT_REF); - else if (ferror(f)) + if (ferror(f)) err = got_ferror(f, GOT_ERR_IO); else err = got_error_from_errno2("getline", abspath);