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

Fix config segfault #718

Merged
merged 2 commits into from
Oct 8, 2024
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
1 change: 1 addition & 0 deletions include/zenoh-pico/link/config/raweth.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ z_result_t _z_endpoint_raweth_valid(_z_endpoint_t *endpoint);
z_result_t _z_new_link_raweth(_z_link_t *zl, _z_endpoint_t endpoint);
size_t _z_raweth_config_strlen(const _z_str_intmap_t *s);
char *_z_raweth_config_to_str(const _z_str_intmap_t *s);
z_result_t _z_raweth_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n);
z_result_t _z_raweth_config_from_str(_z_str_intmap_t *strint, const char *s);

#endif /* ZENOH_PICO_LINK_CONFIG_RAWETH_H */
13 changes: 7 additions & 6 deletions src/link/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,42 +288,43 @@ z_result_t _z_endpoint_config_from_string(_z_str_intmap_t *strint, _z_string_t *
char *p_start = (char *)memchr(_z_string_data(str), ENDPOINT_CONFIG_SEPARATOR, _z_string_len(str));
if (p_start != NULL) {
p_start = _z_ptr_char_offset(p_start, 1);
size_t cfg_size = _z_string_len(str) - _z_ptr_char_diff(_z_string_data(str), p_start);

// Call the right configuration parser depending on the protocol
_z_string_t cmp_str = _z_string_null();
#if Z_FEATURE_LINK_TCP == 1
cmp_str = _z_string_alias_str(TCP_SCHEMA);
if (_z_string_equals(proto, &cmp_str)) {
return _z_tcp_config_from_str(strint, p_start);
return _z_tcp_config_from_strn(strint, p_start, cfg_size);
}
#endif
#if Z_FEATURE_LINK_UDP_UNICAST == 1 || Z_FEATURE_LINK_UDP_MULTICAST == 1
cmp_str = _z_string_alias_str(UDP_SCHEMA);
if (_z_string_equals(proto, &cmp_str)) {
return _z_udp_config_from_str(strint, p_start);
return _z_udp_config_from_strn(strint, p_start, cfg_size);
}
#endif
#if Z_FEATURE_LINK_BLUETOOTH == 1
cmp_str = _z_string_alias_str(BT_SCHEMA);
if (_z_string_equals(proto, &cmp_str)) {
return _z_bt_config_from_str(strint, p_start);
return _z_bt_config_from_strn(strint, p_start, cfg_size);
}
#endif
#if Z_FEATURE_LINK_SERIAL == 1
cmp_str = _z_string_alias_str(SERIAL_SCHEMA);
if (_z_string_equals(proto, &cmp_str)) {
return _z_serial_config_from_str(strint, p_start);
return _z_serial_config_from_strn(strint, p_start, cfg_size);
}
#endif
#if Z_FEATURE_LINK_WS == 1
cmp_str = _z_string_alias_str(WS_SCHEMA);
if (_z_string_equals(proto, &cmp_str)) {
return _z_ws_config_from_str(strint, p_start);
return _z_ws_config_from_strn(strint, p_start, cfg_size);
}
#endif
cmp_str = _z_string_alias_str(RAWETH_SCHEMA);
if (_z_string_equals(proto, &cmp_str)) {
return _z_raweth_config_from_str(strint, p_start);
return _z_raweth_config_from_strn(strint, p_start, cfg_size);
}
}
return _Z_RES_OK;
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/iobuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void _z_zbuf_clear(_z_zbuf_t *zbf) { _z_iosli_clear(&zbf->_ios); }
void _z_zbuf_compact(_z_zbuf_t *zbf) {
if ((zbf->_ios._r_pos != 0) || (zbf->_ios._w_pos != 0)) {
size_t len = _z_iosli_readable(&zbf->_ios);
(void)memcpy(zbf->_ios._buf, _z_zbuf_get_rptr(zbf), len);
(void)memmove(zbf->_ios._buf, _z_zbuf_get_rptr(zbf), len);
_z_zbuf_set_rpos(zbf, 0);
_z_zbuf_set_wpos(zbf, len);
}
Expand Down
16 changes: 14 additions & 2 deletions src/transport/raweth/link.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,9 +500,13 @@ char *_z_raweth_config_to_str(const _z_str_intmap_t *s) {
return _z_str_intmap_to_str(s, RAWETH_CONFIG_ARGC, args);
}

z_result_t _z_raweth_config_from_str(_z_str_intmap_t *strint, const char *s) {
z_result_t _z_raweth_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n) {
RAWETH_CONFIG_MAPPING_BUILD
return _z_str_intmap_from_strn(strint, s, RAWETH_CONFIG_ARGC, args, strlen(s));
return _z_str_intmap_from_strn(strint, s, RAWETH_CONFIG_ARGC, args, n);
}

z_result_t _z_raweth_config_from_str(_z_str_intmap_t *strint, const char *s) {
return _z_raweth_config_from_strn(strint, s, strlen(s));
}

#else
Expand All @@ -521,11 +525,19 @@ size_t _z_raweth_config_strlen(const _z_str_intmap_t *s) {
_ZP_UNUSED(s);
return 0;
}

char *_z_raweth_config_to_str(const _z_str_intmap_t *s) {
_ZP_UNUSED(s);
return NULL;
}

z_result_t _z_raweth_config_from_strn(_z_str_intmap_t *strint, const char *s, size_t n) {
_ZP_UNUSED(strint);
_ZP_UNUSED(s);
_ZP_UNUSED(n);
return _Z_ERR_TRANSPORT_NOT_AVAILABLE;
}

z_result_t _z_raweth_config_from_str(_z_str_intmap_t *strint, const char *s) {
_ZP_UNUSED(strint);
_ZP_UNUSED(s);
Expand Down
Loading