Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid NPE during token update #814

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inc_internal/zt_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ uint64_t ziti_channel_latency(ziti_channel_t *ch);

int ziti_channel_force_connect(ziti_channel_t *ch);

int ziti_channel_update_token(ziti_channel_t *ch);
int ziti_channel_update_token(ziti_channel_t *ch, const char *token);

int ziti_channel_update_posture(ziti_channel_t *ch, const uint8_t *data, size_t len);

Expand Down
13 changes: 9 additions & 4 deletions library/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define POOLED_MESSAGE_SIZE (32 * 1024)
#define INBOUND_POOL_SIZE (32)

#define CH_LOG(lvl, fmt, ...) ZITI_LOG(lvl, "ch[%d] " fmt, ch->id, ##__VA_ARGS__)

Check warning on line 41 in library/channel.c

View workflow job for this annotation

GitHub Actions / Linux ARM

format '%ld' expects argument of type 'long int', but argument 10 has type 'size_t' ***aka 'unsigned int'*** [-Wformat=]

enum ChannelState {
Initial,
Expand Down Expand Up @@ -318,18 +318,23 @@
}
}

int ziti_channel_update_token(ziti_channel_t *ch) {
int ziti_channel_update_token(ziti_channel_t *ch, const char *token) {
if (ch == NULL) {
return ZITI_INVALID_STATE;
}

if (token == NULL) {
return ZITI_NOT_AUTHORIZED;
}

if (ch->state != Connected) {
return ZITI_GATEWAY_UNAVAILABLE;
}

const char* token = ziti_get_api_session_token(ch->ztx);
ziti_channel_send_for_reply(ch, ContentTypeUpdateToken,
NULL, 0, token, strlen(token), token_update_cb, ch);
CH_LOG(DEBUG, "sending token update");
ziti_channel_send_for_reply(ch, ContentTypeUpdateToken, NULL, 0,
(const uint8_t *)token, strlen(token),
token_update_cb, ch);
return ZITI_OK;
}

Expand Down Expand Up @@ -741,7 +746,7 @@
},
};
ch->latency = uv_now(ch->loop);
ziti_channel_send_for_reply(ch, ContentTypeHelloType, headers, 2, ch->token, strlen(ch->token), hello_reply_cb, ch);

Check warning on line 749 in library/channel.c

View workflow job for this annotation

GitHub Actions / MacOS arm64

passing 'char[37]' to parameter of type 'const uint8_t *' (aka 'const unsigned char *') converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]

Check warning on line 749 in library/channel.c

View workflow job for this annotation

GitHub Actions / MacOS x86_64

passing 'char[37]' to parameter of type 'const uint8_t *' (aka 'const unsigned char *') converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
}


Expand Down Expand Up @@ -919,7 +924,7 @@

CH_LOG(TRACE, "on_data [len=%zd]", len);
ch->last_read = uv_now(ch->loop);
buffer_append(ch->incoming, buf->base, (uint32_t) len);

Check warning on line 927 in library/channel.c

View workflow job for this annotation

GitHub Actions / MacOS arm64

passing 'char *const' to parameter of type 'uint8_t *' (aka 'unsigned char *') converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]

Check warning on line 927 in library/channel.c

View workflow job for this annotation

GitHub Actions / MacOS x86_64

passing 'char *const' to parameter of type 'uint8_t *' (aka 'unsigned char *') converts between pointers to integer types where one is of the unique plain 'char' type and the other is not [-Wpointer-sign]
process_inbound(ch);
}

Expand Down
4 changes: 3 additions & 1 deletion library/ziti.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,10 @@
}

void ziti_set_fully_authenticated(ziti_context ztx, const char *session_token) {
assert(session_token);
ZTX_LOG(DEBUG, "setting auth_state[%d] to %d",
ztx->auth_state, ZitiAuthStateFullyAuthenticated);
ztx->auth_state = ZitiAuthStateFullyAuthenticated;

if (ztx->session_token == NULL || strcmp(ztx->session_token, session_token) != 0) {
free(ztx->session_token);
Expand All @@ -370,7 +372,7 @@
const char* url;
ziti_channel_t *ch;
MODEL_MAP_FOREACH(url, ch, &ztx->channels) {
ziti_channel_update_token(ch);
ziti_channel_update_token(ch, session_token);
}
}
ziti_ctrl_get_well_known_certs(ctrl, ca_bundle_cb, ztx);
Expand Down Expand Up @@ -1708,7 +1710,7 @@
id_it = model_list_it_remove(id_it);
}

MODEL_MAP_FOREACH(conn_id, conn, &ztx->connections) {

Check warning on line 1713 in library/ziti.c

View workflow job for this annotation

GitHub Actions / MacOS arm64

comparison between pointer and integer ('uint32_t' (aka 'unsigned int') and 'void *') [-Wpointer-integer-compare]

Check warning on line 1713 in library/ziti.c

View workflow job for this annotation

GitHub Actions / MacOS x86_64

comparison between pointer and integer ('uint32_t' (aka 'unsigned int') and 'void *') [-Wpointer-integer-compare]
if (conn->type == Server) {
update_bindings(conn);
}
Expand Down
Loading