Skip to content

Commit f164a01

Browse files
committed
fix(WeaselTSF): client dump caused by dereferencing nullptr during CEndCompositionEditSession::DoEditSession
1 parent 49811d3 commit f164a01

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

WeaselTSF/Composition.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,19 @@ STDAPI CEndCompositionEditSession::DoEditSession(TfEditCookie ec) {
106106
/* Clear the dummy text we set before, if any. */
107107
if (_pComposition == nullptr)
108108
return S_OK;
109+
// Avoid null pointer dereference
110+
if (!_pTextService || !_pContext)
111+
return S_OK;
109112

110113
_pTextService->_ClearCompositionDisplayAttributes(ec, _pContext);
111114

112-
ITfRange* pCompositionRange;
115+
com_ptr<ITfRange> pCompositionRange;
113116
if (_clear && _pComposition->GetRange(&pCompositionRange) == S_OK)
114117
pCompositionRange->SetText(ec, 0, L"", 0);
115118

116119
_pComposition->EndComposition(ec);
120+
if (!_pTextService)
121+
return S_OK; // _pTextService released, skip _FinalizeComposition
117122
_pTextService->_FinalizeComposition();
118123
return S_OK;
119124
}

WeaselTSF/DisplayAttribute.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
void WeaselTSF::_ClearCompositionDisplayAttributes(TfEditCookie ec,
66
_In_ ITfContext* pContext) {
7-
ITfRange* pRangeComposition = nullptr;
8-
ITfProperty* pDisplayAttributeProperty = nullptr;
7+
com_ptr<ITfRange> pRangeComposition = nullptr;
8+
com_ptr<ITfProperty> pDisplayAttributeProperty = nullptr;
99

1010
if (FAILED(_pComposition->GetRange(&pRangeComposition))) {
1111
return;
@@ -14,17 +14,13 @@ void WeaselTSF::_ClearCompositionDisplayAttributes(TfEditCookie ec,
1414
if (SUCCEEDED(pContext->GetProperty(GUID_PROP_ATTRIBUTE,
1515
&pDisplayAttributeProperty))) {
1616
pDisplayAttributeProperty->Clear(ec, pRangeComposition);
17-
18-
pDisplayAttributeProperty->Release();
1917
}
20-
21-
pRangeComposition->Release();
2218
}
2319

2420
BOOL WeaselTSF::_SetCompositionDisplayAttributes(TfEditCookie ec,
2521
_In_ ITfContext* pContext,
2622
ITfRange* pRangeComposition) {
27-
ITfProperty* pDisplayAttributeProperty = nullptr;
23+
com_ptr<ITfProperty> pDisplayAttributeProperty = nullptr;
2824
HRESULT hr = S_OK;
2925

3026
if (pRangeComposition == nullptr)
@@ -40,10 +36,7 @@ BOOL WeaselTSF::_SetCompositionDisplayAttributes(TfEditCookie ec,
4036
VARIANT var;
4137
var.vt = VT_I4; // we're going to set a TfGuidAtom
4238
var.lVal = _gaDisplayAttributeInput;
43-
4439
hr = pDisplayAttributeProperty->SetValue(ec, pRangeComposition, &var);
45-
46-
pDisplayAttributeProperty->Release();
4740
}
4841

4942
// DO NOT release range composition here
@@ -53,7 +46,7 @@ BOOL WeaselTSF::_SetCompositionDisplayAttributes(TfEditCookie ec,
5346
}
5447

5548
BOOL WeaselTSF::_InitDisplayAttributeGuidAtom() {
56-
ITfCategoryMgr* pCategoryMgr = nullptr;
49+
com_ptr<ITfCategoryMgr> pCategoryMgr = nullptr;
5750
HRESULT hr =
5851
CoCreateInstance(CLSID_TF_CategoryMgr, nullptr, CLSCTX_INPROC_SERVER,
5952
IID_ITfCategoryMgr, (void**)&pCategoryMgr);
@@ -69,7 +62,5 @@ BOOL WeaselTSF::_InitDisplayAttributeGuidAtom() {
6962
}
7063

7164
Exit:
72-
pCategoryMgr->Release();
73-
7465
return (hr == S_OK);
7566
}

0 commit comments

Comments
 (0)