From 68961d1200a9cb6bf3619f292a56b2ea35a048ae Mon Sep 17 00:00:00 2001 From: "Stephane E. Potvin" Date: Wed, 16 Sep 2009 19:53:29 +0000 Subject: [PATCH] The buffer returned by fgenln is not a "C" string and might not be NUL terminated. Make sure that it is before using it. Reviewed by: marck@ MFC after: 3 days --- gnu/usr.bin/patch/common.h | 1 + gnu/usr.bin/patch/pch.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/gnu/usr.bin/patch/common.h b/gnu/usr.bin/patch/common.h index 7063be682429..aa191054aa17 100644 --- a/gnu/usr.bin/patch/common.h +++ b/gnu/usr.bin/patch/common.h @@ -34,6 +34,7 @@ #define Strcpy (void)strcpy #define Strcat (void)strcat #define Strlcpy (void)strlcpy +#define Strncpy (void)strncpy #define Strlcat (void)strlcat /* NeXT declares malloc and realloc incompatibly from us in some of diff --git a/gnu/usr.bin/patch/pch.c b/gnu/usr.bin/patch/pch.c index d72f84f3069e..dba4582e52a4 100644 --- a/gnu/usr.bin/patch/pch.c +++ b/gnu/usr.bin/patch/pch.c @@ -1176,7 +1176,8 @@ pgets(bool do_indent) indent++; } } - Strlcpy(buf, line, len + 1 - skipped); + Strncpy(buf, line, len - skipped); + buf[len - skipped] = '\0'; } return len; }