-/* $OpenBSD: x509_addr.c,v 1.64 2022/01/05 17:36:32 tb Exp $ */
+/* $OpenBSD: x509_addr.c,v 1.65 2022/01/05 17:38:14 tb Exp $ */
/*
* Contributed to the OpenSSL Project by the American Registry for
* Internet Numbers ("ARIN").
IPAddrBlocks *child = NULL, *parent = NULL;
IPAddressFamily *fc, *fp;
IPAddressOrRanges *aorc, *aorp;
- X509 *x;
- int i, j, k;
+ X509 *x = NULL;
+ int depth = -1;
+ int j, k;
unsigned int length;
int ret = 1;
* we're done. Otherwise, check canonical form and set up for walking
* up the chain.
*/
- if (ext != NULL) {
- i = -1;
- x = NULL;
- } else {
- i = 0;
- x = sk_X509_value(chain, i);
+ if (ext == NULL) {
+ depth = 0;
+ x = sk_X509_value(chain, depth);
if ((ext = x->rfc3779_addr) == NULL)
goto done;
}
if (!X509v3_addr_is_canonical(ext)) {
if ((ret = verify_error(ctx, x,
- X509_V_ERR_INVALID_EXTENSION, i)) == 0)
+ X509_V_ERR_INVALID_EXTENSION, depth)) == 0)
goto done;
}
* Now walk up the chain. No cert may list resources that its parent
* doesn't list.
*/
- for (i++; i < sk_X509_num(chain); i++) {
- x = sk_X509_value(chain, i);
+ for (depth++; depth < sk_X509_num(chain); depth++) {
+ x = sk_X509_value(chain, depth);
if ((parent = x->rfc3779_addr) == NULL) {
for (j = 0; j < sk_IPAddressFamily_num(child); j++) {
continue;
if ((ret = verify_error(ctx, x,
- X509_V_ERR_UNNESTED_RESOURCE, i)) == 0)
+ X509_V_ERR_UNNESTED_RESOURCE, depth)) == 0)
goto done;
break;
}
if (!X509v3_addr_is_canonical(parent)) {
if ((ret = verify_error(ctx, x,
- X509_V_ERR_INVALID_EXTENSION, i)) == 0)
+ X509_V_ERR_INVALID_EXTENSION, depth)) == 0)
goto done;
}
/* Otherwise the child isn't covered. */
if ((ret = verify_error(ctx, x,
- X509_V_ERR_UNNESTED_RESOURCE, i)) == 0)
+ X509_V_ERR_UNNESTED_RESOURCE, depth)) == 0)
goto done;
break;
}
}
if ((ret = verify_error(ctx, x,
- X509_V_ERR_UNNESTED_RESOURCE, i)) == 0)
+ X509_V_ERR_UNNESTED_RESOURCE, depth)) == 0)
goto done;
}
}
continue;
if ((ret = verify_error(ctx, x,
- X509_V_ERR_UNNESTED_RESOURCE, i)) == 0)
+ X509_V_ERR_UNNESTED_RESOURCE, depth)) == 0)
goto done;
}
}