Commit Graph

161 Commits (3ba713aabf20279c5d83d039e5a7ac906b79c783)

Author SHA1 Message Date
Jaume Pujantell 3ba713aabf add isMobileApp util function to reduce ifdefs
Removed all MOBILEAPP preprocessor conditionals from Util.hpp/.cpp
Added isMobileApp function to help remove further conditionals.

Signed-off-by: Jaume Pujantell <jaume.pujantell@collabora.com>
Change-Id: I038a4db47ec2a2c7bb10f5696df5571b13bd9a61
2024-03-20 09:13:00 +01:00
Michael Meeks f21b4854ee Generalize DirectoryCounter and add FDCounter class.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I6f51d8eeafcafcd8fe8a70a4e9f734e8c002eed6
2024-03-15 11:41:23 +00:00
Ashod Nakashian d57baeb906 wsd: reduce directives for unused variable supression
We use [[maybe_unused]] to reduce explicit supression
especially under compile-time directives.

Change-Id: Ic5f3f3227a80efe52097cb35520d05b9cdaacb42
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2024-03-09 12:37:19 -05:00
Michael Meeks a702d29244 Re-factor thread counting into a ThreadCounter class.
This can rewinddir on a persistently open file descriptor
pointed at /proc/self/task opened before dropping privileges.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Ie5a5948300c46c8c6a65f7f7eda3a60a9d5cf9c3
2024-03-07 09:36:00 +00:00
Aron Budea 3b8f3d07f6 Replace Util::startsWith/endsWith w/ C++20 equivalent
Replace a few cases of Util::toString(...), too.

Signed-off-by: Aron Budea <aron.budea@collabora.com>
Change-Id: I53c5dbbdf2f60710e94add9dd137aa9becb7bd3e
2024-02-22 08:08:32 +01:00
Michael Meeks 7031c3b0ce cool#8328 - config header fixup.
config.h should be included as the 1st line in each source file.
It should not be included in headers.

config_version.h which changes on every commit should not be
included widely - so remove it from the HttpRequest heeader to
save tinderbox's ccache.

Fetch version info from helper methods rather than in-lining via
defines, to better encapsulate.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: If449a36f1ac61940f04d70d5f4180db389d9b4c4
2024-02-21 09:35:25 +00:00
Ashod Nakashian d3905698b0 wsd: detect unencoded WOPISrc
We should always have an encoded WOPISrc.
We add detection logic to make sure
that all URIs that contain WOPISrc have
it encoded properly. We do this by
comparing the decoded WOPISrc with
the original URI.

Change-Id: Ia0c2a79b009ce105321ad35db3d4f81006e81cb3
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2024-02-09 03:57:04 -05:00
Ashod Nakashian 3d4efc0030 wsd: header clean up and SPDX license
Change-Id: I6e75b9a6d5ddd192bef18f637ef9c3d5548d9c88
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2024-02-05 16:47:08 +00:00
Caolán McNamara f04d3450cd rng::getHardRandomHexString is now the same impl as rng::getHexString
so remove one in favor of the other

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I47778f7bce24f0687565aa179b7a3bbea9d95120
2024-02-05 16:19:38 +00:00
Michael Meeks b627777b13 Remove trendy C++ & Poco wrappers for random numbers.
And improve quality of low-grade random numbers significantly.
_rd.entropy() ? is not your friend.

Change-Id: I477557245949334bec517cdeae653c7452ed2049
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-01-31 16:28:15 +00:00
Noel Grandin 16228fa0ed speed up spawning/execing child programs
using fork(), the kernel needs to copy the VM data structures,
which can be quite large for the main COOL processes.

I looked into things like vfork(), clone() and using a helper-process,
but it looks like posix_spawn is sufficient for our needs.
Internally it uses clone(CLONE_VM) which means we avoid the VMA copies.

Also, simplify the arguments of spawnProcess,
we don't use the optional params anymore.

Signed-off-by: Noel Grandin <noel.grandin@collabora.co.uk>
Change-Id: I8f943541dc4d7f56c2d36ccbf7b78c40ec14b8e0
2024-01-27 11:26:44 +00:00
Miklos Vajna 33310613cd wsd: fix reading past the end of the clipboard in postProcessCopyPayload()
Add a way to search with an offset in findInVector() and then we can
avoid strstr() which assumes a null-terminated input, which may not be
the case.

	READ of size 55 at 0x606000068a56 thread T8 (docbroker_001)
	    #0 0x55d0d6718a5a in StrstrCheck(void*, char*, char const*, char const*) /home/abuild/rpmbuild/BUILD/llvm-15.0.7.src/build/../projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:652:5
	    #1 0x55d0d6718882 in __interceptor_strstr /home/abuild/rpmbuild/BUILD/llvm-15.0.7.src/build/../projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:669:5
	    #2 0x55d0d71872c9 in ClientSession::postProcessCopyPayload(std::shared_ptr<Message> const&)::$_4::operator()(std::vector<char, std::allocator<char>>&) const /home/vmiklos/git/collaboraonline/online-23.05-san/wsd/ClientSession.cpp:1631:31

During unit-uno-command.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Id42669d912bab4746d9f7d99a192c4c3f1d175f7
2024-01-23 08:38:26 +00:00
Michael Meeks 5bd1f1d0e8 convert-to: be more tolerant of unusual filenames.
But re-write them anyway to be more sensible.

Change-Id: Ie146f4f84b539ab7e826a1c1b947497acde7e384
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-01-15 11:57:55 +01:00
Jaume Pujantell 35d6e2925f use isKitInProcess() instead of KIT_IN_PROCESS
Removed all uses of KIT_IN_PROCESS, used Utils::isKitInProcess()
when necessary. Also removed the now unused parameter 'limit' from
forkLibreOfficeKit.

Signed-off-by: Jaume Pujantell <jaume.pujantell@collabora.com>
Change-Id: I068d3f55ab49076590f111847c87b3188f4d25d0
2023-12-18 10:34:10 +00:00
Darshan-upadhyay1110 3f46c1db44 kit-in-process: pure re-factor to a run-time function to flag this.
Avoids a number of compile time conditionals and adds flexibility.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Iff6b294b504526e70715e436ad33d47c8df4752c
2023-11-22 17:06:29 +00:00
Michael Meeks 1a4dafa3e5 Fetch available memory and limits from our control group not the system.
To test:

sudo mkdir /sys/fs/cgroup/memory/0
echo "900M" | sudo tee /sys/fs/cgroup/memory/0/memory.limit_in_bytes
echo $$ | sudo tee /sys/fs/cgroup/memory/0/tasks
make run # and check the log.

Change-Id: I81cf5f6212418d1f900a56cdfe476e1594f4fe77
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-11-14 19:36:31 +00:00
Ashod Nakashian c3fb1d0dde wsd: helper to serialize pairs
Since we don't want to propagate Poco types
as well as our pair containers, it's best
to have these are named functions rather
than as operator<<.

Change-Id: I9772b8f314262147b6c445464bf3ce8cb598b56d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-24 21:33:02 -04:00
Ashod Nakashian 44cc7145c2 wsd: helper to concatenate streamable elements together
Change-Id: I0d989b54d5eebbd3efee2502d84a82281ebf62a7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-24 09:20:32 +02:00
Miklos Vajna 790a19ab25 kit: improve date format of UNO commands in crashreports
Old format:

	kit-27634-02839 2023-08-30 11:08:43.590564 +0000 [ kitbroker_17a ] SIG   Fatal signal received: SIGSEGV code: 1 for address: 0x4f00000007
	      unoCommand(2552f) : ToolbarMode?Mode:string=notebookbar_online.ui - Wed, 30 Aug 2023 11:08:31

New format:

	kit-30199-30197 2023-09-06 14:30:21.417817 +0200 [ kitbroker_001 ] SIG   Fatal signal received: SIGABRT code: 18446744073709551610 for address: 0x3e8000075f7
	Recent activity:
		unoCommand(064) : ToolbarMode?Mode:string=notebookbar_online.ui - 2023-09-06 12:29:56

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Idf62ea18c75c453d188d8c25723a43824d5fc147
2023-09-11 10:07:19 +02:00
Caolán McNamara afe6c1bed8 reduce cost of TileDesc::parse
perf reported 6.58% of time in collaborative multi user test
on 2023-08-24 was spent in TileDesc::parse and much of that
in std::unordered_map.

There are only 12 arguments in the map we care about here so
we can just used a sorted array, look by name on write, and
read by index.

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Iadfc2001e298d8f4d46200c8488f0eb4cd8734c2
2023-08-24 22:22:43 +01:00
Caolán McNamara 492f678996 add and use 'N_ELEMENTS' in lieu of std::size
which isn't available in the current android toolchain

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I5834adb7c6211c7aad38f5977a7e425d9ca257fd
2023-08-23 12:06:31 +02:00
Caolán McNamara f7e121e2ea cid#318953 COPY_INSTEAD_OF_MOVE
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I863ce92808f93e98fecb6022324228b5acdba141
2023-08-14 12:31:55 +02:00
Ashod Nakashian 75ae9894b9 wsd: Util::make_unique -> std::make_unique
Change-Id: I1063913f91571ea6ad95386a3da6a4072574d155
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-08-03 08:40:20 +02:00
Caolán McNamara 4730458b97 cid#318835 COPY_INSTEAD_OF_MOVE
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I964fc80c2bb7bddb8391e631ce179bf947fce55e
2023-06-29 08:03:00 -04:00
Caolán McNamara d900c3fc12 cid#318841 markup forcedExit as a fatal path
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I8825d8f2756c33d10efe9bc40129fbf4871e9de0
2023-06-26 07:08:46 -04:00
Ashod Nakashian 155bc06e24 wsd: de-duplicate assertCorrectThread
This merges multiple implementations of
assertCorrectThread and simplifies its
usage.

Change-Id: I7be5dea62c6046fb0412d7f885fcbcc4b66e3fd9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-22 09:34:29 -04:00
Patrick Luby 94469d7b61 Replace deprecated calls
Also, don't set webView.configuration.userContentController to nil as it
generates a "nil not allowed" compiler warning.

Signed-off-by: Patrick Luby <plubius@neooffice.org>
Change-Id: Ibb49228a65f102fa6d97d4e5affafae8ad528c0d
2023-05-16 09:43:29 +02:00
Ashod Nakashian a883e357b2 wsd: minor improvement to Util::replace
Change-Id: I2b9e9b33d8e63a43b50beda432fc48f8b9d7a8c7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-15 08:47:26 +01:00
Ashod Nakashian a54416311f wsd: test: time countCoolKitProcesses to catch slow unloads
Change-Id: I26e4382badc4b3e3172d3788e27f024ee7e07c7d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-02 19:54:31 -04:00
Ashod Nakashian 3dbfce54d3 wsd: helper to dump the state of an object as a string
Change-Id: Ib49a47be2dc37663ef06ac80be981c9f3c029814
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-11 08:03:01 -04:00
Ashod Nakashian a24a07b301 wsd: new Stopwatch utility
Similar code is scattered in the code. This
should help clean them up and make usage
easier.

Change-Id: I02f82c9aa169f591c5688c4b2adca257eecf8221
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-11 08:03:01 -04:00
Ashod Nakashian b9a3115833 wsd: test: add decodeURIComponent
This decodes strings encoded using
encodeURIComponent.

For now, it wraps Poco::URI::decode,
which should be replaced in the future.

Change-Id: I608b327be81aeda37d2afc4dfd29828658e92dc8
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-12-12 08:00:05 -05:00
Ashod Nakashian 06d7fd1753 wsd: extract URI encoding in a helper
This is compatible with the JavaScript
encodeURIComponent(), which supports
XML embedding.

Change-Id: I38bb64af67789bd5eea3f8f8bdb7f80e313599fb
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-10-26 16:26:15 +02:00
Andras Timar cf6e22c22c Fix typos in comments
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I813f652b516c79f350b46317e589b91e0ef39a1a
2022-08-23 18:37:44 +02:00
Aron Budea d30b423c07 Replace #ifdef-s with #if-s, and enable -Wundef
...for variables coming from configure.ac.

Signed-off-by: Aron Budea <aron.budea@collabora.com>
Change-Id: I39ebd21c4cb56d2a3bd38fdc35dc59b5f1fd4b49
2022-08-03 11:07:38 +02:00
Ashod Nakashian d6cf1f0532 wsd: minor code-coverage improvements
Change-Id: If9d16bdb37944220635c27d98595c2ebcb19a51d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-08-02 14:45:12 -04:00
Ashod Nakashian 5c6516e4e4 wsd: support code-coverage report via --with-coverage
This adds support for code-coverage HTML reporting.
To achieve this, we must use file-linking in jails
so that we can update the coverage data (.gcda files)
from the jails. This means that creating jails is
slower than with bind-mounting and we need to
account for that in our timeouts.

We also can't kill child processes with SIGKILL,
which is un-catchable. Instead, we use SIGTERM
and dump the profile data before exiting.

Change-Id: I16fa534f6ed42f7133014d841bb024423315e0a4
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-08-02 14:45:12 -04:00
Ashod Nakashian c735429571 wsd: fix signedness warning/error
Change-Id: Ifb35c034b8e2cbf6f6031821b5ede2e2317a2c60
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-07-25 14:04:13 +01:00
Ashod Nakashian bb1978770a wsd: Message supports new find and contains operations
Change-Id: Id5112dda76fe2aaa27392d59f9b8ecfa3cfabe54
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-27 14:07:08 +01:00
Rash419 45891d0ded wsd: alias: handle a case when regex is added in host tag of alias_group
if host has regex and group has no aliases, when we receive first request from host pattern we considered it as original host and all the host following first request which matches the pattern are considered as aliases
for example:
<group>
	<host>https://.*:80</host>
</group>
if we receives first request from asustuf then behaviour will similar to the following config:
<group>
	<host>https://asustuf:80</host>
	<alias>https://.*:80</alias>
</group>

Signed-off-by: Rash419 <rashesh.padia@collabora.com>
Change-Id: I70fb91a4bb7bf38ed79db9efd9fe4bc46db325e1
2022-06-15 11:04:36 +05:30
Ashod Nakashian 5bdd977410 wsd: simplify socket read logging
Change-Id: I083b86d6c8e6e2b3dc7b14836409281792d7b0bf
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-07 09:09:00 +01:00
Rash419 2163e2f043 wsd: cleanup setting firsthost code
we added AllHosts to give admin the err log that host is not in alias_groups but now as we removed the host list entries from configuration we don't need that log

Signed-off-by: Rash419 <rashesh.padia@collabora.com>
Change-Id: I8b5e9e6b7df7df59befb496c12966c7ddc60c707
2022-05-05 11:04:22 +05:30
Ashod Nakashian 480fb7b931 wsd: move tokenizer helpers into StringVector
In an attempt to reduce the size of Util.{c,h}pp
which has grown to contain all sorts of unrelated
helpers, we move StringVector helpers into
the StringVector.{c,h}pp files.

This makes the code better organized.

Change-Id: I152f341606807ae66253415b951bc9f89b09df57
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-12 07:39:07 -04:00
Miklos Vajna 212e3c0818 common: isValidUtf8: ensure chunk len is 4 at max
UTF-8 is expected to encode a code point using 1 to 4 bytes.

Also check that the promised chunks are there before accessing them.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I9b4f346738865fc18242e51a33c97e5b38ee90d8
2022-04-06 10:26:24 +02:00
Rash419 c2be0b3a48 wsd: add: support to define multiple domain with '|'
fix: in regex, escaping special character fails to find host of the alias

Signed-off-by: Rash419 <rashesh.padia@collabora.com>
Change-Id: I19bfacc5e45af26832cb8c6a7d249e0c7de56624
2022-04-05 13:47:57 +02:00
Michael Meeks db63703d0c Validate as utf-8 all Websocket text messages in debug mode.
Ensure that rendersearchresult: is terminated, and identified as binary.

Change-Id: I84e83c63351cd0aac0923bf7c833b14c1be2c051
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2022-04-04 20:46:11 +01:00
Michael Meeks 9f5c5dcdf4 Show (E) for experimental mode in help->about if present.
Change-Id: I00d6cb861c3050d5b4f80b0cb41e70012d0fe610
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2022-03-24 17:25:40 +00:00
Rash419 ea35dbe350 wsd: added regex support for alias tag
Signed-off-by: Rash419 <rashesh.padia@collabora.com>
Change-Id: I2534ea9afa7d3d3bf10f91eeac44f70381acc76a
2022-03-22 14:13:22 +01:00
Pranam Lashkari defef6a171 util: removed duplicate string trimming function
Signed-off-by: Pranam Lashkari <lpranam@collabora.com>
Change-Id: Ia150975467d1df8a9d05c8543bcb5d7369d29099
2022-03-22 09:07:03 -04:00
Ashod Nakashian 88e03a47d3 wsd: support new clang versions for fuzzing
Now we choose static-libasan vs static-libsan
at configuration time, dynamically. This
enables supporting post clang-9 releases
which do not have libasan.

In addition, clang warns about the order
and visibility of operator<< for the chrono
types. Those are fixed to.

Change-Id: I17f5fc4b3e34464194ad686542935c9f596366e4
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-09 19:24:40 -05:00