diff options
author | midipix <writeonce@midipix.org> | 2018-08-03 23:30:51 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2018-08-03 21:13:31 -0400 |
commit | 9695ec6ea64c668211f0e39691e87419c1c0b424 (patch) | |
tree | 3bba432a0c9d51d4438da32775f8825176ed7cb1 | |
parent | 2f4c03923b250a3bbf96188ceb91979841a95e91 (diff) | |
download | mdso-9695ec6ea64c668211f0e39691e87419c1c0b424.tar.bz2 mdso-9695ec6ea64c668211f0e39691e87419c1c0b424.tar.xz |
mdso_argen_common(): refactor, enhance error reporting.
-rw-r--r-- | src/archive/mdso_argen_common.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/src/archive/mdso_argen_common.c b/src/archive/mdso_argen_common.c index 9cd80d6..072f57e 100644 --- a/src/archive/mdso_argen_common.c +++ b/src/archive/mdso_argen_common.c @@ -75,7 +75,7 @@ int mdso_argen_common( char objname[16]; /* init */ - memset (sobj,0,sizeof(sobj)); + memset(sobj,0,sizeof(sobj)); for (nsym=0,ndata=0,psym=symv; *psym; psym++,nsym++) ndata += (stype[psym-symv] == MDSO_SYMBOL_TYPE_DATA); @@ -106,6 +106,7 @@ int mdso_argen_common( mapstrslen = aobj->mapstrslen; mapstrsnum = aobj->mapstrsnum; + /* objlen: symfn, symentry */ for (psym=symv,pobj=&aobj[1]; *psym && !ret; psym++) { if (stype[psym-symv] == MDSO_SYMBOL_TYPE_CODE) { ret = mdso_objgen_symfn(dctx,*psym,pobj); @@ -136,11 +137,14 @@ int mdso_argen_common( pobj++; } - if (ret && (aobj != sobj)) - free(aobj); + /* verify logic */ + if (ret && (aobj == sobj)) + return MDSO_NESTED_ERROR(dctx); - if (ret) - return ret; + if (ret) { + free(aobj); + return MDSO_NESTED_ERROR(dctx); + } /* index: string block alignment */ mapstrslen += 1; @@ -155,6 +159,7 @@ int mdso_argen_common( objlen |= 15; objlen ^= 15; + /* archive meta info, in-memory mapping */ if (vobj->addr && (vobj->size < objlen)) return MDSO_BUFFER_ERROR(dctx); @@ -271,13 +276,6 @@ int mdso_argen_common( pobj++; } - if (ret) { - if (aobj != sobj) - free(aobj); - - return ret; - } - /* aobj */ if (aobj != sobj) free(aobj); @@ -286,6 +284,10 @@ int mdso_argen_common( if (!addr) munmap(vobj->addr,vobj->size); + /* verify */ + if (ret) + return MDSO_NESTED_ERROR(dctx); + /* tada */ return 0; |