From 1cd7eb316e44cd1f6973c0738d8b06a361e87505 Mon Sep 17 00:00:00 2001 From: Herman Venter Date: Wed, 12 Jun 2013 15:32:08 -0700 Subject: [PATCH] Check precondition before calling set_execution_mode set_execution_mode has an assertion that amounts to a precondition requiring that its input parameters have been validated. This causes hhvm to assert and crash if the user specifies an invalid mode on the command line. --- hphp/runtime/base/program_functions.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/hphp/runtime/base/program_functions.cpp b/hphp/runtime/base/program_functions.cpp index 999142a9a..74833a61d 100644 --- a/hphp/runtime/base/program_functions.cpp +++ b/hphp/runtime/base/program_functions.cpp @@ -864,13 +864,20 @@ static int execute_program_impl(int argc, char **argv) { if (po.mode == "s") po.mode = "server"; if (po.mode == "t") po.mode = "translate"; if (po.mode == "") po.mode = "run"; - set_execution_mode(po.mode); + if (po.mode == "daemon" || po.mode == "server" || po.mode == "replay" || + po.mode == "run" || po.mode == "debug"|| po.mode == "translate") { + set_execution_mode(po.mode); + } else { + Logger::Error("Error in command line: invalid mode: %s", po.mode.c_str()); + cout << desc << "\n"; + return -1; + } } catch (error &e) { - Logger::Error("Error in command line: %s\n\n", e.what()); + Logger::Error("Error in command line: %s", e.what()); cout << desc << "\n"; return -1; } catch (...) { - Logger::Error("Error in command line:\n\n"); + Logger::Error("Error in command line."); cout << desc << "\n"; return -1; }