Skip to content

Commit

Permalink
[rcheevos] Fix crash on maliformed cached login token.
Browse files Browse the repository at this point in the history
  • Loading branch information
skylersaleh committed Sep 13, 2023
1 parent 31789fc commit 27e6ab4
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1517,13 +1517,7 @@ static void se_ra_event_handler(const rc_client_event_t* event, rc_client_t* cli
}
}
static void se_init_retro_achievements(){
memset(ra_info.username, 0, sizeof(ra_info.username));
memset(ra_info.password, 0, sizeof(ra_info.password));
ra_info.is_logged_in = false;
ra_info.game_id = 0;
ra_info.image.id = SG_INVALID_ID;
ra_info.achievement_list = NULL;
ra_info.achievement_images = NULL;
memset(&ra_info, 0, sizeof(ra_info));
ra_info.mutex = create_mutex();
ra_initialize_client(se_ra_read_memory_callback);
rc_client_set_event_handler(ra_get_client(),se_ra_event_handler);
Expand All @@ -1532,16 +1526,24 @@ static void se_init_retro_achievements(){
char login_info_path[SB_FILE_PATH_SIZE];
snprintf(login_info_path,SB_FILE_PATH_SIZE,"%sra_login_info.txt",se_get_pref_path());
if (sb_file_exists(login_info_path)){
char text[sizeof(ra_info.username) + sizeof(ra_info.password) + 2];
memset(text, 0, sizeof(text));
if (sb_load_file_data_into_buffer(login_info_path, text, sizeof(text))){
int username_length = strchr(text, '\n') - text;
strncpy(ra_info.username, text, username_length);
int password_length = strchr(text + username_length + 1, '\n') - (text + username_length + 1);
size_t size;
uint8_t *text = sb_load_file_data(login_info_path,&size);
if (text){
int i = 0;
for(i=0;i<size;++i){
if(i<sizeof(ra_info.username)-1 && text[i]!='\n')ra_info.username[i]=text[i];
else break;
}
ra_info.username[i++]=0;
char token[256];
memset(token, 0, sizeof(token));
strncpy(token, text + username_length + 1, password_length);
int i2=0;
for(i2=0;i+i2<size;++i2){
if(i2<sizeof(token)-1&&text[i+i2]!='\n')token[i2]=text[i+i2];
else break;
}
token[i2]=0;
ra_login_token(ra_info.username, token, se_ra_login_callback);
free(text);
}
}
}
Expand Down Expand Up @@ -5358,10 +5360,12 @@ void se_draw_menu_panel(){
igSeparator();
if (ra_info.achievement_list){
for (int i = 0; i < ra_info.achievement_list->num_buckets; i++){
se_text(ICON_FK_LOCK " %s",ra_info.achievement_list->buckets[i].label);
for (int j = 0; j < ra_info.achievement_list->buckets[i].num_achievements; j++){
if(ra_info.achievement_images && ra_info.achievement_images[i] && ra_info.achievement_images[i][j].id!=SG_INVALID_ID){
igImageButton((ImTextureID)(intptr_t)ra_info.achievement_images[i][j].id,(ImVec2){32,32},(ImVec2){0,0},(ImVec2){1,1},0,(ImVec4){1,1,1,1},(ImVec4){1,1,1,1});
// se_text("%s",ra_info.achievement_list->buckets[i].achievements[j]->title);
se_text("%s",ra_info.achievement_list->buckets[i].achievements[j]->title);
se_text("%s",ra_info.achievement_list->buckets[i].achievements[j]->description);
}
}
}
Expand Down

0 comments on commit 27e6ab4

Please sign in to comment.