You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
3.3 KiB

  1. diff --git a/lib/x509/ip-in-cidr.h b/lib/x509/ip-in-cidr.h
  2. index 778502a..7613de9 100644
  3. --- a/lib/x509/ip-in-cidr.h
  4. +++ b/lib/x509/ip-in-cidr.h
  5. @@ -36,6 +36,8 @@ static unsigned ip_in_cidr(const gnutls_datum_t *ip, const gnutls_datum_t *cidr)
  6. {
  7. char str_ip[48];
  8. char str_cidr[97];
  9. + unsigned byte;
  10. +
  11. _gnutls_hard_log("matching %.*s with CIDR constraint %.*s\n",
  12. (int) sizeof(str_ip),
  13. _gnutls_ip_to_string(ip->data, ip->size, str_ip, sizeof(str_ip)),
  14. @@ -43,7 +45,7 @@ static unsigned ip_in_cidr(const gnutls_datum_t *ip, const gnutls_datum_t *cidr)
  15. _gnutls_cidr_to_string(cidr->data, cidr->size, str_cidr, sizeof(str_cidr)));
  16. unsigned ipsize = ip->size;
  17. - for (unsigned byte = 0; byte < ipsize; byte++)
  18. + for (byte = 0; byte < ipsize; byte++)
  19. if (((ip->data[byte] ^ cidr->data[byte]) & cidr->data[ipsize+byte]) != 0)
  20. return 0;
  21. diff --git a/lib/x509/ip.c b/lib/x509/ip.c
  22. index 9316933..b4b31a4 100644
  23. --- a/lib/x509/ip.c
  24. +++ b/lib/x509/ip.c
  25. @@ -175,10 +175,13 @@ static void prefix_to_mask(unsigned prefix, unsigned char *mask, size_t mask_siz
  26. *
  27. * Returns: On success, %GNUTLS_E_SUCCESS (0) is returned, otherwise a negative error value.
  28. -*/
  29. -int _gnutls_mask_ip(unsigned char *ip, const unsigned char *mask, unsigned ipsize) {
  30. +int _gnutls_mask_ip(unsigned char *ip, const unsigned char *mask, unsigned ipsize)
  31. +{
  32. + unsigned i;
  33. +
  34. if (ipsize != 4 && ipsize != 16)
  35. return GNUTLS_E_MALFORMED_CIDR;
  36. - for (unsigned i = 0;i < ipsize; i++)
  37. + for (i = 0; i < ipsize; i++)
  38. ip[i] &= mask[i];
  39. return GNUTLS_E_SUCCESS;
  40. }
  41. diff --git a/lib/x509/name_constraints.c b/lib/x509/name_constraints.c
  42. index 98c0f02..196e6d9 100644
  43. --- a/lib/x509/name_constraints.c
  44. +++ b/lib/x509/name_constraints.c
  45. @@ -777,6 +777,7 @@ name_constraints_intersect_nodes(name_constraints_node_st * nc1,
  46. *_intersection = NULL;
  47. name_constraints_node_st *to_copy = NULL;
  48. unsigned iplength = 0;
  49. + unsigned byte;
  50. if (nc1->type != nc2->type) {
  51. return GNUTLS_E_SUCCESS;
  52. @@ -796,7 +797,7 @@ name_constraints_intersect_nodes(name_constraints_node_st * nc1,
  53. if (nc1->name.size != nc2->name.size)
  54. return GNUTLS_E_SUCCESS;
  55. iplength = nc1->name.size/2;
  56. - for (unsigned byte = 0; byte < iplength; byte++) {
  57. + for (byte = 0; byte < iplength; byte++) {
  58. if (((nc1->name.data[byte]^nc2->name.data[byte]) // XOR of addresses
  59. & nc1->name.data[byte+iplength] // AND mask from nc1
  60. & nc2->name.data[byte+iplength]) // AND mask from nc2
  61. @@ -813,6 +814,8 @@ name_constraints_intersect_nodes(name_constraints_node_st * nc1,
  62. }
  63. // copy existing node if applicable
  64. if (to_copy != NULL) {
  65. + unsigned byte;
  66. +
  67. *_intersection = name_constraints_node_new(to_copy->type, to_copy->name.data, to_copy->name.size);
  68. if (*_intersection == NULL)
  69. return gnutls_assert_val(GNUTLS_E_MEMORY_ERROR);
  70. @@ -822,7 +825,7 @@ name_constraints_intersect_nodes(name_constraints_node_st * nc1,
  71. _gnutls_mask_ip(intersection->name.data, intersection->name.data+iplength, iplength);
  72. _gnutls_mask_ip(nc1->name.data, nc1->name.data+iplength, iplength);
  73. // update intersection, if necessary (we already know one is subset of other)
  74. - for (unsigned byte = 0; byte < 2 * iplength; byte++) {
  75. + for (byte = 0; byte < 2 * iplength; byte++) {
  76. intersection->name.data[byte] |= nc1->name.data[byte];
  77. }
  78. }