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(mme): Null terminates string to stop buffer overflow #11925

Merged
merged 1 commit into from
Mar 5, 2022
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
4 changes: 2 additions & 2 deletions lte/gateway/c/core/oai/common/state_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void StateConverter::guti_to_proto(const guti_t& state_guti,
oai::Guti* guti_proto) {
guti_proto->Clear();

char plmn_array[PLMN_BYTES + 1];
char plmn_array[PLMN_BYTES] = {0};
plmn_to_chars(state_guti.gummei.plmn, plmn_array);
guti_proto->set_plmn(plmn_array);
guti_proto->set_mme_gid(state_guti.gummei.mme_gid);
Expand All @@ -74,7 +74,7 @@ void StateConverter::ecgi_to_proto(const ecgi_t& state_ecgi,
oai::Ecgi* ecgi_proto) {
ecgi_proto->Clear();

char plmn_array[PLMN_BYTES + 1];
char plmn_array[PLMN_BYTES] = {0};
plmn_to_chars(state_ecgi.plmn, plmn_array);
ecgi_proto->set_plmn(plmn_array);
ecgi_proto->set_enb_id(state_ecgi.cell_identity.enb_id);
Expand Down
2 changes: 1 addition & 1 deletion lte/gateway/c/core/oai/include/state_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace magma {
namespace lte {

#define ASCII_ZERO 0x30
#define PLMN_BYTES 6
#define PLMN_BYTES 7
#define BSTRING_TO_STRING(bstr, str_ptr) \
do { \
*str_ptr = std::string(bdata(bstr), blength(bstr)); \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void AmfNasStateConverter::tai_to_proto(const tai_t* state_tai,
magma::lte::oai::Tai* tai_proto) {
OAILOG_DEBUG(LOG_MME_APP, "State PLMN " PLMN_FMT "to proto",
PLMN_ARG(&state_tai->plmn));
char plmn_array[PLMN_BYTES];
char plmn_array[PLMN_BYTES] = {0};
plmn_array[0] = static_cast<char>(state_tai->plmn.mcc_digit1 + ASCII_ZERO);
plmn_array[1] = static_cast<char>(state_tai->plmn.mcc_digit2 + ASCII_ZERO);
plmn_array[2] = static_cast<char>(state_tai->plmn.mcc_digit3 + ASCII_ZERO);
Expand Down Expand Up @@ -327,7 +327,7 @@ void AmfNasStateConverter::proto_to_tai(const magma::lte::oai::Tai& tai_proto,
void AmfNasStateConverter::guti_m5_to_proto(
const guti_m5_t& state_guti_m5, magma::lte::oai::Guti_m5* guti_m5_proto) {
guti_m5_proto->Clear();
char plmn_array[PLMN_BYTES];
char plmn_array[PLMN_BYTES] = {0};
AmfNasStateConverter::plmn_to_chars(state_guti_m5.guamfi.plmn, plmn_array);
guti_m5_proto->set_plmn(plmn_array);
guti_m5_proto->set_amf_regionid(state_guti_m5.guamfi.amf_regionid);
Expand Down
4 changes: 2 additions & 2 deletions lte/gateway/c/core/oai/tasks/nas/nas_state_converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void NasStateConverter::partial_tai_list_to_proto(
partial_tai_list_proto->mutable_tai_one_plmn_consecutive_tacs());
} break;
case TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_NON_CONSECUTIVE_TACS: {
char plmn_array[PLMN_BYTES];
char plmn_array[PLMN_BYTES] = {0};
plmn_array[0] =
(char)(state_partial_tai_list->u.tai_one_plmn_non_consecutive_tacs
.plmn.mcc_digit1 +
Expand Down Expand Up @@ -153,7 +153,7 @@ void NasStateConverter::tai_to_proto(const tai_t* state_tai,
oai::Tai* tai_proto) {
OAILOG_DEBUG(LOG_MME_APP, "State PLMN " PLMN_FMT "to proto",
PLMN_ARG(&state_tai->plmn));
char plmn_array[PLMN_BYTES];
char plmn_array[PLMN_BYTES] = {0};
plmn_array[0] = (char)(state_tai->plmn.mcc_digit1 + ASCII_ZERO);
plmn_array[1] = (char)(state_tai->plmn.mcc_digit2 + ASCII_ZERO);
plmn_array[2] = (char)(state_tai->plmn.mcc_digit3 + ASCII_ZERO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void NgapStateConverter::supported_tai_item_to_proto(
supported_tai_item_proto->set_tac(state_supported_tai_item->tac);
supported_tai_item_proto->set_bplmnlist_count(
state_supported_tai_item->bplmnlist_count);
char plmn_array[PLMN_BYTES + 1] = {0};
char plmn_array[PLMN_BYTES] = {0};
for (int idx = 0; idx < state_supported_tai_item->bplmnlist_count; idx++) {
plmn_array[0] = static_cast<char>(
state_supported_tai_item->bplmn_list[idx].plmn_id.mcc_digit1 +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void S1apStateConverter::supported_tai_item_to_proto(
supported_tai_item_proto->set_tac(state_supported_tai_item->tac);
supported_tai_item_proto->set_bplmnlist_count(
state_supported_tai_item->bplmnlist_count);
char plmn_array[PLMN_BYTES + 1] = {0};
char plmn_array[PLMN_BYTES] = {0};
for (int idx = 0; idx < state_supported_tai_item->bplmnlist_count; idx++) {
plmn_array[0] =
(char)(state_supported_tai_item->bplmns[idx].mcc_digit1 + ASCII_ZERO);
Expand Down