Skip to content

Fixed bug #8203 : Function MAKE_DBKEY may produce random errors if used with relation name #8204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/dsql/ExprNodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8092,6 +8092,16 @@ dsc* LiteralNode::execute(thread_db* /*tdbb*/, Request* /*request*/) const
return const_cast<dsc*>(&litDesc);
}

bool LiteralNode::getMetaName(thread_db* tdbb, MetaName& name) const
{
if (!DTYPE_IS_TEXT(litDesc.dsc_dtype))
return false;

CVT2_make_metaname(&litDesc, name, tdbb->getAttachment()->att_dec_status);

return true;
}

void LiteralNode::fixMinSInt64(MemoryPool& pool)
{
// MIN_SINT64 should be stored as BIGINT, not 128-bit integer
Expand Down Expand Up @@ -12304,9 +12314,9 @@ DmlNode* SysFuncCallNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScrat

auto literal = nodeAs<LiteralNode>(node->args->items[0]);

if (literal && literal->litDesc.isText())
MetaName relName;
if (literal && literal->getMetaName(tdbb, relName))
{
const MetaName relName = literal->getText();
const jrd_rel* const relation = MET_lookup_relation(tdbb, relName);

if (relation)
Expand Down
6 changes: 1 addition & 5 deletions src/dsql/ExprNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,11 +965,7 @@ class LiteralNode final : public TypedNode<ValueExprNode, ExprNode::TYPE_LITERAL
return *reinterpret_cast<SLONG*>(litDesc.dsc_address);
}

const char* getText() const
{
fb_assert(litDesc.dsc_dtype == dtype_text);
return reinterpret_cast<const char*>(litDesc.dsc_address);
}
bool getMetaName(thread_db* tdbb, MetaName& name) const;

void fixMinSInt32(MemoryPool& pool);
void fixMinSInt64(MemoryPool& pool);
Expand Down
3 changes: 2 additions & 1 deletion src/jrd/SysFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "../jrd/blb_proto.h"
#include "../jrd/cch_proto.h"
#include "../jrd/cvt_proto.h"
#include "../jrd/cvt2_proto.h"
#include "../common/cvt.h"
#include "../jrd/evl_proto.h"
#include "../jrd/intl_proto.h"
Expand Down Expand Up @@ -5365,7 +5366,7 @@ dsc* evlMakeDbkey(Jrd::thread_db* tdbb, const SysFunction* function, const NestV
if (argDsc->isText())
{
MetaName relName;
MOV_get_metaname(tdbb, argDsc, relName);
CVT2_make_metaname(argDsc, relName, tdbb->getAttachment()->att_dec_status);

const jrd_rel* const relation = MET_lookup_relation(tdbb, relName);
if (!relation)
Expand Down
22 changes: 22 additions & 0 deletions src/jrd/cvt2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,28 @@ int CVT2_blob_compare(const dsc* arg1, const dsc* arg2, DecimalStatus decSt)
}


void CVT2_make_metaname(const dsc* desc, MetaName& name, DecimalStatus decSt)
/**************************************
*
* C V T 2 _ m a k e _ m e t a n a m e
*
**************************************
*
* Functional description
*
* Convert the data from the desc to a string in the metadata charset.
* Then return the string as MetaName object.
*
**************************************/
{
MoveBuffer buff;
UCHAR* ptr = nullptr;

const auto len = CVT2_make_string2(desc, CS_METADATA, &ptr, buff, decSt);
name.assign(reinterpret_cast<const char*>(ptr), len);
}


USHORT CVT2_make_string2(const dsc* desc, USHORT to_interp, UCHAR** address, MoveBuffer& temp, DecimalStatus decSt)
{
/**************************************
Expand Down
1 change: 1 addition & 0 deletions src/jrd/cvt2_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern const BYTE CVT2_compare_priority[];
bool CVT2_get_binary_comparable_desc(dsc*, const dsc*, const dsc*);
int CVT2_compare(const dsc*, const dsc*, Firebird::DecimalStatus);
int CVT2_blob_compare(const dsc*, const dsc*, Firebird::DecimalStatus);
void CVT2_make_metaname(const dsc* desc, Jrd::MetaName& name, Firebird::DecimalStatus);
USHORT CVT2_make_string2(const dsc*, USHORT, UCHAR**, Jrd::MoveBuffer&, Firebird::DecimalStatus);

#endif // JRD_CVT2_PROTO_H
Loading