It depends on the details, but from what you write the answer is probably yes.
You were stopped for speeding, that is a valid reason to stop a car. Now there come several different theories that might be applicable and that all lead to the same result:
He could have performed a Terry Frisk:
A cop can order all passengers out of a car when he legally stopped it and can "pat down" everyone for weapons as a safety measure. He does not need to have "probable cause" that a crime has been committed at this point, he merely needs some kind of reason why he would assume that anyone was armed, courts are pretty lenient on this point.
He does not need any consent for this "pat down."
Once he conducts this "pat down", which must be done in a certain way, he might come upon something suspicious. Either he does not know what he feels in the pat down but reasonably thinks it could be a weapon, or he exactly knows what he is feeling and that it is contraband, he can take that item out of the pocket or wherever he felt it. If it is in fact contraband, it can be used as evidence, it can then give the officer probable cause for an arrest and an extended search. Since the officer said he would frisk for weapons, he probably intended to perform such a so called "Terry Search."
The other theory the search could be based on depending on the circumstances is that he actually had already probable cause that some evidence of a crime could be found and exigent circumstances allowed a warrantless search.
Under both theories the search would have been legal.
Now, as I said, it depends on the actual details of what exactly happened, so if you should be charged, you should discuss the search with your attorney. This here can only be a general overview of the law. Your attorney might find circumstances were such that they make this search illegal.