Skip to content

Commit

Permalink
Binary parser bug fix.
Browse files Browse the repository at this point in the history
Signed-off-by: Ulf Bjorkengren <[email protected]>
  • Loading branch information
Ulf Bjorkengren authored and erikbosch committed Dec 22, 2023
1 parent 9dd9cf1 commit 5343e9c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
21 changes: 19 additions & 2 deletions binary/c_parser/cparserlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,24 @@ typedef struct SearchContext_t {
FILE* listFp;
} SearchContext_t;

uint8_t validationMatrix[4][4] = {{1,2,11,12}, {2,2,12,12}, {11,12,11,12}, {12,12,12,12}};
// Access control values: none=0, write-only=1. read-write=2, consent +=10
// matrix preserving inherited value with read-write having priority over write-only and consent over no consent
uint8_t validationMatrix[5][5] = {{0,1,2,11,12}, {1,1,2,11,12}, {2,2,2,12,12}, {11,11,12,11,12}, {12,12,12,12,12}};

uint8_t getMaxValidation(uint8_t newValidation, uint8_t currentMaxValidation) {
return validationMatrix[translateToMatrixIndex(newValidation)][translateToMatrixIndex(currentMaxValidation)];
}

uint8_t translateToMatrixIndex(uint8_t index) {
switch (index) {
case 0: return 0;
case 1: return 1;
case 2: return 2;
case 11: return 3;
case 12: return 4;
}
return 0;
}

void initReadMetadata() {
readTreeMetadata.currentDepth = 0;
Expand Down Expand Up @@ -219,7 +236,7 @@ int saveMatchingNode(long thisNode, SearchContext_t* context, bool* done) {
if (strcmp(getPathSegment(0, context), "*") == 0) {
context->speculationIndex++;
}
context->maxValidation = validationMatrix[VSSgetValidation(thisNode)][context->maxValidation];
context->maxValidation = getMaxValidation(VSSgetValidation(thisNode), context->maxValidation);
if (VSSgetType(thisNode) != BRANCH && VSSgetType(thisNode) != STRUCT || context->leafNodesOnly == false) {
if ( isGetLeafNodeList == false && isGetUuidList == false) {
strcpy(context->searchData[context->numOfMatches].responsePaths, context->matchPath);
Expand Down
2 changes: 2 additions & 0 deletions binary/c_parser/cparserlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,5 @@ char* VSSgetDescr(long nodeHandle);
int VSSgetNumOfAllowedElements(long nodeHandle);
char* VSSgetAllowedElement(long nodeHandle, int index);
char* VSSgetUnit(long nodeHandle);
uint8_t getMaxValidation(uint8_t newValidation, uint8_t currentMaxValidation);
uint8_t translateToMatrixIndex(uint8_t index);
20 changes: 18 additions & 2 deletions binary/go_parser/parserlib/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,24 @@ type SearchContext_t struct {
ListFp *os.File
}

var validationMatrix [4][4]int = [4][4]int{{1,2,11,12}, {2,2,12,12}, {11,12,11,12}, {12,12,12,12}}
// Access control values: none=0, write-only=1. read-write=2, consent +=10
// matrix preserving inherited value with read-write having priority over write-only and consent over no consent
var validationMatrix [5][5]int = [5][5]int{{0,1,2,11,12}, {1,1,2,11,12}, {2,2,2,12,12}, {11,11,12,11,12}, {12,12,12,12,12}}

func getMaxValidation(newValidation int, currentMaxValidation int) int {
return validationMatrix[translateToMatrixIndex(newValidation)][translateToMatrixIndex(currentMaxValidation)]
}

func translateToMatrixIndex(index int) int {
switch index {
case 0: return 0
case 1: return 1
case 2: return 2
case 11: return 3
case 12: return 4
}
return 0
}

func initReadMetadata() {
readTreeMetadata.CurrentDepth = 0
Expand Down Expand Up @@ -179,7 +195,7 @@ func saveMatchingNode(thisNode *def.Node_t, context *SearchContext_t, done *bool
if (getPathSegment(0, context) == "*") {
context.SpeculationIndex++
}
context.MaxValidation = validationMatrix[VSSgetValidation(thisNode)][context.MaxValidation]
context.MaxValidation = getMaxValidation(VSSgetValidation(thisNode), context.MaxValidation)
if (VSSgetType(thisNode) != def.BRANCH && VSSgetType(thisNode) != def.STRUCT || context.LeafNodesOnly == false) {
if ( isGetLeafNodeList == false && isGetUuidList == false) {
context.SearchData[context.NumOfMatches].NodePath = context.MatchPath
Expand Down

0 comments on commit 5343e9c

Please sign in to comment.