Have no fear. It is indeed legal to remain in the U.S. for up to 180 days while an application for a change of status is pending, or until the decision, whichever comes first.
Should the application to change status result in a denial , then you will be requested to leave the country at once. There is no grace period, unfortunately. The rule of thumb is "reasonable" time. 10 days or so, from the time you receive the denial notice, will be considered reasonable.
Behar Intl. Counsel 619.234.5962 Kindly be advised that the answer above is only general in nature cannot be construed as legal advice, given that not enough facts are known. It is your responsibility to retain a lawyer to analyze the facts specific to your particular situation in order to give you specific advice. Specific answers will require cognizance of all pertinent facts about your case. Any answers offered on Avvo are of a general nature only, and are not meant to create an attorney-client relationship.