Skip to content

Commit c66a55e

Browse files
authored
Double free when accessing .AsBoxed() on Pod with 0 refcount (#7659)
1 parent a536da4 commit c66a55e

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

ydb/library/yql/parser/pg_wrapper/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline NKikimr::NUdf::TUnboxedValuePod AnyDatumToPod(Datum datum, bool passByVal
6565
}
6666

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

7171
inline Datum PointerDatumFromItem(const NKikimr::NUdf::TBlockItem& value) {

ydb/library/yql/public/udf/udf_value.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,8 @@ friend class TUnboxedValue;
827827

828828
inline TStringValue AsStringValue() const;
829829
inline IBoxedValuePtr AsBoxed() const;
830+
inline TStringValue::TData* AsRawStringValue() const;
831+
inline IBoxedValue* AsRawBoxed() const;
830832
inline bool UniqueBoxed() const;
831833

832834
// special values

ydb/library/yql/public/udf/udf_value_inl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,18 @@ inline IBoxedValuePtr TUnboxedValuePod::AsBoxed() const
390390
return IBoxedValuePtr(Raw.Boxed.Value);
391391
}
392392

393+
inline TStringValue::TData* TUnboxedValuePod::AsRawStringValue() const
394+
{
395+
UDF_VERIFY(IsString(), "Value is not a string");
396+
return Raw.String.Value;
397+
}
398+
399+
inline IBoxedValue* TUnboxedValuePod::AsRawBoxed() const
400+
{
401+
UDF_VERIFY(IsBoxed(), "Value is not boxed");
402+
return Raw.Boxed.Value;
403+
}
404+
393405
inline bool TUnboxedValuePod::UniqueBoxed() const
394406
{
395407
UDF_VERIFY(IsBoxed(), "Value is not boxed");

0 commit comments

Comments
 (0)