From 65da0d66b4e89951078ebc43a5343780e4e700d6 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Fri, 7 Jul 2000 21:12:53 +0000 Subject: Fix misuse of StrNCpy to copy and add null to non-null-terminated data. Does not work since it fetches one byte beyond the source data, and when the phase of the moon is wrong, the source data is smack up against the end of backend memory and you get SIGSEGV. Don't laugh, this is a fix for an actual user bug report. --- src/backend/utils/adt/like.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/backend/utils/adt/like.c') diff --git a/src/backend/utils/adt/like.c b/src/backend/utils/adt/like.c index 6fbd95ffe2..5a7b847339 100644 --- a/src/backend/utils/adt/like.c +++ b/src/backend/utils/adt/like.c @@ -11,7 +11,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.36 2000/07/06 05:48:11 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/adt/like.c,v 1.37 2000/07/07 21:12:50 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -48,7 +48,8 @@ fixedlen_like(char *s, text *p, int charlen) (void) pg_mb2wchar_with_len((unsigned char *) s, sterm, charlen); #else sterm = (char *) palloc(charlen + 1); - StrNCpy(sterm, s, charlen + 1); + memcpy(sterm, s, charlen); + sterm[charlen] = '\0'; #endif /* -- cgit v1.2.1