| 1 | /* |
| 2 | * Copyright 2009--2014 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 | * David Niemoller <[email protected]> |
| 21 | * Peter Vrabec <[email protected]> |
| 22 | * Tomas Heinrich <[email protected]> |
| 23 | * Daniel Kopecek <[email protected]> |
| 24 | * Šimon Lukašík |
| 25 | */ |
| 26 | |
| 27 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 28 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 29 | #endif |
| 30 | |
| 31 | #include <string.h> |
| 32 | #include <inttypes.h> |
| 33 | |
| 34 | #ifdef OS_WINDOWS |
| 35 | #include <winsock2.h> |
| 36 | #else |
| 37 | #include <arpa/inet.h> |
| 38 | #include <sys/socket.h> |
| 39 | #endif |
| 40 | |
| 41 | #include "oval_types.h"cxx . . $ `<file>/src/OVAL/public/oval_types.h`/ |
| 42 | #include "oval_system_characteristics.h"cxx . . $ `<file>/src/OVAL/public/oval_system_characteristics.h`/ |
| 43 | #include "common/_error.h"cxx . . $ `<file>/src/common/_error.h`/ |
| 44 | #include "common/debug_priv.h"cxx . . $ `<file>/src/common/debug_priv.h`/ |
| 45 | |
| 46 | #include "oval_cmp_basic_impl.h"cxx . . $ `<file>/src/OVAL/results/oval_cmp_basic_impl.h`/ |
| 47 | #include "oval_cmp_evr_string_impl.h"cxx . . $ `<file>/src/OVAL/results/oval_cmp_evr_string_impl.h`/ |
| 48 | #include "oval_cmp_ip_address_impl.h"cxx . . $ `<file>/src/OVAL/results/oval_cmp_ip_address_impl.h`/ |
| 49 | #include "oval_cmp_impl.h"cxx . . $ `<file>/src/OVAL/results/oval_cmp_impl.h`/ |
| 50 | |
| 51 | __attribute__((nonnull(1,2))) static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cstr_to_intmaxcxx . . $ cstr_to_intmax(72fb3136b965dd2).(const char *cstr, intmax_tcxx . . $ intmax_t# *result) |
| 52 | { |
| 53 | char *endptr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 54 | |
| 55 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; |
| 56 | *result = strtoimaxcxx . . $ strtoimax(44bbb87609b212fc).(cstr, &endptr, 10); |
| 57 | // Check for underflow/overflow, strtoimax sets ERANGE in such case |
| 58 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ERANGEcxx . . $ `<external>/8987895939074593727/errno-base.h:38:9`!) { |
| 59 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 60 | } |
| 61 | // Check whether there were some digits in the string |
| 62 | if (endptr == cstr) { |
| 63 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 64 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 65 | } |
| 66 | // Check whether the function used the whole string |
| 67 | if (*endptr != '\0') { |
| 68 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 69 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 70 | } |
| 71 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 72 | } |
| 73 | |
| 74 | __attribute__((nonnull(1,2))) static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cstr_to_doublecxx . . $ cstr_to_double(15581f7d2df46e17).(const char *cstr, double *result) |
| 75 | { |
| 76 | char *endptr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 77 | |
| 78 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0; |
| 79 | *result = strtodcxx . . $ strtod(3dfe5620a0d3160e).(cstr, &endptr); |
| 80 | // Check for underflow/overflow, strtoimax sets ERANGE in such case |
| 81 | if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ERANGEcxx . . $ `<external>/8987895939074593727/errno-base.h:38:9`!) { |
| 82 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 83 | } |
| 84 | // Check whether there were some digits in the string |
| 85 | if (endptr == cstr) { |
| 86 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 87 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 88 | } |
| 89 | // Check whether the function used the whole string |
| 90 | if (*endptr != '\0') { |
| 91 | errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 92 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 93 | } |
| 94 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 95 | } |
| 96 | |
| 97 | oval_result_tcxx . . $ oval_result_t# oval_str_cmp_strcxx . . $ oval_str_cmp_str(97cba3a0fb0a0268).(char *state_data, oval_datatype_tcxx . . $ oval_datatype_t# state_data_type, const char *sys_data, oval_operation_tcxx . . $ oval_operation_t# operation) |
| 98 | { |
| 99 | // finally, we have gotten to the point of comparing system data with a state |
| 100 | |
| 101 | if (state_data_type == OVAL_DATATYPE_STRINGcxx . . $ OVAL_DATATYPE_STRING.) { |
| 102 | return oval_string_cmpcxx . . $ oval_string_cmp(1cc2eda1f1bc9b56).(state_data, sys_data, operation); |
| 103 | } else if (state_data_type == OVAL_DATATYPE_INTEGERcxx . . $ OVAL_DATATYPE_INTEGER.) { |
| 104 | intmax_tcxx . . $ intmax_t# state_val, syschar_val; |
| 105 | |
| 106 | if (!cstr_to_intmaxcxx . . $ cstr_to_intmax(72fb3136b965dd2).(state_data, &state_val)) { |
| 107 | dWcxx . . $ `src/common/debug_priv.h:62:9`!( |
| 108 | "Conversion of the string \"%s\" to an integer (%zu bits) failed: %s", |
| 109 | state_data, sizeof(intmax_t)*8, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 110 | return OVAL_RESULT_ERRORcxx . . $ OVAL_RESULT_ERROR.; |
| 111 | } |
| 112 | |
| 113 | if (!cstr_to_intmaxcxx . . $ cstr_to_intmax(72fb3136b965dd2).(sys_data, &syschar_val)) { |
| 114 | dWcxx . . $ `src/common/debug_priv.h:62:9`!( |
| 115 | "Conversion of the string \"%s\" to an integer (%zu bits) failed: %s", |
| 116 | sys_data, sizeof(intmax_t)*8, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 117 | return OVAL_RESULT_ERRORcxx . . $ OVAL_RESULT_ERROR.; |
| 118 | } |
| 119 | return oval_int_cmpcxx . . $ oval_int_cmp(9cddff872de8d216).(state_val, syschar_val, operation); |
| 120 | } else if (state_data_type == OVAL_DATATYPE_FLOATcxx . . $ OVAL_DATATYPE_FLOAT.) { |
| 121 | double state_val, sys_val; |
| 122 | |
| 123 | if (!cstr_to_doublecxx . . $ cstr_to_double(15581f7d2df46e17).(state_data, &state_val)) { |
| 124 | dWcxx . . $ `src/common/debug_priv.h:62:9`!( |
| 125 | "Conversion of the string \"%s\" to a floating type (double) failed: %s", |
| 126 | state_data, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 127 | return OVAL_RESULT_ERRORcxx . . $ OVAL_RESULT_ERROR.; |
| 128 | } |
| 129 | |
| 130 | if (!cstr_to_doublecxx . . $ cstr_to_double(15581f7d2df46e17).(sys_data, &sys_val)) { |
| 131 | dWcxx . . $ `src/common/debug_priv.h:62:9`!( |
| 132 | "Conversion of the string \"%s\" to a floating type (double) failed: %s", |
| 133 | sys_data, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)); |
| 134 | return OVAL_RESULT_ERRORcxx . . $ OVAL_RESULT_ERROR.; |
| 135 | } |
| 136 | return oval_float_cmpcxx . . $ oval_float_cmp(fdbee3ef524f2c1c).(state_val, sys_val, operation); |
| 137 | } else if (state_data_type == OVAL_DATATYPE_BOOLEANcxx . . $ OVAL_DATATYPE_BOOLEAN.) { |
| 138 | int state_int; |
| 139 | int sys_int; |
| 140 | state_int = (((strcmpcxx . . $ strcmp(5ae29d726ae57f88).(state_data, "true")) == 0) || ((strcmpcxx . . $ strcmp(5ae29d726ae57f88).(state_data, "1")) == 0)) ? 1 : 0; |
| 141 | sys_int = (((strcmpcxx . . $ strcmp(5ae29d726ae57f88).(sys_data, "true")) == 0) || ((strcmpcxx . . $ strcmp(5ae29d726ae57f88).(sys_data, "1")) == 0)) ? 1 : 0; |
| 142 | return oval_boolean_cmpcxx . . $ oval_boolean_cmp(56d242478234f315).(state_int, sys_int, operation); |
| 143 | } else if (state_data_type == OVAL_DATATYPE_BINARYcxx . . $ OVAL_DATATYPE_BINARY.) { |
| 144 | return oval_binary_cmpcxx . . $ oval_binary_cmp(1cc2eda1f1bc9b56).(state_data, sys_data, operation); |
| 145 | } else if (state_data_type == OVAL_DATATYPE_EVR_STRINGcxx . . $ OVAL_DATATYPE_EVR_STRING.) { |
| 146 | return oval_evr_string_cmpcxx . . $ oval_evr_string_cmp(1cc2eda1f1bc9b56).(state_data, sys_data, operation); |
| 147 | } else if (state_data_type == OVAL_DATATYPE_DEBIAN_EVR_STRINGcxx . . $ OVAL_DATATYPE_DEBIAN_EVR_STRING.) { |
| 148 | return oval_debian_evr_string_cmpcxx . . $ oval_debian_evr_string_cmp(1cc2eda1f1bc9b56).(state_data, sys_data, operation); |
| 149 | } else if (state_data_type == OVAL_DATATYPE_VERSIONcxx . . $ OVAL_DATATYPE_VERSION.) { |
| 150 | return oval_versiontype_cmpcxx . . $ oval_versiontype_cmp(1cc2eda1f1bc9b56).(state_data, sys_data, operation); |
| 151 | } else if (state_data_type == OVAL_DATATYPE_IPV4ADDRcxx . . $ OVAL_DATATYPE_IPV4ADDR.) { |
| 152 | return oval_ipaddr_cmpcxx . . $ oval_ipaddr_cmp(70c1ad763aee40a3).(AF_INETcxx . . $ `<external>/8962547315054503424/socket.h:97:9`!, state_data, sys_data, operation); |
| 153 | } else if (state_data_type == OVAL_DATATYPE_IPV6ADDRcxx . . $ OVAL_DATATYPE_IPV6ADDR.) { |
| 154 | return oval_ipaddr_cmpcxx . . $ oval_ipaddr_cmp(70c1ad763aee40a3).(AF_INET6cxx . . $ `<external>/8962547315054503424/socket.h:105:9`!, state_data, sys_data, operation); |
| 155 | } else if (state_data_type == OVAL_DATATYPE_FILESET_REVISIONcxx . . $ OVAL_DATATYPE_FILESET_REVISION. |
| 156 | || state_data_type == OVAL_DATATYPE_IOS_VERSIONcxx . . $ OVAL_DATATYPE_IOS_VERSION.) { |
| 157 | dWcxx . . $ `src/common/debug_priv.h:62:9`!("Unsupported data type: %s.", oval_datatype_get_text(state_data_type)); |
| 158 | return OVAL_RESULT_NOT_EVALUATEDcxx . . $ OVAL_RESULT_NOT_EVALUATED.; |
| 159 | } |
| 160 | |
| 161 | oscap_seterrcxx . . $ `src/common/_error.h:52:9`!(OSCAP_EFAMILY_OVALcxx . . $ `src/common/public/oscap_error.h:61:9`!, "Invalid OVAL data type: %d.", state_data_type); |
| 162 | return OVAL_RESULT_ERRORcxx . . $ OVAL_RESULT_ERROR.; |
| 163 | } |