commit e896de0dbd9971fbc7969f0df170b4a495b4cd28 from: James Cook date: Fri Apr 04 02:10:05 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 - 25005dc3b0e6dc5d627ed020f3ef1ef039b94a4f commit + e896de0dbd9971fbc7969f0df170b4a495b4cd28 blob - 6737bf650daa76886cbc9ad90d24404103479dd7 blob + 90462626d8b4280e7a38aa3e03f64545013c53f6 --- lib/reference.c +++ lib/reference.c @@ -206,6 +206,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; } @@ -214,9 +220,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);