Skip to content

A trailing garbage character is accepted after a special date/time expression #9115

Description

@ChudaykinAlex

A single character following NOW, TODAY, TOMORROW or YESTERDAY is silently ignored instead of raising a conversion error:

SELECT CAST('NOW)' AS TIMESTAMP) FROM RDB$DATABASE;      -- succeeds, returns the current timestamp
SELECT CAST('TODAY!' AS DATE) FROM RDB$DATABASE;         -- succeeds, returns the current date
SELECT CAST('YESTERDAY-' AS DATE) FROM RDB$DATABASE;     -- succeeds, returns yesterday

Two or more garbage characters are rejected correctly, so only the first one slips through:

SELECT CAST('NOW))' AS TIMESTAMP) FROM RDB$DATABASE;     -- conversion error, as expected

The effect was confirmed in master, v5.0-release, B3_0_Release.

Cause

CVT_string_to_datetime() in src/common/cvt.cpp validates the rest of the string after the word has been read:

while (++p < end)
{
    if (*p != ' ' && *p != '\t' && *p != '\0')
        CVT_conversion_error(desc, cb->err);
}

At this point p already points to the first character that was not consumed as a part of the word, so the pre-increment in the condition skips it and it is never checked.

Fix

while (p < end)
{
    if (*p != ' ' && *p != '\t' && *p != '\0')
        CVT_conversion_error(desc, cb->err);

    ++p;
}

Trailing blanks, tabs and NULs stay allowed, so CHAR padding keeps working.

Tested on master, B3_0_Release

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions