Skip to content

Commit

Permalink
hdd.c null terminate strings copied with strncpy()
Browse files Browse the repository at this point in the history
  • Loading branch information
KrahJohlito committed Aug 3, 2021
1 parent a8d9a39 commit 4544141
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/hdd.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ struct GameDataEntry
{
u32 lba, size;
struct GameDataEntry *next;
char id[APA_IDMAX];
char id[APA_IDMAX + 1];
};

static int hddGetHDLGameInfo(struct GameDataEntry *game, hdl_game_info_t *ginfo)
Expand All @@ -152,7 +152,9 @@ static int hddGetHDLGameInfo(struct GameDataEntry *game, hdl_game_info_t *ginfo)
strncpy(ginfo->partition_name, game->id, APA_IDMAX);
ginfo->partition_name[APA_IDMAX] = '\0';
strncpy(ginfo->name, hdl_header->gamename, HDL_GAME_NAME_MAX);
ginfo->name[HDL_GAME_NAME_MAX] = '\0';
strncpy(ginfo->startup, hdl_header->startup, sizeof(ginfo->startup) - 1);
ginfo->startup[sizeof(ginfo->startup) - 1] = '\0';
ginfo->hdl_compat_flags = hdl_header->hdl_compat_flags;
ginfo->ops2l_compat_flags = hdl_header->ops2l_compat_flags;
ginfo->dma_type = hdl_header->dma_type;
Expand Down Expand Up @@ -207,6 +209,7 @@ int hddGetHDLGamelist(hdl_games_list_t *game_list)
break;

strncpy(current->id, dirent.name, APA_IDMAX);
current->id[APA_IDMAX] = '\0';
count++;
current->next = NULL;
current->size = 0;
Expand Down

0 comments on commit 4544141

Please sign in to comment.