Exemple #1
0
        internal SandboxedProcess(SandboxedProcessInfo info)
        {
            Contract.Requires(info != null);
            Contract.Requires(!info.Timeout.HasValue || info.Timeout.Value <= Process.MaxTimeout);

            // there could be a race here, but it just doesn't matter
            if (s_binaryPaths == null)
            {
                s_binaryPaths = new BinaryPaths(); // this can take a while; performs I/O
            }

            // If unspecified make the injection timeout the DefaultProcessTimeoutInMinutes. Also, make it no less than DefaultProcessTimeoutInMinutes.
            m_timeoutMins = info.Timeout.HasValue ? ((uint)info.Timeout.Value.TotalMinutes) : SandboxConfiguration.DefaultProcessTimeoutInMinutes;
            if (m_timeoutMins < SandboxConfiguration.DefaultProcessTimeoutInMinutes)
            {
                m_timeoutMins = SandboxConfiguration.DefaultProcessTimeoutInMinutes;
            }

            m_fileAccessManifest = info.FileAccessManifest;
            m_fileAccessManifestStreamWrapper = Pools.MemoryStreamPool.GetInstance();
            m_bufferSize = SandboxedProcessInfo.BufferSize;
            m_allowedSurvivingChildProcessNames = info.AllowedSurvivingChildProcessNames;
            m_nestedProcessTerminationTimeout   = info.NestedProcessTerminationTimeout;
            m_loggingContext = info.LoggingContext;

            Encoding inputEncoding = info.StandardInputEncoding ?? Console.InputEncoding;

            m_standardInputReader = info.StandardInputReader;

            m_pathTable = info.PathTable;

            Encoding outputEncoding = info.StandardOutputEncoding ?? Console.OutputEncoding;

            m_output = new SandboxedProcessOutputBuilder(
                outputEncoding,
                info.MaxLengthInMemory,
                info.FileStorage,
                SandboxedProcessFile.StandardOutput,
                info.StandardOutputObserver);
            Encoding errorEncoding = info.StandardErrorEncoding ?? Console.OutputEncoding;

            m_error = new SandboxedProcessOutputBuilder(
                errorEncoding,
                info.MaxLengthInMemory,
                info.FileStorage,
                SandboxedProcessFile.StandardError,
                info.StandardErrorObserver);

            m_reports = m_fileAccessManifest != null ?
                        new SandboxedProcessReports(
                m_fileAccessManifest,
                info.PathTable,
                info.PipSemiStableHash,
                info.PipDescription,
                info.LoggingContext,
                info.DetoursEventListener,
                info.SidebandWriter) : null;

            Contract.Assume(inputEncoding != null);
            Contract.Assert(errorEncoding != null);
            Contract.Assert(outputEncoding != null);

            m_detouredProcess =
                new DetouredProcess(
                    SandboxedProcessInfo.BufferSize,
                    info.GetCommandLine(),
                    info.WorkingDirectory,
                    info.GetUnicodeEnvironmentBlock(),
                    inputEncoding,
                    errorEncoding,
                    m_error.AppendLine,
                    outputEncoding,
                    m_output.AppendLine,
                    OnProcessExitingAsync,
                    OnProcessExited,
                    info.Timeout,
                    info.DisableConHostSharing,
                    info.LoggingContext,
                    info.TimeoutDumpDirectory,
                    info.ContainerConfiguration,
                    // If there is any process configured to breakway from the sandbox, then we need to allow
                    // this to happen at the job object level
                    setJobBreakawayOk: m_fileAccessManifest.ProcessesCanBreakaway,
                    info.CreateJobObjectForCurrentProcess);
        }
Exemple #2
0
        internal SandboxedProcess(SandboxedProcessInfo info)
        {
            Contract.Requires(info != null);
            Contract.Requires(!info.Timeout.HasValue || info.Timeout.Value <= Process.MaxTimeout);

            // there could be a race here, but it just doesn't matter
            if (s_binaryPaths == null)
            {
                s_binaryPaths = new BinaryPaths(); // this can take a while; performs I/O
            }

            // If unspecified make the injection timeout 10 mins. Also, make it no less than 10 mins.
            m_timeoutMins = info.Timeout.HasValue ? ((uint)info.Timeout.Value.TotalMinutes) : 10;
            if (m_timeoutMins < 10)
            {
                m_timeoutMins = 10;
            }

            m_fileAccessManifest = info.FileAccessManifest;
            m_fileAccessManifestStreamWrapper = Pools.MemoryStreamPool.GetInstance();
            m_bufferSize = SandboxedProcessInfo.BufferSize;
            m_nestedProcessTerminationTimeout = info.NestedProcessTerminationTimeout;

            Encoding inputEncoding = info.StandardInputEncoding ?? Console.InputEncoding;

            m_standardInputReader = info.StandardInputReader;

            m_pathTable = info.PathTable;

            Encoding outputEncoding = info.StandardOutputEncoding ?? Console.OutputEncoding;

            m_output = new SandboxedProcessOutputBuilder(
                outputEncoding,
                info.MaxLengthInMemory,
                info.FileStorage,
                SandboxedProcessFile.StandardOutput,
                info.StandardOutputObserver);
            Encoding errorEncoding = info.StandardErrorEncoding ?? Console.OutputEncoding;

            m_error = new SandboxedProcessOutputBuilder(
                errorEncoding,
                info.MaxLengthInMemory,
                info.FileStorage,
                SandboxedProcessFile.StandardError,
                info.StandardErrorObserver);

            m_reports = m_fileAccessManifest != null ?
                        new SandboxedProcessReports(
                m_fileAccessManifest,
                info.PathTable,
                info.PipSemiStableHash,
                info.PipDescription,
                info.LoggingContext,
                info.DetoursEventListener) : null;

            Contract.Assume(inputEncoding != null);
            Contract.Assert(errorEncoding != null);
            Contract.Assert(outputEncoding != null);

            m_processIdListener = info.ProcessIdListener;
            m_detouredProcess   =
                new DetouredProcess(
                    SandboxedProcessInfo.BufferSize,
                    info.GetCommandLine(),
                    info.WorkingDirectory,
                    info.GetUnicodeEnvironmentBlock(),
                    inputEncoding,
                    errorEncoding,
                    m_error.AppendLine,
                    outputEncoding,
                    m_output.AppendLine,
                    OnProcessExitingAsync,
                    OnProcessExited,
                    info.Timeout,
                    info.DisableConHostSharing,
                    info.LoggingContext,
                    info.TimeoutDumpDirectory);
        }