The length of the exported song depends on a specific hierarchy.
As a default, the exported Project starts at the beginning and ends about a second after the end of the last Region in your Project.
If you put the the End-of-Project Marker exactly at the end of the last Region then the song ends exactly there. The end of song marker is positioned at bar 33 when opening a new Project. It can be placed between bar 8 and bar 9999 but cannot be placed before the end of the last Region. Otherwise, it only determines how far to the right you can scroll your Project.
The best way however is to use the Cycle Range. When activated (visible), then GarageBand exports the exact length of the yellow Cycle Range. In case there is an effect still going on after the last note of you song, i.e. the tail of a Reverb or a Delay, you can set the end of the cycle to make sure that it is not cut of. It is also useful when you want to export only a section of the song that doesn’t start at the beginning.
One exception is when you have a movie in your Project. In that case the export starts at the beginning (0:00) and ends with the last Region (regardless of the Cycle Range).
Hope that helps