FirebirdSQL / firebird

Firebird server, client and tools
https://firebirdsql.org
1.26k stars 217 forks source link

isc_que_events callback function randomly return invalid Update Buffer [CORE5254] #5533

Open firebird-automations opened 8 years ago

firebird-automations commented 8 years ago

Submitted by: Mahmudov Ilgar S. (maxis)

I use POST EVENT in triggers and stored procedures. For catching events I try use FIBPlus, but found AV when registering/unregistering Events (\~50 % times in application staring/closing). I write my own component (similar to FIBPlus super alerter and IBEvents) and found that EventBuffer used in res = Parent->Database->ClientLibrary->isc_que_events(StatusVector, &DBH, &EventID, EventBufferLen, EventBuffer, (TISC_CALLBACK)EventCallback, PVoid)this); in sometimes corrupt, because of in EventCallback function receive invalid Updated, witch copied to ResulBuffer and then isc_event_counts copied ResultBuffer to EventBuffer

void EventCallback(void *Ptr, short Length, unsigned char *Updated) { if (Ptr && Updated) { TMxFBEventsBlockListener *T = (TMxFBEventsBlockListener *)Ptr;

    T\-\>UpdateResultBuffer\(Length, Updated\);
    T\-\>SignalEvent\(\);
\}

} //--------------------------------------------------------------------------- void __fastcall TMxFBEventsBlockListener::UpdateResultBuffer(short Length, unsigned char *Updated) { if (Length == EventBufferLen && Updated[0] == 1) memcpy(ResultBuffer, Updated, Length); else // ---------------------------------------------------> INVALID UPDATED { memcpy(ResultBuffer, EventBuffer, EventBufferLen); // this is my patch, witch help call isc_que_events without error 335544973 // bFirstTime = true; Parent->DoError("MxFBEventsAlerter: Invalid Updated buffer ="+IntToStr(Length), 0); } }

This is floating error. You can 100 times unregister and register again same event list and see this error 20-50 times.

İ can send all sources

firebird-automations commented 8 years ago
Modified by: Mahmudov Ilgar S. (maxis) description: I use POST EVENT in triggers and stored procedures\. For catching events I try use FIBPlus, but found AV when registering/unregistering Events \(50 % times in application staring/closing\)\. I write my own component \(similar to FIBPlus super alerter and IBEvents\) and found that EventBuffer used in res = Parent\-\>Database\-\>ClientLibrary\-\>isc\_que\_events\(StatusVector, &DBH, &EventID, EventBufferLen, EventBuffer, \(TISC\_CALLBACK\)EventCallback, PVoid\)this\); in sometimes corrupt, because of in EventCallback function receive invalid Updated, witch copied to ResulBuffer and after isc\_event\_counts copied to EventBuffer void EventCallback\(void \*Ptr, short Length, unsigned char \*Updated\) \{ if \(Ptr && Updated\) \{ TMxFBEventsBlockListener \*T = \(TMxFBEventsBlockListener \*\)Ptr; T\-\>UpdateResultBuffer\(Length, Updated\); T\-\>SignalEvent\(\); \} \} //\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- void \_\_fastcall TMxFBEventsBlockListener::UpdateResultBuffer\(short Length, unsigned char \*Updated\) \{ if \(Length == EventBufferLen && Updated\[0\] == 1\) memcpy\(ResultBuffer, Updated, Length\); else // \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\> INVALID UPDATED \{ memcpy\(ResultBuffer, EventBuffer, EventBufferLen\); // bFirstTime = true; Parent\-\>DoError\("MxFBEventsAlerter: Invalid Updated buffer ="\+IntToStr\(Length\), 0\); \} \} This is floating error\. You can 100 times unregister and register again same event list and see this error 20\-50 times\. =\> I use POST EVENT in triggers and stored procedures\. For catching events I try use FIBPlus, but found AV when registering/unregistering Events \(\~50 % times in application staring/closing\)\. I write my own component \(similar to FIBPlus super alerter and IBEvents\) and found that EventBuffer used in res = Parent\-\>Database\-\>ClientLibrary\-\>isc\_que\_events\(StatusVector, &DBH, &EventID, EventBufferLen, EventBuffer, \(TISC\_CALLBACK\)EventCallback, PVoid\)this\); in sometimes corrupt, because of in EventCallback function receive invalid Updated, witch copied to ResulBuffer and then isc\_event\_counts copied ResultBuffer to EventBuffer void EventCallback\(void \*Ptr, short Length, unsigned char \*Updated\) \{ if \(Ptr && Updated\) \{ TMxFBEventsBlockListener \*T = \(TMxFBEventsBlockListener \*\)Ptr; T\-\>UpdateResultBuffer\(Length, Updated\); T\-\>SignalEvent\(\); \} \} //\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\- void \_\_fastcall TMxFBEventsBlockListener::UpdateResultBuffer\(short Length, unsigned char \*Updated\) \{ if \(Length == EventBufferLen && Updated\[0\] == 1\) memcpy\(ResultBuffer, Updated, Length\); else // \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\> INVALID UPDATED \{ memcpy\(ResultBuffer, EventBuffer, EventBufferLen\); // this is my patch, witch help call isc\_que\_events without error 335544973 // bFirstTime = true; Parent\-\>DoError\("MxFBEventsAlerter: Invalid Updated buffer ="\+IntToStr\(Length\), 0\); \} \} This is floating error\. You can 100 times unregister and register again same event list and see this error 20\-50 times\. İ can send all sources
firebird-automations commented 8 years ago

Commented by: @aafemt

In callback you must check that length > 0 in addition to updated != NULL.

firebird-automations commented 8 years ago

Commented by: Mahmudov Ilgar S. (maxis)

İt's already checked in UpdateResultBuffer if (Length == EventBufferLen && Updated[0] == 1)

firebird-automations commented 7 years ago

Commented by: @hvlad

It looks like recently fixed CORE5521 Is it still actual ?