From 02402fe1109cfd16f303a0d24555f5fd199d8e62 Mon Sep 17 00:00:00 2001 From: mrg Date: Tue, 13 Apr 2021 00:29:22 +0000 Subject: [PATCH] pass dest buffer size to strncpy() and ensure nul termination. --- lib/libc/rpc/getrpcent.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/libc/rpc/getrpcent.c b/lib/libc/rpc/getrpcent.c index 68242cceab4e..b2a38d408f5b 100644 --- a/lib/libc/rpc/getrpcent.c +++ b/lib/libc/rpc/getrpcent.c @@ -1,4 +1,4 @@ -/* $NetBSD: getrpcent.c,v 1.23 2013/03/11 20:19:29 tron Exp $ */ +/* $NetBSD: getrpcent.c,v 1.24 2021/04/13 00:29:22 mrg Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -36,7 +36,7 @@ #if 0 static char *sccsid = "@(#)getrpcent.c 1.14 91/03/11 Copyr 1984 Sun Micro"; #else -__RCSID("$NetBSD: getrpcent.c,v 1.23 2013/03/11 20:19:29 tron Exp $"); +__RCSID("$NetBSD: getrpcent.c,v 1.24 2021/04/13 00:29:22 mrg Exp $"); #endif #endif @@ -185,7 +185,8 @@ interpret(char *val, size_t len) if (d == 0) return (0); - (void) strncpy(d->line, val, len); + strncpy(d->line, val, sizeof(d->line) - 1); + d->line[sizeof(d->line) - 1] = '\0'; p = d->line; d->line[len] = '\n'; if (*p == '#')