Commit graph

29566 commits

Author SHA1 Message Date
Karol Kosek
a7e7cb0e70 LibHTTP: Store Content-Length value in the HTTP Job class
This way we can save some calculations, but more importantly this will
also be needed in next commits. :P
2021-10-24 23:54:26 +02:00
Karol Kosek
71f663b205 LibHTTP: Fix buffer overflow when body is larger than the Content-Length
(Actually, this also needs a Content-Encoding header, as response
streaming is disabled then. It didn't fit in the title.)

We were creating too small buffer -- instead of assigning the total
received buffer size, we were using the Content-Length value.

As you can see, the m_buffered_size might now exceed the Content-Length
value, but that will be handled in next commits, regardless if
the response can be streamed or not. :^)

Here's a minimal code that caused crash before:

  printf 'HTTP/1.0 200 OK\r\n%s\r\n%s\r\n\r\n%s' \
      'Content-Encoding: anything' 'Content-Length: 3' \
      ':^)AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' | nc -lN 0.0.0.0 8000
  pro http://0.0.0.0:8000
2021-10-24 23:54:26 +02:00
Idan Horowitz
87bd98fe8e Profiler: Handle profiles with more kernel samples than user samples
Previously we assumed there were less kernel samples than user samples,
by implicitly using the kernel histogram size for indicies to the user
histogram. Such a profile can be reproduced by profiling a very short
lived program like true: `profile -c true`
2021-10-24 23:04:47 +02:00
Idan Horowitz
db68a52e23 Profiler: Use profile length in ms as histogram column count directly
Beforehand we were dividing the frame width by the profile length in ms
and then dividing the frame width by the result once more, which is
equivalent to (but slower) just using the length in ms directly, aside
from the case in which the profile is less than 1 ms long, in which
case this would trigger undefined behaviour due to the division by zero
2021-10-24 23:04:47 +02:00
Sam Atkins
3e9191936b LibWeb: Remove now-unnecessary String copy when parsing CSS colors
Color::from_string() now does a case-insensitive comparison of color
names, so we don't need this copy. :^)
2021-10-24 22:12:35 +02:00
Sam Atkins
094dc04695 LibGfx: Make Color::from_string() case-insensitive
This function implements CSS color syntax, which is case-insensitive in
HTML contexts. Making it insensitive here means not having to remember
to do it in every user, (many of the HTML elements do not do this,) and
means they don't have to produce a lowercase copy of the input string
before passing it.
2021-10-24 22:12:35 +02:00
Sam Atkins
639c913e58 LibGfx: Make Color use east-const 2021-10-24 22:12:35 +02:00
Jelle Raaijmakers
40a0a995af WindowServer: Prevent sending duplicate MousePackets when clicking
If a mouse button was clicked, `EventLoop::drain_mouse()` would always
send the last MousePacket state to the screen input - even if that
state is equivalent to the last state sent as part of the button logic.

By remembering if the state was already sent, we prevent sending that
state a second time saving some resources in the process.
2021-10-24 22:00:34 +02:00
Jelle Raaijmakers
38b09ba133 WindowServer: Deduplicate code for mouse Z state in EventLoop 2021-10-24 22:00:34 +02:00
Jelle Raaijmakers
bbaf8e3b70 WindowServer: Simplify mouse button handling logic in EventLoop
The `buttons` variable is a bit superfluous here.
2021-10-24 22:00:34 +02:00
Jelle Raaijmakers
4131b35851 Kernel: Prevent VMWareMouseDevice from handling invalid mouse packets
Bit 3 is set here:
c5b2f55981/hw/input/ps2.c (L736)

Spurious mouse packets can be received without this bit set, for
example when double-clicking and keeping the mouse button depressed
instead of releasing it the second time (i.e. mousedown > mouseup >
mousedown). We should not process such packets.

This makes interaction with our buttons much smoother!

Fixes #5881.
2021-10-24 21:59:08 +02:00
Jelle Raaijmakers
8b3232121b Kernel: Do not detect mouse or keyboard when handling IRQ for I8042
Instead of detecting which flag was set in the status register, we can
use the instrument type passed to us. This works because the mouse and
keyboard use different IRQs.
2021-10-24 21:59:08 +02:00
Jelle Raaijmakers
26c84967fa Kernel: Enumify all magic constants for I8042 devices
This makes the code much easier to read.
2021-10-24 21:59:08 +02:00
Daniel Bertalan
0a748de1a0 UE: Properly align stack for signal handlers
This issue was also present in the kernel, the description of which is
provided in an identically titled commit.

Note that this couldn't have affected any programs running in
UserspaceEmulator as we don't support SSE instructions, and don't seem
to raise faults under any conditions.
2021-10-24 21:54:51 +02:00
Daniel Bertalan
db71c36657 Kernel: Properly align stack for signal handlers
The System V ABI requires that the stack is 16-byte aligned on function
call. Confusingly, however, they mean that the stack must be aligned
this way **before** the `CALL` instruction is executed. That instruction
pushes the return value onto the stack, so the callee will actually see
the stack pointer as a value `sizeof(FlatPtr)` smaller.

The signal trampoline was written with this in mind, but `setup_stack`
aligned the entire stack, *including the return address* to a 16-byte
boundary. Because of this, the trampoline subtracted too much from the
stack pointer, thus misaligning it.

This was not a problem on i686 because we didn't execute any
instructions from signal handlers that would require memory operands to
be aligned to more than 4 bytes. This is not the case, however, on
x86_64, where SSE instructions are enabled by default and they require
16-byte aligned operands. Running such instructions raised a GP fault,
immediately killing the offending program with a SIGSEGV signal.

This issue caused TestKernelAlarm to fail in LibC when ran locally, and
at one point, the zsh port was affected too.

Fixes #9291
2021-10-24 21:54:51 +02:00
Andreas Kling
b138b4c83f LibJS: Optimize Value::to_property_key() for numeric property names
If the Value is a non-negative Int32, create a numeric PropertyKey
instead of making a string key.

This makes "ai-astar" test from the Kraken benchmark run in 30 seconds,
down from 42 seconds. :^)
2021-10-24 17:18:09 +02:00
Andreas Kling
65a7296b8f LibJS: Make Value::to_property_key() return a JS::PropertyKey
Instead of returning JS::StringOrSymbol, which is a space-optimized type
used in Shape property tables, this now returns JS::PropertyKey which is
*not* space-optimized, but has other niceties like optimized storage of
numeric ("indexed") properties.
2021-10-24 17:18:09 +02:00
Andreas Kling
7ccb8c8609 LibJS: Provide default hash traits for JS::PropertyKey
Let's not require people to use PropertyNameTraits everywhere when we
can just specialize AK::Traits<JS::PropertyKey> instead. :^)
2021-10-24 17:18:09 +02:00
Andreas Kling
c02e992de2 LibJS: Use PropertyKey in MemberExpression::to_reference() 2021-10-24 17:18:09 +02:00
Andreas Kling
75f2510de9 LibJS: Make make_super_property_reference() take a PropertyKey
Let's get rid of StringOrSymbol usage outside of Shape.
2021-10-24 17:18:08 +02:00
Andreas Kling
398c181c79 LibJS: Rename PropertyName to PropertyKey
Let's use the same name as the spec. :^)
2021-10-24 17:18:07 +02:00
Andreas Kling
715e7fada8 LibJS: Add the "fast non-local access" optimization to the bytecode VM
The GetVariable bytecode op now caches environment coordinates for fast
cross-scope variable lookup.
2021-10-24 17:18:07 +02:00
Andreas Kling
da98212001 LibJS: Add a separate "identifier table" to bytecode executables
This is a specialized string table for storing identifiers only.
Identifiers are always FlyStrings, which makes many common operations
faster by allowing O(1) comparison.
2021-10-24 17:18:07 +02:00
Andreas Kling
13f04e37e5 LibJS: Use String and move semantics in Bytecode::StringTable
Avoid creating new AK::String objects when we already have one.
2021-10-24 17:18:07 +02:00
Andreas Kling
3117182c2e LibJS: Implement 'this' in the bytecode VM
ThisExpression now emits a "ResolveThisBinding" bytecode op, which
simply loads the VM's current 'this' binding into the accumulator.
2021-10-24 17:18:06 +02:00
Andreas Kling
7c7bc4f44a LibJS: Alphabetize the bytecode opcode list 2021-10-24 17:18:06 +02:00
Andreas Kling
f75d78f56a LibJS: Include executable name in bytecode dumps 2021-10-24 17:18:06 +02:00
Andreas Kling
c95dde971b LibJS: Move global "should dump bytecode" flag into LibJS
This will allow us to trigger bytecode executable dumps when generating
bytecode inside LibJS as well, not just in clients like js and test-js.
2021-10-24 17:18:06 +02:00
Andreas Kling
da77e2aa4f LibJS: Add Bytecode::Executable::dump()
Let's have a helper for producing a consistent executable dump instead
of repeating the logic in multiple places.
2021-10-24 17:18:05 +02:00
Idan Horowitz
b41954182a PixelPaint: Move Mask::{get, set, to_index} to the header file
They were previously taking up 9% of samples in a profile of PixelPaint
while selecting a mask, and as a result of moving them to the header
they were inlined, which effectively eliminated them from the profile.
2021-10-24 17:02:44 +02:00
Brian Gianforcaro
3e592f5959 Base: Make /usr/Tests read-only since it's now suid capable
Commit cf0dbc906 recently added the ability for setuid binaries to be
located in /usr/Tests. This should really now be read only to mitigate
the potential misuse of any of the setuid binaries.
2021-10-24 11:33:34 +02:00
davidot
9c9aaf4d4f LibJS: Don't VERIFY that a function is Regular when executing in AST
By replacing this VERIFY with a thrown Error we no longer crash when
calling a generator function in the AST interpreter. This allows us to
more gracefully handle situation which have not been implemented yet.
In particular this helps the libjs-test262-runner since it can now
continue on to the next tests instead of having the entire process end.
2021-10-24 08:38:02 +01:00
Daniel Bertalan
ff1b72c95c Ports: Remove obsolete bash locale patch
Now that we have a semi-decent support for wide characters and a stubbed
out locale API, this hack is not needed anymore.
2021-10-23 23:31:43 -07:00
Daniel Bertalan
b3ac24a939 LibC: Use a sensible MB_CUR_MAX value
We always use UTF-8, meaning that a single `wchar_t` might be converted
into up to 4 `char`s. This would cause a buffer overflow if something
actually relied on this being the right value.
2021-10-23 23:31:43 -07:00
Daniel Bertalan
ba975f4ba4 LibC: Define locale categories (LC_*) as macros
The C standard states that these symbols should be declared as macros,
not as emum variants as we were doing previously. This is used in some
ports (e.g. bash) to conditionally compile locale-dependent
functionality.

We now use the same trick here as with the errno constants. We keep the
enum, but also create macros that defer to the enum variants.
2021-10-23 23:31:43 -07:00
Andreas Kling
fa753ff863 LibCore: Pop the main Core::EventLoop off the stack when destroyed
The main event loop pushes itself onto the event loop stack, and so it
should also pop itself when destroyed.

This will surface attempts to use the event loop stack after the main
event loop has been destroyed.
2021-10-24 01:01:01 +02:00
Andreas Kling
3bed7d5a5e LibIPC: Use a zero-delay timer for message processing
This lets us avoid using Core::deferred_invoke() which is not usable
during application teardown (as there is no event loop to push the
deferred invocation onto.)

(Not that there is an event loop to fire the processing timer during
teardown *either*, but at least we can exit gracefully with pending
timers, unlike deferred invocations, which hang the process. This is an
area where more improvements are definitely needed!)
2021-10-24 01:01:01 +02:00
Andreas Kling
24642861af LibIPC: Store local endpoint magic in a ConnectionBase member
This simplifies some of the code, since it's no longer necessary for the
templated code to pass LocalEndpoint::static_magic() everywhere.
2021-10-24 01:01:01 +02:00
Andreas Kling
9a8bdf84c8 LibIPC: Move waiting for synchronous responses to ConnectionBase 2021-10-24 01:01:01 +02:00
Andreas Kling
8728d36dd0 LibIPC: Move more of IPC::Connection to ConnectionBase
This patch moves the templated message parsing code to a virtual
try_parse_messages() helper. By doing that, we can move the rest of the
socket draining code up to ConnectionBase and keep it out of line.
2021-10-24 01:01:01 +02:00
Andreas Kling
f3c4a357ea LibIPC: Move non-templated parts of IPC::Connection out of line
This patch splits IPC::Connection into Connection and ConnectionBase.
ConnectionBase moves into Connection.cpp so we don't have to inline it
for every single templated subclass.
2021-10-24 01:01:01 +02:00
Andreas Kling
561c18726f LibIPC: Add missing <signal.h> include 2021-10-24 01:01:01 +02:00
Andreas Kling
0221affb31 LibIPC: Add IPC::Stub to forwarding header 2021-10-24 01:01:01 +02:00
Ben Wiederhake
48e4fb239a Shell: Prevent exponential explosion around '$(('
When parse_expression looks at '$((', there are two ways it can end up
in parse_expression again, three consumed characters later. All these
ways fail, so what happened was that the parser tried all possible
combinations, hence taking potentially an exponential amount of time.

1. parse_evaluate swallows the '$(', a new invocation of
   parse_expression swallows the other '(', and through
   parse_list_expression we're at another parse_expression.
2. parse_evaluate swallows the '$(', but returns a SyntaxError.
   parse_expression used to not recognize the error, and treated it as a
   regular AST node, calling into read_concat, then a new invocation of
   parse_expression swallows the other '(', and through
   parse_list_expression we're at another parse_expression.

Fixes #10561.

Found by OSS Fuzz, long-standing issue
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28113
2021-10-23 19:29:59 +01:00
Ben Wiederhake
fc519d43ba Fuzzing: Update build instructions
The project needs clang-12, which is not on all systems the default
(e.g. Debian Testing).
2021-10-23 19:29:59 +01:00
Timothy Flynn
e503b60bdc LibJS: Convert a few TRYs to MUST in RegExp.prototype
These are marked with ! in the spec. This also adds assertions above
a couple of these operations to be extra sure (the spec also indicates
we should make these assertions).
2021-10-23 19:22:34 +01:00
Ben Wiederhake
cb868cfa41 AK+Everywhere: Make Base64 decoding fallible 2021-10-23 19:16:40 +01:00
Ben Wiederhake
3bf1f7ae87 AK: Don't crash on invalid Base64 input
In the long-term, we should probably have a way to signal decoding
failure. For now, it should suffice to at least not crash. This is
particularly relevant because apparently this can be triggered while
parsing a PEM certificate, which happens during every TLS connection.

Found by OSS Fuzz
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38979
2021-10-23 19:16:40 +01:00
Timothy Flynn
20f73d2abc LibJS: Convert Atomics functions to ThrowCompletionOr 2021-10-23 19:16:03 +01:00
Timothy Flynn
3edf86462b LibJS: Convert typed_array_from to ThrowCompletionOr 2021-10-23 19:16:03 +01:00