Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t0Szz-00BalI-6e for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Oct 2024 21:53:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t0Szx-000CJW-FO for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Oct 2024 21:53:05 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t0Szx-000CJO-6l for pgsql-bugs@lists.postgresql.org; Mon, 14 Oct 2024 21:53:05 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t0Szu-000txs-Ms for pgsql-bugs@lists.postgresql.org; Mon, 14 Oct 2024 21:53:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2024011501; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:To:From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description; bh=gtlG+m6teu1t5A7yqrZpdhK9jh/wE1LpiQHn191xHnI=; b=Qihc9 X7S/AwsNh/4+PxqLmgJDgNEYIfO/2/SJ1WEDgpJtkZfWlhqcoSm5LH0ygjLMfpG1I0e83VniMik/x qbe7hq+Ku3z58fncS8h+uJOtmLVqDnj4MhBn923XuhxSpg8hdxSUIbhZEys01OOmHGuzKj0JKakwQ O4fa7vMcADUL3Dj7uL9c/JsyNhs33R63xDHrbhU66Z5URz/kln82OPGajbs/NJK5j6RRGskCPS0qY xSX9eoitwachLOGPO9RltK4NBJUOw622aw54xsKtQRTg4s/cOqHk49DmI4EDLYwmf/60GKS4JdgeL 5zOLRavqopH99EmQ1mlMuDO6XcEnQ==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1t0Szs-001ShF-02; Mon, 14 Oct 2024 17:53:00 -0400 Date: Mon, 14 Oct 2024 17:52:59 -0400 From: Bruce Momjian To: p.nekrasov@fobos-nt.ru, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18614: [ECPG] out of bound in DecodeDateTime Message-ID: References: <18614-6bbe00117352309e@postgresql.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="z0AzLbL4UB6jW5F+" Content-Disposition: inline In-Reply-To: <18614-6bbe00117352309e@postgresql.org> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --z0AzLbL4UB6jW5F+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Sep 12, 2024 at 08:54:42AM +0000, PG Bug reporting form wrote: > The following bug has been logged on the website: > > Bug reference: 18614 > Logged by: Pavel Nekrasov > Email address: p.nekrasov@fobos-nt.ru > PostgreSQL version: 17rc1 > Operating system: Alt 10 > Description: > > in the line ```if (tm->tm_mday < 1 || tm->tm_mday > > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]) ``` tm->tm_mon may be equal to > 0, which will result in reading by indexes -1 > > this is possible when calling PGTYPESdate_from_asc or > PGTYPEStimestamp_from_asc with "str" equal, for example, "AM95000062" Yes, I agree. Attached is a non-word-wrapped patch that I plan to apply to all supported PG versions. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com When a patient asks the doctor, "Am I going to die?", he means "Am I going to die soon?" --z0AzLbL4UB6jW5F+ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="ecpg.diff" diff --git a/src/interfaces/ecpg/pgtypeslib/dt_common.c b/src/interfaces/ecpg/pgtypeslib/dt_common.c index 0d63fe52c5b..bf5976cf03b 100644 --- a/src/interfaces/ecpg/pgtypeslib/dt_common.c +++ b/src/interfaces/ecpg/pgtypeslib/dt_common.c @@ -2327,10 +2327,10 @@ DecodeDateTime(char **field, int *ftype, int nf, return ((fmask & DTK_TIME_M) == DTK_TIME_M) ? 1 : -1; /* - * check for valid day of month, now that we know for sure the month + * check for valid day of month and month, now that we know for sure the month * and year... */ - if (tm->tm_mday < 1 || tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]) + if (tm->tm_mon < 1 || tm->tm_mday < 1 || tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1]) return -1; /* --z0AzLbL4UB6jW5F+--