The c and rc dances don't make this code shorter or easier to follow, so I suggest we do it the dumb and straightforward way.
There are more of these 'if (rc == 0)' cleanups in other parse functions with only minimal gains. I can send a diff for this... Index: cert.c =================================================================== RCS file: /cvs/src/usr.sbin/rpki-client/cert.c,v retrieving revision 1.60 diff -u -p -r1.60 cert.c --- cert.c 2 Apr 2022 12:17:53 -0000 1.60 +++ cert.c 3 Apr 2022 20:30:29 -0000 @@ -1057,7 +1057,7 @@ certificate_policies(struct parse *p, X5 struct cert * cert_parse_pre(const char *fn, const unsigned char *der, size_t len) { - int rc = 0, extsz, c; + int extsz; int sia_present = 0; size_t i; X509 *x = NULL; @@ -1089,21 +1089,24 @@ cert_parse_pre(const char *fn, const uns assert(ext != NULL); obj = X509_EXTENSION_get_object(ext); assert(obj != NULL); - c = 1; switch (OBJ_obj2nid(obj)) { case NID_sbgp_ipAddrBlock: - c = sbgp_ipaddrblk(&p, ext); + if (!sbgp_ipaddrblk(&p, ext)) + goto out; break; case NID_sbgp_autonomousSysNum: - c = sbgp_assysnum(&p, ext); + if (!sbgp_assysnum(&p, ext)) + goto out; break; case NID_sinfo_access: sia_present = 1; - c = sbgp_sia(&p, ext); + if (!sbgp_sia(&p, ext)) + goto out; break; case NID_certificate_policies: - c = certificate_policies(&p, ext); + if (!certificate_policies(&p, ext)) + goto out; break; case NID_crl_distribution_points: /* ignored here, handled later */ @@ -1125,8 +1128,6 @@ cert_parse_pre(const char *fn, const uns } */ break; } - if (c == 0) - goto out; } if (!x509_get_aki(x, p.fn, &p.res->aki)) @@ -1182,14 +1183,12 @@ cert_parse_pre(const char *fn, const uns } p.res->x509 = x; + return p.res; - rc = 1; out: - if (rc == 0) { - cert_free(p.res); - X509_free(x); - } - return (rc == 0) ? NULL : p.res; + cert_free(p.res); + X509_free(x); + return NULL; } struct cert *