1
0
mirror of https://github.com/openbsd/src.git synced 2026-05-01 17:46:35 +00:00

Fix warning: 'snprintf' will always be truncated

When make -t touched an archive member, snprintf(_, 12, "%-12ld", _)
truncated 13 bytes to 12.  Fix is to snprintf() 13 bytes in a temp
buffer, then memcpy() 12 without the '\0'.

Also change "%-12ld" to "%-12lld", (long long)time_t.

from espie@ ok tb@
This commit is contained in:
gkoehler
2025-09-28 16:22:51 +00:00
parent 4a3a3ef47d
commit 3abf7a093b

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: arch.c,v 1.94 2023/09/04 11:35:11 espie Exp $ */
/* $OpenBSD: arch.c,v 1.95 2025/09/28 16:22:51 gkoehler Exp $ */
/* $NetBSD: arch.c,v 1.17 1996/11/06 17:58:59 christos Exp $ */
/*
@@ -836,8 +836,10 @@ ArchTouch(const char *archive, const char *member)
arch = ArchFindMember(archive, member, &arHeader, "r+");
if (arch != NULL) {
snprintf(arHeader.ar_date, sizeof(arHeader.ar_date),
"%-12ld", (long) time(NULL));
char temp[sizeof(arHeader.ar_date)+1];
snprintf(temp, sizeof(temp), "%-12lld", (long long)time(NULL));
memcpy(arHeader.ar_date, temp, sizeof(arHeader.ar_date));
if (fseek(arch, -sizeof(struct ar_hdr), SEEK_CUR) == 0)
(void)fwrite(&arHeader, sizeof(struct ar_hdr), 1, arch);
fclose(arch);