"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
more ftruncate + lseek
To:
gameoftrees@openbsd.org
Date:
Mon, 21 Jul 2025 14:57:29 +0200

Download raw body.

Thread
This fixes more instances of missing seek after truncate which I
could find with grep. Similar to the issue reported by Aaron.
Most of them seem harmless. Fix them anyway for consistency.

M  gotd/session_write.c                                     |  2+  0-
M  gotsysd/libexec/gotsys-repo-create/gotsys-repo-create.c  |  4+  0-
M  gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c    |  2+  0-
M  lib/repository.c                                         |  4+  0-

4 files changed, 12 insertions(+), 0 deletions(-)

commit - 5344003c15642e6213a5e80e2d1359a9d1c564bf
commit + 1fd758ac622ef91709d8e5c88802828925931182
blob - 6a93d428b645fa7449b875471e7683b83ab8a090
blob + c9a965bc2a4faed953e12c6a78fc77fa2d52af85
--- gotd/session_write.c
+++ gotd/session_write.c
@@ -232,6 +232,8 @@ request_gotsys_conf(struct gotd_imsgev *iev)
 
 	if (ftruncate(gotd_session.content_fd, 0L) == -1)
 		return got_error_from_errno("ftruncate");
+	if (lseek(gotd_session.content_fd, 0L, SEEK_SET) == -1)
+		return got_error_from_errno("lseek");
 	
 	len = sizeof(content_req) + strlen(refname) + strlen(path);
 	wbuf = imsg_create(&iev->ibuf, GOTD_IMSG_PACKFILE_GET_CONTENT,
blob - 108f6cc7b0d24fd077c34f5968ef71d639e11322
blob + 0022bec28505fa335dd8deeebaaefa71b090f25f
--- gotsysd/libexec/gotsys-repo-create/gotsys-repo-create.c
+++ gotsysd/libexec/gotsys-repo-create/gotsys-repo-create.c
@@ -171,6 +171,10 @@ set_head_ref(int repos_dir_fd, const char *repo_name, 
 		err = got_error_from_errno2("ftruncate", relpath);
 		goto done;
 	}
+	if (lseek(fd, 0L, SEEK_SET) == -1) {
+		err = got_error_from_errno2("lseek", relpath);
+		goto done;
+	}
 
 	w = write(fd, content, content_len);
 	if (w == -1)
blob - 7996125cee248ac4fb8218d775a7a8b6a3f47ddf
blob + 67115ca0e835945a579386472c68a9561804ee5c
--- gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c
+++ gotsysd/libexec/gotsys-write-conf/gotsys-write-conf.c
@@ -333,6 +333,8 @@ write_gotd_conf(void)
 
 	if (ftruncate(gotd_conf_tmpfd, 0) == -1)
 		return got_error_from_errno("ftruncate");
+	if (lseek(gotd_conf_tmpfd, 0L, SEEK_SET) == -1)
+		return got_error_from_errno("lseek");
 
 	if (clock_gettime(CLOCK_MONOTONIC, &now) == -1)
 		return got_error_from_errno("clock_gettime");
blob - 175996e19e6d5ed9c58c09fb0722aef4dab5cd75
blob + 92459dcbba069990e1f2f04edf7daaaf14322e9b
--- lib/repository.c
+++ lib/repository.c
@@ -1606,8 +1606,12 @@ got_repo_cache_pack(struct got_pack **packp, struct go
 			return err;
 		if (ftruncate(repo->packs[i].basefd, 0L) == -1)
 			return got_error_from_errno("ftruncate");
+		if (lseek(repo->packs[i].basefd, 0L, SEEK_SET) == -1)
+			return got_error_from_errno("lseek");
 		if (ftruncate(repo->packs[i].accumfd, 0L) == -1)
 			return got_error_from_errno("ftruncate");
+		if (lseek(repo->packs[i].accumfd, 0L, SEEK_SET) == -1)
+			return got_error_from_errno("lseek");
 	}
 
 	if (i != 0) {