Module Name: src Committed By: mrg Date: Fri Oct 4 11:39:44 UTC 2019
Modified Files: src/usr.bin/telnet: commands.c Log Message: use memmove() instead of strncpy() for overlapping strings. ensure nul termination. To generate a diff of this commit: cvs rdiff -u -r1.76 -r1.77 src/usr.bin/telnet/commands.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/telnet/commands.c diff -u src/usr.bin/telnet/commands.c:1.76 src/usr.bin/telnet/commands.c:1.77 --- src/usr.bin/telnet/commands.c:1.76 Sat Jan 5 08:55:58 2019 +++ src/usr.bin/telnet/commands.c Fri Oct 4 11:39:44 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: commands.c,v 1.76 2019/01/05 08:55:58 maya Exp $ */ +/* $NetBSD: commands.c,v 1.77 2019/10/04 11:39:44 mrg Exp $ */ /* * Copyright (C) 1997 and 1998 WIDE Project. @@ -63,7 +63,7 @@ #if 0 static char sccsid[] = "@(#)commands.c 8.4 (Berkeley) 5/30/95"; #else -__RCSID("$NetBSD: commands.c,v 1.76 2019/01/05 08:55:58 maya Exp $"); +__RCSID("$NetBSD: commands.c,v 1.77 2019/10/04 11:39:44 mrg Exp $"); #endif #endif /* not lint */ @@ -2503,13 +2503,14 @@ cmdrc(const char *m1, const char *m2) if (isspace((unsigned char)line[0])) continue; if (strncasecmp(line, m1, l1) == 0) - strncpy(line, &line[l1], sizeof(line) - l1); + memmove(line, &line[l1], sizeof(line) - l1 - 1); else if (strncasecmp(line, m2, l2) == 0) - strncpy(line, &line[l2], sizeof(line) - l2); + memmove(line, &line[l2], sizeof(line) - l2 - 1); else if (strncasecmp(line, "DEFAULT", 7) == 0) - strncpy(line, &line[7], sizeof(line) - 7); + memmove(line, &line[7], sizeof(line) - 7 - 1); else continue; + line[sizeof(line) - 1] = '\0'; if (line[0] != ' ' && line[0] != '\t' && line[0] != '\n') continue; gotmachine = 1;