comparison src/core/ngx_hash.c @ 4728:fc62b72f7597 stable-1.2

Merge of r4690: conflicting wildcard server names fix. With previous code wildcard names were added to hash even if conflict was detected. This resulted in identical names in hash and segfault later in ngx_hash_wildcard_init().
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 02 Jul 2012 16:59:34 +0000
parents d620f497c50f
children c348dea081fb
comparison
equal deleted inserted replaced
4727:1c7616100797 4728:fc62b72f7597
922 hwc = &ha->dns_wc_tail; 922 hwc = &ha->dns_wc_tail;
923 keys = &ha->dns_wc_tail_hash[k]; 923 keys = &ha->dns_wc_tail_hash[k];
924 } 924 }
925 925
926 926
927 /* check conflicts in wildcard hash */
928
929 name = keys->elts;
930
931 if (name) {
932 len = last - skip;
933
934 for (i = 0; i < keys->nelts; i++) {
935 if (len != name[i].len) {
936 continue;
937 }
938
939 if (ngx_strncmp(key->data + skip, name[i].data, len) == 0) {
940 return NGX_BUSY;
941 }
942 }
943
944 } else {
945 if (ngx_array_init(keys, ha->temp_pool, 4, sizeof(ngx_str_t)) != NGX_OK)
946 {
947 return NGX_ERROR;
948 }
949 }
950
951 name = ngx_array_push(keys);
952 if (name == NULL) {
953 return NGX_ERROR;
954 }
955
956 name->len = last - skip;
957 name->data = ngx_pnalloc(ha->temp_pool, name->len);
958 if (name->data == NULL) {
959 return NGX_ERROR;
960 }
961
962 ngx_memcpy(name->data, key->data + skip, name->len);
963
964
965 /* add to wildcard hash */
966
927 hk = ngx_array_push(hwc); 967 hk = ngx_array_push(hwc);
928 if (hk == NULL) { 968 if (hk == NULL) {
929 return NGX_ERROR; 969 return NGX_ERROR;
930 } 970 }
931 971
932 hk->key.len = last - 1; 972 hk->key.len = last - 1;
933 hk->key.data = p; 973 hk->key.data = p;
934 hk->key_hash = 0; 974 hk->key_hash = 0;
935 hk->value = value; 975 hk->value = value;
936 976
937
938 /* check conflicts in wildcard hash */
939
940 name = keys->elts;
941
942 if (name) {
943 len = last - skip;
944
945 for (i = 0; i < keys->nelts; i++) {
946 if (len != name[i].len) {
947 continue;
948 }
949
950 if (ngx_strncmp(key->data + skip, name[i].data, len) == 0) {
951 return NGX_BUSY;
952 }
953 }
954
955 } else {
956 if (ngx_array_init(keys, ha->temp_pool, 4, sizeof(ngx_str_t)) != NGX_OK)
957 {
958 return NGX_ERROR;
959 }
960 }
961
962 name = ngx_array_push(keys);
963 if (name == NULL) {
964 return NGX_ERROR;
965 }
966
967 name->len = last - skip;
968 name->data = ngx_pnalloc(ha->temp_pool, name->len);
969 if (name->data == NULL) {
970 return NGX_ERROR;
971 }
972
973 ngx_memcpy(name->data, key->data + skip, name->len);
974
975 return NGX_OK; 977 return NGX_OK;
976 } 978 }