HaikuDepot: preliminary fix for crash in JSON listener

* Fix use-after-free in the auto-generated JSON listener code (was
  calling method of instance after 'delete this')
  Will also submit a patch for the code generation script in the
  haikudepotserver repo so it won't get lost -- this is just a
  temporary fix-up until then.

* Fixes some random occasional crashes
This commit is contained in:
Julian Harnath
2017-11-24 18:22:14 +01:00
parent 492c58fd9c
commit a78e725206
2 changed files with 290 additions and 232 deletions
@@ -326,9 +326,12 @@ GeneralObjectStackedDumpExportPkgJsonListener::Handle(const BJsonEvent& event)
break; break;
case B_JSON_OBJECT_END: case B_JSON_OBJECT_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
} }
@@ -374,9 +377,12 @@ GeneralArrayStackedDumpExportPkgJsonListener::Handle(const BJsonEvent& event)
break; break;
case B_JSON_ARRAY_END: case B_JSON_ARRAY_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
} }
@@ -419,9 +425,12 @@ DumpExportPkg_StackedDumpExportPkgJsonListener::Handle(const BJsonEvent& event)
break; break;
case B_JSON_OBJECT_END: case B_JSON_OBJECT_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
case B_JSON_STRING: case B_JSON_STRING:
@@ -539,9 +548,12 @@ DumpExportPkg_List_StackedDumpExportPkgJsonListener::Handle(const BJsonEvent& ev
switch (event.EventType()) { switch (event.EventType()) {
case B_JSON_ARRAY_END: case B_JSON_ARRAY_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
case B_JSON_OBJECT_START: case B_JSON_OBJECT_START:
{ {
@@ -597,9 +609,12 @@ DumpExportPkgVersion_StackedDumpExportPkgJsonListener::Handle(const BJsonEvent&
break; break;
case B_JSON_OBJECT_END: case B_JSON_OBJECT_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
case B_JSON_STRING: case B_JSON_STRING:
@@ -732,9 +747,12 @@ DumpExportPkgVersion_List_StackedDumpExportPkgJsonListener::Handle(const BJsonEv
switch (event.EventType()) { switch (event.EventType()) {
case B_JSON_ARRAY_END: case B_JSON_ARRAY_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
case B_JSON_OBJECT_START: case B_JSON_OBJECT_START:
{ {
@@ -790,9 +808,12 @@ DumpExportPkgScreenshot_StackedDumpExportPkgJsonListener::Handle(const BJsonEven
break; break;
case B_JSON_OBJECT_END: case B_JSON_OBJECT_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
case B_JSON_STRING: case B_JSON_STRING:
@@ -895,9 +916,12 @@ DumpExportPkgScreenshot_List_StackedDumpExportPkgJsonListener::Handle(const BJso
switch (event.EventType()) { switch (event.EventType()) {
case B_JSON_ARRAY_END: case B_JSON_ARRAY_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
case B_JSON_OBJECT_START: case B_JSON_OBJECT_START:
{ {
@@ -953,9 +977,12 @@ DumpExportPkgCategory_StackedDumpExportPkgJsonListener::Handle(const BJsonEvent&
break; break;
case B_JSON_OBJECT_END: case B_JSON_OBJECT_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
case B_JSON_STRING: case B_JSON_STRING:
@@ -1034,9 +1061,12 @@ DumpExportPkgCategory_List_StackedDumpExportPkgJsonListener::Handle(const BJsonE
switch (event.EventType()) { switch (event.EventType()) {
case B_JSON_ARRAY_END: case B_JSON_ARRAY_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
case B_JSON_OBJECT_START: case B_JSON_OBJECT_START:
{ {
@@ -1119,9 +1149,12 @@ BulkContainerStackedDumpExportPkgJsonListener::Handle(const BJsonEvent& event)
break; break;
case B_JSON_OBJECT_END: case B_JSON_OBJECT_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
default: default:
// ignore // ignore
@@ -1157,9 +1190,12 @@ BulkContainerItemsStackedDumpExportPkgJsonListener::Handle(const BJsonEvent& eve
break; break;
case B_JSON_ARRAY_END: case B_JSON_ARRAY_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
default: default:
HandleError(B_NOT_ALLOWED, JSON_EVENT_LISTENER_ANY_LINE, "illegal state - unexpected json event"); HandleError(B_NOT_ALLOWED, JSON_EVENT_LISTENER_ANY_LINE, "illegal state - unexpected json event");
@@ -5,7 +5,6 @@
*/ */
#include "DumpExportRepositoryJsonListener.h" #include "DumpExportRepositoryJsonListener.h"
#include "List.h" #include "List.h"
#include <stdio.h> #include <stdio.h>
// #pragma mark - private interfaces for the stacked listeners // #pragma mark - private interfaces for the stacked listeners
@@ -264,10 +263,12 @@ GeneralObjectStackedDumpExportRepositoryJsonListener::Handle(const BJsonEvent& e
break; break;
case B_JSON_OBJECT_END: case B_JSON_OBJECT_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
} }
return ErrorStatus() == B_OK; return ErrorStatus() == B_OK;
@@ -312,10 +313,12 @@ GeneralArrayStackedDumpExportRepositoryJsonListener::Handle(const BJsonEvent& ev
break; break;
case B_JSON_ARRAY_END: case B_JSON_ARRAY_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
} }
return ErrorStatus() == B_OK; return ErrorStatus() == B_OK;
@@ -357,9 +360,12 @@ DumpExportRepository_StackedDumpExportRepositoryJsonListener::Handle(const BJson
break; break;
case B_JSON_OBJECT_END: case B_JSON_OBJECT_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
case B_JSON_STRING: case B_JSON_STRING:
@@ -461,9 +467,12 @@ DumpExportRepository_List_StackedDumpExportRepositoryJsonListener::Handle(const
switch (event.EventType()) { switch (event.EventType()) {
case B_JSON_ARRAY_END: case B_JSON_ARRAY_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
case B_JSON_OBJECT_START: case B_JSON_OBJECT_START:
{ {
@@ -519,9 +528,12 @@ DumpExportRepositorySource_StackedDumpExportRepositoryJsonListener::Handle(const
break; break;
case B_JSON_OBJECT_END: case B_JSON_OBJECT_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
case B_JSON_STRING: case B_JSON_STRING:
@@ -606,9 +618,12 @@ DumpExportRepositorySource_List_StackedDumpExportRepositoryJsonListener::Handle(
switch (event.EventType()) { switch (event.EventType()) {
case B_JSON_ARRAY_END: case B_JSON_ARRAY_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
case B_JSON_OBJECT_START: case B_JSON_OBJECT_START:
{ {
@@ -691,9 +706,12 @@ BulkContainerStackedDumpExportRepositoryJsonListener::Handle(const BJsonEvent& e
break; break;
case B_JSON_OBJECT_END: case B_JSON_OBJECT_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
default: default:
// ignore // ignore
@@ -729,9 +747,12 @@ BulkContainerItemsStackedDumpExportRepositoryJsonListener::Handle(const BJsonEve
break; break;
case B_JSON_ARRAY_END: case B_JSON_ARRAY_END:
{
Pop(); Pop();
bool status = (ErrorStatus() == B_OK);
delete this; delete this;
break; return status;
}
default: default:
HandleError(B_NOT_ALLOWED, JSON_EVENT_LISTENER_ANY_LINE, "illegal state - unexpected json event"); HandleError(B_NOT_ALLOWED, JSON_EVENT_LISTENER_ANY_LINE, "illegal state - unexpected json event");
@@ -874,6 +895,7 @@ BulkContainerDumpExportRepositoryJsonListener::Handle(const BJsonEvent& event)
BulkContainerStackedDumpExportRepositoryJsonListener* nextListener = BulkContainerStackedDumpExportRepositoryJsonListener* nextListener =
new BulkContainerStackedDumpExportRepositoryJsonListener( new BulkContainerStackedDumpExportRepositoryJsonListener(
this, NULL, fItemListener); this, NULL, fItemListener);
SetStackedListener(nextListener); SetStackedListener(nextListener);
return true; return true;
break; break;