upstream: prefer fstat to stat when it's trivial to do so

OpenBSD-Commit-ID: 3af5548ba2112045db392a14c959ca309605bdb9
This commit is contained in:
djm@openbsd.org authored and Damien Miller committed 2026-07-21 15:22:55 +10:00
1 parent cadefc724f
commit 1bf5871aea
1 file changed
+2 -2
+2 -2
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: authfile.c,v 1.151 2026/06/29 09:14:25 djm Exp $ */
/* $OpenBSD: authfile.c,v 1.152 2026/07/07 04:04:16 djm Exp $ */
/*
* Copyright (c) 2000, 2013 Markus Friedl. All rights reserved.
*
@@ -207,7 +207,7 @@ sshkey_try_load_public(struct sshkey **kp, const char *filename,
*commentp = NULL;
if ((f = fopen(filename, "r")) == NULL)
return SSH_ERR_SYSTEM_ERROR;
if (stat(filename, &st) == 0 && S_ISREG(st.st_mode) &&
if (fstat(fileno(f), &st) == 0 && S_ISREG(st.st_mode) &&
st.st_size > SSHBUF_SIZE_MAX) {
fclose(f);
return SSH_ERR_INVALID_FORMAT;