From 9695ec6ea64c668211f0e39691e87419c1c0b424 Mon Sep 17 00:00:00 2001 From: midipix Date: Fri, 3 Aug 2018 23:30:51 +0000 Subject: mdso_argen_common(): refactor, enhance error reporting. --- src/archive/mdso_argen_common.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/archive') 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; -- cgit v1.2.3