From: Stefan Sperling Subject: Re: got/tog segfault with corrupted (?) checkout To: Theo Buehler Cc: Matthias Schmidt , gameoftrees@openbsd.org Date: Wed, 27 Dec 2023 13:22:48 +0100 On Wed, Dec 27, 2023 at 01:13:22PM +0100, Theo Buehler wrote: > does /usr/ports/.got/base_commit happen to be empty? Yes, the problem can be reproduced with these steps: $ rm .got/base-commit $ touch .got/base-commit $ got up Segmentation fault (core dumped) Below is the obvious fix: $ got up got: /tmp/test-wt/.got/base-commit: bad worktree meta data diff /home/stsp/src/got commit - 1e63031fcde1dee62ea14a73d4bf3638632e691b path + /home/stsp/src/got blob - cbce00f57c0999cd56f639776fdc0be83f732cf9 file + lib/worktree_open.c --- lib/worktree_open.c +++ lib/worktree_open.c @@ -80,6 +80,10 @@ read_meta_file(char **content, const char *path_got, c err = got_error_from_errno2("fstat", path); goto done; } + if (sb.st_size == 0) { + err = got_error_path(path, GOT_ERR_WORKTREE_META); + goto done; + } *content = calloc(1, sb.st_size); if (*content == NULL) { err = got_error_from_errno("calloc");