mirror of
https://github.com/open5gs/open5gs.git
synced 2025-10-23 07:41:57 +00:00
[AMF/MME] Fix potential buffer overflow in ASCII-to-USC2 conversion
In amf_context_parse_config(), update the loop condition to ensure that ((i * 2) + 1) remains below (OGS_NAS_MAX_NETWORK_NAME_LEN - 1) before performing any writes. This change prevents potential out-of-bounds memory writes during the conversion of an ASCII string to USC-2, thereby fixing a buffer overflow issue. This issue was observed on Ubuntu 25.04 and reported in the osmocom nightly package.
This commit is contained in:
@@ -977,12 +977,14 @@ int amf_context_parse_config(void)
|
||||
ogs_yaml_iter_value(&network_name_iter);
|
||||
uint8_t size = strlen(c_network_name);
|
||||
uint8_t i;
|
||||
for (i = 0;i<size;i++) {
|
||||
for (i = 0; i < size &&
|
||||
(((i * 2) + 1) <
|
||||
(OGS_NAS_MAX_NETWORK_NAME_LEN - 1));
|
||||
i++) {
|
||||
/* Workaround to convert the ASCII to USC-2 */
|
||||
network_full_name->name[i*2] = 0;
|
||||
network_full_name->name[(i*2)+1] =
|
||||
network_full_name->name[i * 2] = 0;
|
||||
network_full_name->name[i * 2 + 1] =
|
||||
c_network_name[i];
|
||||
|
||||
}
|
||||
network_full_name->length = size*2+1;
|
||||
network_full_name->coding_scheme = 1;
|
||||
@@ -994,12 +996,14 @@ int amf_context_parse_config(void)
|
||||
ogs_yaml_iter_value(&network_name_iter);
|
||||
uint8_t size = strlen(c_network_name);
|
||||
uint8_t i;
|
||||
for (i = 0;i<size;i++) {
|
||||
for (i = 0; i < size &&
|
||||
(((i * 2) + 1) <
|
||||
(OGS_NAS_MAX_NETWORK_NAME_LEN - 1));
|
||||
i++) {
|
||||
/* Workaround to convert the ASCII to USC-2 */
|
||||
network_short_name->name[i*2] = 0;
|
||||
network_short_name->name[(i*2)+1] =
|
||||
network_short_name->name[i * 2] = 0;
|
||||
network_short_name->name[i * 2 + 1] =
|
||||
c_network_name[i];
|
||||
|
||||
}
|
||||
network_short_name->length = size*2+1;
|
||||
network_short_name->coding_scheme = 1;
|
||||
|
@@ -2014,12 +2014,14 @@ int mme_context_parse_config(void)
|
||||
ogs_yaml_iter_value(&network_name_iter);
|
||||
uint8_t size = strlen(c_network_name);
|
||||
uint8_t i;
|
||||
for (i = 0;i<size;i++) {
|
||||
for (i = 0; i < size &&
|
||||
(((i * 2) + 1) <
|
||||
(OGS_NAS_MAX_NETWORK_NAME_LEN - 1));
|
||||
i++) {
|
||||
/* Workaround to convert the ASCII to USC-2 */
|
||||
network_full_name->name[i*2] = 0;
|
||||
network_full_name->name[(i*2)+1] =
|
||||
network_full_name->name[i * 2] = 0;
|
||||
network_full_name->name[i * 2 + 1] =
|
||||
c_network_name[i];
|
||||
|
||||
}
|
||||
network_full_name->length = size*2+1;
|
||||
network_full_name->coding_scheme = 1;
|
||||
@@ -2031,12 +2033,14 @@ int mme_context_parse_config(void)
|
||||
ogs_yaml_iter_value(&network_name_iter);
|
||||
uint8_t size = strlen(c_network_name);
|
||||
uint8_t i;
|
||||
for (i = 0;i<size;i++) {
|
||||
for (i = 0; i < size &&
|
||||
(((i * 2) + 1) <
|
||||
(OGS_NAS_MAX_NETWORK_NAME_LEN - 1));
|
||||
i++) {
|
||||
/* Workaround to convert the ASCII to USC-2 */
|
||||
network_short_name->name[i*2] = 0;
|
||||
network_short_name->name[(i*2)+1] =
|
||||
network_short_name->name[i * 2] = 0;
|
||||
network_short_name->name[i * 2 + 1] =
|
||||
c_network_name[i];
|
||||
|
||||
}
|
||||
network_short_name->length = size*2+1;
|
||||
network_short_name->coding_scheme = 1;
|
||||
|
Reference in New Issue
Block a user