Debian Codegraph @

src/OVAL/oval_schema_version.c

raw symbols SCIP
1 /*
2 * Copyright 2015 Red Hat Inc., Durham, North Carolina.
3 * All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * "Jan Černý" <[email protected]>
21 */
22
23 #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`!
24 #include <config.h>cxx . . $ `<file>/build/config.h`/
25 #endif
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <sys/types.h>
31 #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/
32 #include "common/oscap_pcre.h"cxx . . $ `<file>/src/common/oscap_pcre.h`/
33 #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/
34 #include "public/oval_schema_version.h"cxx . . $ `<file>/src/OVAL/public/oval_schema_version.h`/
35
36 #define OVECTOR_LENcxx . . $ `src/OVAL/oval_schema_version.c:36:9`! 60 // must be a multiple of 30
37
38 static int _parse_intcxx . . $ _parse_int(54dd70b47e85a2fc).(const char *substring, size_t substring_length)
39 {
40 /* Pay attention that substring_length != strlen(substring) */
41 char *buffer = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(substring_length + 1); // +1 for a zero byte
42 strncpycxx . . $ strncpy(255158a415b673b0).(buffer, substring, substring_length);
43 buffer[substring_length] = '\0';
44 int i = atoicxx . . $ atoi(5c4306d8553b3696).(buffer);
45 freecxx . . $ free(5d22bdacc48458e8).(buffer);
46 return i;
47 }
48
49 oval_schema_version_tcxx . . $ oval_schema_version_t# oval_schema_version_from_cstrcxx . . $ oval_schema_version_from_cstr(da442b0b9c467d6b).(const char *ver_str)
50 {
51 oval_schema_version_tcxx . . $ oval_schema_version_t# version;
52 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&version, 0, sizeof(oval_schema_version_tcxx . . $ oval_schema_version_t#));
53 if (ver_str == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
54 return version;
55 }
56 const char *pattern = "([0-9]+)\\.([0-9]+)(?:\\.([0-9]+))?(?::([0-9]+)\\.([0-9]+)(?:\\.([0-9]+))?)?";
57 char *error;
58 int erroffset;
59 oscap_pcre_tcxx . . $ oscap_pcre_t# *re = oscap_pcre_compilecxx . . $ oscap_pcre_compile(29ca11f2d36a957a).(pattern, 0, &error, &erroffset);
60 if (re == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
61 dEcxx . . $ `src/common/debug_priv.h:63:9`!("Regular expression compilation failed with %s", pattern);
62 oscap_pcre_err_freecxx . . $ oscap_pcre_err_free(fda57c8427c60377).(error);
63 return version;
64 }
65 int ovector[OVECTOR_LENcxx . . $ `src/OVAL/oval_schema_version.c:36:9`!];
66 int rc = oscap_pcre_execcxx . . $ oscap_pcre_exec(7630dfd25fd504ec).(re, ver_str, strlencxx . . $ strlen(751346f8406fd082).(ver_str), 0, 0, ovector, OVECTOR_LENcxx . . $ `src/OVAL/oval_schema_version.c:36:9`!);
67 oscap_pcre_freecxx . . $ oscap_pcre_free(804bb72472b0846e).(re);
68 if (rc < 0) {
69 dEcxx . . $ `src/common/debug_priv.h:63:9`!("Regular expression %s did not match string %s", pattern, ver_str);
70 return version;
71 }
72 for (int i = 1; i < rc; i++) {
73 const char *substring = ver_str + ovector[2 * i];
74 size_t substring_length = ovector[2 * i + 1] - ovector[2 * i];
75 version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[i - 1] = _parse_intcxx . . $ _parse_int(54dd70b47e85a2fc).(substring, substring_length);
76 }
77 return version;
78 }
79
80 const char *oval_schema_version_to_cstrcxx . . $ oval_schema_version_to_cstr(4608dbb4b45290a0).(oval_schema_version_tcxx . . $ oval_schema_version_t# version)
81 {
82 size_t buf_len = 32;
83 char *buf = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(buf_len);
84 const char *format;
85 if (version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[OVAL_SCHEMA_VERSION_PLATFORM_MAJORcxx . . $ OVAL_SCHEMA_VERSION_PLATFORM_MAJOR.]) {
86 if (version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[OVAL_SCHEMA_VERSION_CORE_UPDATEcxx . . $ OVAL_SCHEMA_VERSION_CORE_UPDATE.] &&
87 version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[OVAL_SCHEMA_VERSION_PLATFORM_UPDATEcxx . . $ OVAL_SCHEMA_VERSION_PLATFORM_UPDATE.]) {
88 format = "%1$d.%2$d.%3$d:%4$d.%5$d.%6$d";
89 } else if (version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[OVAL_SCHEMA_VERSION_CORE_UPDATEcxx . . $ OVAL_SCHEMA_VERSION_CORE_UPDATE.]) {
90 format = "%1$d.%2$d.%3$d:%4$d.%5$d";
91 } else if (version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[OVAL_SCHEMA_VERSION_PLATFORM_UPDATEcxx . . $ OVAL_SCHEMA_VERSION_PLATFORM_UPDATE.]) {
92 format = "%1$d.%2$d:%4$d.%5$d.%6$d";
93 } else {
94 format = "%1$d.%2$d:%4$d.%5$d";
95 }
96 } else if (version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[OVAL_SCHEMA_VERSION_CORE_UPDATEcxx . . $ OVAL_SCHEMA_VERSION_CORE_UPDATE.]) {
97 format = "%1$d.%2$d.%3$d";
98 } else {
99 format = "%1$d.%2$d";
100 }
101 snprintfcxx . . $ snprintf(ea502d73e74c754c).(buf, buf_len, format,
102 version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[OVAL_SCHEMA_VERSION_CORE_MAJORcxx . . $ OVAL_SCHEMA_VERSION_CORE_MAJOR.],
103 version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[OVAL_SCHEMA_VERSION_CORE_MINORcxx . . $ OVAL_SCHEMA_VERSION_CORE_MINOR.],
104 version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[OVAL_SCHEMA_VERSION_CORE_UPDATEcxx . . $ OVAL_SCHEMA_VERSION_CORE_UPDATE.],
105 version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[OVAL_SCHEMA_VERSION_PLATFORM_MAJORcxx . . $ OVAL_SCHEMA_VERSION_PLATFORM_MAJOR.],
106 version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[OVAL_SCHEMA_VERSION_PLATFORM_MINORcxx . . $ OVAL_SCHEMA_VERSION_PLATFORM_MINOR.],
107 version.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[OVAL_SCHEMA_VERSION_PLATFORM_UPDATEcxx . . $ OVAL_SCHEMA_VERSION_PLATFORM_UPDATE.]);
108 return buf;
109 }
110
111 int oval_schema_version_cmpcxx . . $ oval_schema_version_cmp(b4d0c2bfb97f274f).(oval_schema_version_tcxx . . $ oval_schema_version_t# v1, oval_schema_version_tcxx . . $ oval_schema_version_t# v2)
112 {
113 for (int i = 0; i < OVAL_SCHEMA_VERSION_COMPONENTS_COUNTcxx . . $ OVAL_SCHEMA_VERSION_COMPONENTS_COUNT.; i++) {
114 if (v1.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[i] < v2.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[i]) {
115 return -1;
116 } else if (v1.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[i] > v2.componentcxx . . $ $anonymous_type_831faa1011083683_0#component.[i]) {
117 return 1;
118 }
119 }
120 return 0;
121 }