See the lot-cloth split section of Wikipedia. Here are two excerpts:
The lengthening and raising generally happened before the fricatives /f/, /θ/ and /s/. In American English the raising was extended to the environment before /ŋ/ and /ɡ/, and in a few words before /k/ as well, giving pronunciations like /lɔŋ/ for long, /dɔɡ/ for dog, and /tʃɔklɨt/ for chocolate.
The sound change is most consistent in the last syllable of a word, and much less so elsewhere. Some words that entered the language later, especially when used more in writing than speech, are exempt from the lengthening, e.g. joss and Goth with the short vowel.
Translating from IPA for those people who don't know it, the vowel is generally long before the sounds 'f', 's', 'th', 'g', 'ng', 'nk', especially in one-syllable words. There are exceptions both ways. For example, it's usually short in cog and long in chocolate. I don't believe there's any way to figure out which words are the exceptions.