Neither of those sentences is incorrect, and I'd venture to say they do not even sound awkward.
Using the same word twice in a sentence – particularly when the word in question is a preposition – won't cause a native reader to blink twice.
There are even a few words in English that are used back-to-back once in a while, such as had and that:
The two had had an almost classic friendship. (D.H. Lawrence, The Rainbow)
I never could make him understand that that was what civilized people ought to do (A. Huxley, Brave New World).
Common sense rules apply, though. A single word used too often in a sentence will eventually start to read awkwardly, depending on how many times the word is used, how close together those words are in the sentence, and what the meanings of those words are. The infamous "Buffalo sentence," for example, may be grammatically correct, but it's really just a novelty, and wouldn't be useful in any form of real communication.
Every once in a while, I'll read something that I've written, and think to myself, "That word sounds overused; I should find a synonym." For example, I'd likely change:
She lived in a big house with a big garage on the outskirts of a big city.
She lived in a big house with a spacious garage on the outskirts of a major city.
However, word overuse is a style issue; there's nothing "incorrect" about using a word too many times in a sentence. Moreover, for prepositions, it's best to use the most appropriate preposition available, and using the same preposition twice – even in a short sentence – would not be considered bad practice. In fact, if used properly, a little bit of repetition can create a parallel structure that is easy to follow and almost poetic to read:
It was the best of times, it was the worst of times.
There's no hard-and-fast rule; you simply need to use your best judgement.