You can always ask if they would like a hug. Even if they would not, they would recognize the question in and of itself as a gesture of kindness and appreciate it as such.
While it truly varies for each person and each situation, gestures of kindness are usually appreciated, such as asking them the root of the problem, consoling their fears, if they share any, telling them that "it's going to be okay," even if you have no reason to believe that it is; a good strategy is to bring up something that they find humorous or entertaining to divert their attention from their source of pain. Examples would be bringing up a band or television show that they enjoy: I, personally, am not amazing at humor, though a Google search should yield results on how to make someone laugh (laughter is the best medicine, they say).
No matter how poorly the interaction goes (some people, while crying, will be so upset that any attempt at socialization or comfort by anyone would automatically fail), telling them that you hope that they feel better or that the situation will turn in their favor will often take away a little of their pain, even if they do not show it outwardly.