Skip to content

Commit d3a58bd

Browse files
authored
Merge pull request #524 from openziti/fix-binding-parameters
make sure terminator cost and precedence headers use expected sizes
2 parents d7f329f + 2c97161 commit d3a58bd

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

library/connect.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,8 +1117,8 @@ static int ziti_channel_start_connection(struct ziti_conn *conn, ziti_channel_t
11171117
if (req->listen_opts != NULL) {
11181118
ziti_listen_opts *opts = req->listen_opts;
11191119
char *identity = opts->identity;
1120-
int term_cost = get_terminator_cost(opts, conn->conn_req->service_id, conn->ziti_ctx);
1121-
int term_prec = get_terminator_precedence(opts, conn->conn_req->service_id, conn->ziti_ctx);
1120+
uint16_t term_cost = get_terminator_cost(opts, conn->conn_req->service_id, conn->ziti_ctx);
1121+
uint8_t term_prec = get_terminator_precedence(opts, conn->conn_req->service_id, conn->ziti_ctx);
11221122

11231123
if (opts->bind_using_edge_identity) {
11241124
if (opts->identity != NULL) {
@@ -1135,17 +1135,16 @@ static int ziti_channel_start_connection(struct ziti_conn *conn, ziti_channel_t
11351135
nheaders++;
11361136
}
11371137
if (term_cost > 0) {
1138-
int32_t cost = htole32(term_cost);
1138+
uint16_t cost = htole16(term_cost);
11391139
headers[nheaders].header_id = CostHeader;
11401140
headers[nheaders].value = (uint8_t *) &cost;
11411141
headers[nheaders].length = sizeof(cost);
11421142
nheaders++;
11431143
}
11441144
if (term_prec != PRECEDENCE_DEFAULT) {
1145-
int32_t precedence = htole32(term_prec);
11461145
headers[nheaders].header_id = PrecedenceHeader;
1147-
headers[nheaders].value = (uint8_t *) &precedence;
1148-
headers[nheaders].length = sizeof(precedence);
1146+
headers[nheaders].value = &term_prec;
1147+
headers[nheaders].length = sizeof(term_prec);
11491148
nheaders++;
11501149
}
11511150
}

library/endian_internal.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
/*
2-
Copyright 2019-2020 NetFoundry, Inc.
3-
4-
Licensed under the Apache License, Version 2.0 (the "License");
5-
you may not use this file except in compliance with the License.
6-
You may obtain a copy of the License at
7-
8-
https://www.apache.org/licenses/LICENSE-2.0
9-
10-
Unless required by applicable law or agreed to in writing, software
11-
distributed under the License is distributed on an "AS IS" BASIS,
12-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
See the License for the specific language governing permissions and
14-
limitations under the License.
15-
*/
1+
// Copyright (c) 2023. NetFoundry Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
1614

1715
#ifndef ZITI_SDK_ENDIAN_INTERNAL_H
1816
#define ZITI_SDK_ENDIAN_INTERNAL_H
@@ -26,6 +24,7 @@ limitations under the License.
2624
# include <endian.h>
2725
#elif defined (__APPLE__)
2826
# include <libkern/OSByteOrder.h>
27+
# define htole16(x) OSSwapHostToLittleInt16(x)
2928
# define htole32(x) OSSwapHostToLittleInt32(x)
3029
# define htole64(x) OSSwapHostToLittleInt64(x)
3130
# define le32toh(x) OSSwapLittleToHostInt32(x)

0 commit comments

Comments
 (0)