summaryrefslogtreecommitdiffstats
path: root/toolkit/crashreporter/linux_utils.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /toolkit/crashreporter/linux_utils.cc
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-adbda400be353e676059e335c3c0aaf99e719475.tar.xz
firefox-adbda400be353e676059e335c3c0aaf99e719475.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/crashreporter/linux_utils.cc')
-rw-r--r--toolkit/crashreporter/linux_utils.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/toolkit/crashreporter/linux_utils.cc b/toolkit/crashreporter/linux_utils.cc
new file mode 100644
index 0000000000..cfddecf084
--- /dev/null
+++ b/toolkit/crashreporter/linux_utils.cc
@@ -0,0 +1,59 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "common/linux/linux_libc_support.h"
+#include "linux_utils.h"
+
+bool ElfFileSoVersion(const char* mapping_name, uint32_t* version_components) {
+ if (!version_components) {
+ return false;
+ }
+
+ // We found no version so just report 0
+ const char* so_version = my_strstr(mapping_name, ".so.");
+ if (so_version == nullptr) {
+ return true;
+ }
+
+ char tmp[12]; // 11 for maximum representation of UINT32T_MAX + \0 ?
+ size_t current_position = 0;
+ size_t next_tmp = 0;
+ tmp[0] = '\0';
+ for (size_t so_version_pos = 0; so_version_pos <= my_strlen(so_version);
+ ++so_version_pos) {
+ // We can't have more than four: MAJOR.minor.release.patch
+ if (current_position == 4) {
+ break;
+ }
+
+ char c = so_version[so_version_pos];
+ if (c != '.') {
+ if ((c <= '9' && c >= '0')) {
+ tmp[next_tmp] = c;
+ tmp[next_tmp + 1] = '\0';
+ ++next_tmp;
+ }
+
+ if (so_version[so_version_pos + 1] != '\0') {
+ continue;
+ }
+ }
+
+ if (my_strlen(tmp) > 0) {
+ int t;
+ if (!my_strtoui(&t, tmp)) {
+ return false;
+ }
+ uint32_t casted_tmp = (uint32_t)t;
+ version_components[current_position] = casted_tmp;
+ ++current_position;
+ }
+
+ tmp[0] = '\0';
+ next_tmp = 0;
+ }
+
+ return true;
+}