Skip to content

Commit

Permalink
Double free when accessing .AsBoxed() on Pod with 0 refcount (ydb-pla…
Browse files Browse the repository at this point in the history
  • Loading branch information
MrLolthe1st committed Aug 12, 2024
1 parent 6ec9f0c commit 6464c40
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ydb/library/yql/parser/pg_wrapper/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline NKikimr::NUdf::TUnboxedValuePod AnyDatumToPod(Datum datum, bool passByVal
}

inline Datum PointerDatumFromPod(const NKikimr::NUdf::TUnboxedValuePod& value) {
return (Datum)(((const NKikimr::NMiniKQL::TMkqlPAllocHeader*)value.AsBoxed().Get()) + 1);
return (Datum)(((const NKikimr::NMiniKQL::TMkqlPAllocHeader*)value.AsRawBoxed()) + 1);
}

inline Datum PointerDatumFromItem(const NKikimr::NUdf::TBlockItem& value) {
Expand Down
2 changes: 2 additions & 0 deletions ydb/library/yql/public/udf/udf_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,8 @@ friend class TUnboxedValue;

inline TStringValue AsStringValue() const;
inline IBoxedValuePtr AsBoxed() const;
inline TStringValue::TData* AsRawStringValue() const;
inline IBoxedValue* AsRawBoxed() const;
inline bool UniqueBoxed() const;

// special values
Expand Down
12 changes: 12 additions & 0 deletions ydb/library/yql/public/udf/udf_value_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,18 @@ inline IBoxedValuePtr TUnboxedValuePod::AsBoxed() const
return IBoxedValuePtr(Raw.Boxed.Value);
}

inline TStringValue::TData* TUnboxedValuePod::AsRawStringValue() const
{
UDF_VERIFY(IsString(), "Value is not a string");
return Raw.String.Value;
}

inline IBoxedValue* TUnboxedValuePod::AsRawBoxed() const
{
UDF_VERIFY(IsBoxed(), "Value is not boxed");
return Raw.Boxed.Value;
}

inline bool TUnboxedValuePod::UniqueBoxed() const
{
UDF_VERIFY(IsBoxed(), "Value is not boxed");
Expand Down

0 comments on commit 6464c40

Please sign in to comment.