aboutsummaryrefslogtreecommitdiffstats
path: root/gasroot-setuid.c
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2026-02-28 14:19:22 +0100
committerMattias Andrée <m@maandree.se>2026-02-28 14:19:22 +0100
commit3ec75cb8fe8426e66aabb3193bcbcdfade5c4546 (patch)
treeb8357bb0a677c4e8618ac43c516790f0c3f3512f /gasroot-setuid.c
parentm fixes (diff)
downloadgasroot-3ec75cb8fe8426e66aabb3193bcbcdfade5c4546.tar.gz
gasroot-3ec75cb8fe8426e66aabb3193bcbcdfade5c4546.tar.bz2
gasroot-3ec75cb8fe8426e66aabb3193bcbcdfade5c4546.tar.xz
Use constant-time string comparision for password hash checkingHEAD1.0.2master
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'gasroot-setuid.c')
-rw-r--r--gasroot-setuid.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/gasroot-setuid.c b/gasroot-setuid.c
index ca0b6c6..b970e19 100644
--- a/gasroot-setuid.c
+++ b/gasroot-setuid.c
@@ -204,6 +204,17 @@ recvtext(int fd, char **bufp, size_t *sizep)
}
+static int
+consttime_streq(const char *a, const char *b)
+{
+ size_t i;
+ int ret = 1;
+ for (i = 0; a[i] && b[i]; i++)
+ ret &= a[i] == b[i];
+ return ret & !a[i] && !b[i];
+}
+
+
int
main(int argc, char *argv[])
{
@@ -230,7 +241,7 @@ main(int argc, char *argv[])
sendtext(fd, "HELLO");
for (;;) {
recvtext(fd, &passphrase, &passphrase_size);
- if (!strcmp(crypt(passphrase, expected), expected))
+ if (consttime_streq(crypt(passphrase, expected), expected))
break;
wipe(passphrase);
#if RETRY_SLEEP > 0