Changeset 194590 in webkit


Ignore:
Timestamp:
Jan 5, 2016, 11:03:07 AM (10 years ago)
Author:
mark.lam@apple.com
Message:

Add validation of JSC options to catch typos.
https://bugs.webkit.org/show_bug.cgi?id=152549

Reviewed by Benjamin Poulain.

  1. If a JSC_xxx option is found and xxx is not a valid option, we will now log an error message.
  2. The jsc app is commonly used as follows:

$ jsc [jsc options] [scripts]


Previously, we'll continue to parse for [jsc options] after [scripts] is seen.
We won't do this anymore. Any --xxx jsc options must precede the [scripts]
arguments.

  1. If a --xxx jsc option is specified, but xxx is not a valid option, we will now log an error message.
  1. Added JSC_validateOptions, which if set to true will cause the VM to crash if an invalid option was seen during options parsing.
  • jsc.cpp:

(CommandLine::parseArguments):

  • runtime/Options.cpp:

(JSC::Options::initialize):

  • runtime/Options.h:
Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r194565 r194590  
     12015-12-24  Mark Lam  <mark.lam@apple.com>
     2
     3        Add validation of JSC options to catch typos.
     4        https://bugs.webkit.org/show_bug.cgi?id=152549
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        1. If a JSC_xxx option is found and xxx is not a valid option, we will now log
     9           an error message.
     10        2. The jsc app is commonly used as follows:
     11
     12               $ jsc [jsc options] [scripts]
     13     
     14           Previously, we'll continue to parse for [jsc options] after [scripts] is seen.
     15           We won't do this anymore.  Any --xxx jsc options must precede the [scripts]
     16           arguments.
     17
     18        3. If a --xxx jsc option is specified, but xxx is not a valid option, we will
     19           now log an error message.
     20
     21        4. Added JSC_validateOptions, which if set to true will cause the VM to crash if
     22           an invalid option was seen during options parsing.
     23
     24        * jsc.cpp:
     25        (CommandLine::parseArguments):
     26        * runtime/Options.cpp:
     27        (JSC::Options::initialize):
     28        * runtime/Options.h:
     29
    1302016-01-04  Keith Miller  <keith_miller@apple.com>
    231
  • trunk/Source/JavaScriptCore/jsc.cpp

    r194017 r194590  
    18901890    bool needToExit = false;
    18911891
     1892    bool doneWithJSCOptions = false;
     1893    bool hasBadJSCOptions = false;
    18921894    for (; i < argc; ++i) {
    18931895        const char* arg = argv[i];
    1894         if (!strcmp(arg, "-f")) {
    1895             if (++i == argc)
    1896                 printUsageStatement();
    1897             m_scripts.append(Script(true, argv[i]));
    1898             continue;
    1899         }
    1900         if (!strcmp(arg, "-e")) {
    1901             if (++i == argc)
    1902                 printUsageStatement();
    1903             m_scripts.append(Script(false, argv[i]));
    1904             continue;
    1905         }
    1906         if (!strcmp(arg, "-i")) {
    1907             m_interactive = true;
    1908             continue;
    1909         }
    1910         if (!strcmp(arg, "-d")) {
    1911             m_dump = true;
    1912             continue;
    1913         }
    1914         if (!strcmp(arg, "-p")) {
    1915             if (++i == argc)
    1916                 printUsageStatement();
    1917             m_profile = true;
    1918             m_profilerOutput = argv[i];
    1919             continue;
    1920         }
    1921         if (!strcmp(arg, "-m")) {
    1922             m_module = true;
    1923             continue;
    1924         }
    1925         if (!strcmp(arg, "-s")) {
     1896
     1897        if (!doneWithJSCOptions) {
     1898            if (!strcmp(arg, "-f")) {
     1899                if (++i == argc)
     1900                    printUsageStatement();
     1901                m_scripts.append(Script(true, argv[i]));
     1902                continue;
     1903            }
     1904            if (!strcmp(arg, "-e")) {
     1905                if (++i == argc)
     1906                    printUsageStatement();
     1907                m_scripts.append(Script(false, argv[i]));
     1908                continue;
     1909            }
     1910            if (!strcmp(arg, "-i")) {
     1911                m_interactive = true;
     1912                continue;
     1913            }
     1914            if (!strcmp(arg, "-d")) {
     1915                m_dump = true;
     1916                continue;
     1917            }
     1918            if (!strcmp(arg, "-p")) {
     1919                if (++i == argc)
     1920                    printUsageStatement();
     1921                m_profile = true;
     1922                m_profilerOutput = argv[i];
     1923                continue;
     1924            }
     1925            if (!strcmp(arg, "-m")) {
     1926                m_module = true;
     1927                continue;
     1928            }
     1929            if (!strcmp(arg, "-s")) {
    19261930#if HAVE(SIGNAL_H)
    1927             signal(SIGILL, _exit);
    1928             signal(SIGFPE, _exit);
    1929             signal(SIGBUS, _exit);
    1930             signal(SIGSEGV, _exit);
    1931 #endif
    1932             continue;
    1933         }
    1934         if (!strcmp(arg, "-x")) {
    1935             m_exitCode = true;
    1936             continue;
    1937         }
    1938         if (!strcmp(arg, "--")) {
    1939             ++i;
    1940             break;
    1941         }
    1942         if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
    1943             printUsageStatement(true);
    1944 
    1945         if (!strcmp(arg, "--options")) {
    1946             needToDumpOptions = true;
    1947             needToExit = true;
    1948             continue;
    1949         }
    1950         if (!strcmp(arg, "--dumpOptions")) {
    1951             needToDumpOptions = true;
    1952             continue;
    1953         }
    1954 
    1955         // See if the -- option is a JSC VM option.
    1956         if (strstr(arg, "--") == arg && JSC::Options::setOption(&arg[2])) {
    1957             // The arg was recognized as a VM option and has been parsed.
    1958             continue; // Just continue with the next arg.
    1959         }
     1931                signal(SIGILL, _exit);
     1932                signal(SIGFPE, _exit);
     1933                signal(SIGBUS, _exit);
     1934                signal(SIGSEGV, _exit);
     1935#endif
     1936                continue;
     1937            }
     1938            if (!strcmp(arg, "-x")) {
     1939                m_exitCode = true;
     1940                continue;
     1941            }
     1942            if (!strcmp(arg, "--")) {
     1943                ++i;
     1944                break;
     1945            }
     1946            if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
     1947                printUsageStatement(true);
     1948
     1949            if (!strcmp(arg, "--options")) {
     1950                needToDumpOptions = true;
     1951                needToExit = true;
     1952                continue;
     1953            }
     1954            if (!strcmp(arg, "--dumpOptions")) {
     1955                needToDumpOptions = true;
     1956                continue;
     1957            }
     1958
     1959            // See if the -- option is a JSC VM option.
     1960            if (strstr(arg, "--") == arg) {
     1961                if (!JSC::Options::setOption(&arg[2])) {
     1962                    hasBadJSCOptions = true;
     1963                    dataLog("ERROR: invalid option: ", arg, "\n");
     1964                }
     1965                continue;
     1966            }
     1967
     1968            doneWithJSCOptions = true;
     1969
     1970        } // !doneWithJSCOptions
    19601971
    19611972        // This arg is not recognized by the VM nor by jsc. Pass it on to the
     
    19631974        m_scripts.append(Script(true, argv[i]));
    19641975    }
     1976
     1977    if (hasBadJSCOptions && JSC::Options::validateOptions())
     1978        CRASH();
    19651979
    19661980    if (m_scripts.isEmpty())
  • trunk/Source/JavaScriptCore/runtime/Options.cpp

    r194518 r194590  
    4040#include <wtf/text/StringBuilder.h>
    4141
     42#if PLATFORM(COCOA)
     43#include <crt_externs.h>
     44#endif
     45
    4246#if OS(WINDOWS)
    4347#include "MacroAssemblerX86.h"
     
    362366            // The evn var should be the name of the option prefixed with
    363367            // "JSC_".
     368#if PLATFORM(COCOA)
     369            bool hasBadOptions = false;
     370            for (char** envp = *_NSGetEnviron(); *envp; envp++) {
     371                const char* env = *envp;
     372                if (!strncmp("JSC_", env, 4)) {
     373                    if (!Options::setOption(&env[4])) {
     374                        dataLog("ERROR: invalid option: ", *envp, "\n");
     375                        hasBadOptions = true;
     376                    }
     377                }
     378            }
     379            if (hasBadOptions && Options::validateOptions())
     380                CRASH();
     381#else // PLATFORM(COCOA)
    364382#define FOR_EACH_OPTION(type_, name_, defaultValue_, description_)      \
    365383            overrideOptionWithHeuristic(name_(), "JSC_" #name_);
    366384            JSC_OPTIONS(FOR_EACH_OPTION)
    367385#undef FOR_EACH_OPTION
     386#endif // PLATFORM(COCOA)
    368387
    369388#if 0
  • trunk/Source/JavaScriptCore/runtime/Options.h

    r194402 r194590  
    103103
    104104#define JSC_OPTIONS(v) \
     105    v(bool, validateOptions, false, "crashes if mis-typed JSC options were passed to the VM") \
    105106    v(unsigned, dumpOptions, 0, "dumps JSC options (0 = None, 1 = Overridden only, 2 = All, 3 = Verbose)") \
    106107    \
Note: See TracChangeset for help on using the changeset viewer.