| 1 | /*! \file cpename.c |
| 2 | * \brief Interface to Common Platform Enumeration (CPE) URI |
| 3 | * |
| 4 | * See more details at http://nvd.nist.gov/cpe.cfm |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Copyright 2009 Red Hat Inc., Durham, North Carolina. |
| 10 | * All Rights Reserved. |
| 11 | * |
| 12 | * This library is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU Lesser General Public |
| 14 | * License as published by the Free Software Foundation; either |
| 15 | * version 2.1 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This library is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * Lesser General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Lesser General Public |
| 23 | * License along with this library; if not, write to the Free Software |
| 24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 | * |
| 26 | * Authors: |
| 27 | * Brandon Dixon <[email protected]> |
| 28 | * Lukas Kuklinek <[email protected]> |
| 29 | */ |
| 30 | |
| 31 | #define _BSD_SOURCEcxx . . $ `src/CPE/cpename.c:31:9`! |
| 32 | #define _DEFAULT_SOURCEcxx . . $ `src/CPE/cpename.c:32:9`! |
| 33 | |
| 34 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:409:9`! |
| 35 | #include <config.h>cxx . . $ `<file>/build/config.h`/ |
| 36 | #endif |
| 37 | |
| 38 | #include <string.h> |
| 39 | #include <stdio.h> |
| 40 | #include <ctype.h> |
| 41 | |
| 42 | #include "cpe_name.h"cxx . . $ `<file>/src/CPE/public/cpe_name.h`/ |
| 43 | #include "common/util.h"cxx . . $ `<file>/src/common/util.h`/ |
| 44 | #include "common/oscap_pcre.h"cxx . . $ `<file>/src/common/oscap_pcre.h`/ |
| 45 | #include "oscap_helpers.h"cxx . . $ `<file>/src/common/public/oscap_helpers.h`/ |
| 46 | |
| 47 | #define CPE_URI_SUPPORTEDcxx . . $ `src/CPE/cpename.c:47:9`! "2.3" |
| 48 | |
| 49 | // enumeration of CPE URI fields (useful for indexing arrays) |
| 50 | enum cpe_field_tcxx . . $ cpe_field_t# { |
| 51 | CPE_FIELD_TYPEcxx . . $ CPE_FIELD_TYPE. = 0, |
| 52 | CPE_FIELD_VENDORcxx . . $ CPE_FIELD_VENDOR. = 1, |
| 53 | CPE_FIELD_PRODUCTcxx . . $ CPE_FIELD_PRODUCT. = 2, |
| 54 | CPE_FIELD_VERSIONcxx . . $ CPE_FIELD_VERSION. = 3, |
| 55 | CPE_FIELD_UPDATEcxx . . $ CPE_FIELD_UPDATE. = 4, |
| 56 | CPE_FIELD_EDITIONcxx . . $ CPE_FIELD_EDITION. = 5, |
| 57 | CPE_FIELD_LANGUAGEcxx . . $ CPE_FIELD_LANGUAGE. = 6, |
| 58 | CPE_BASIC_FIELDNUMcxx . . $ CPE_BASIC_FIELDNUM. = 7, |
| 59 | |
| 60 | // Extended attributes CPE 2.3 only but packed so they are not garbled |
| 61 | // by CPE 2.2-only tools |
| 62 | CPE_FIELD_SW_EDITIONcxx . . $ CPE_FIELD_SW_EDITION. = 7, |
| 63 | CPE_FIELD_TARGET_SWcxx . . $ CPE_FIELD_TARGET_SW. = 8, |
| 64 | CPE_FIELD_TARGET_HWcxx . . $ CPE_FIELD_TARGET_HW. = 9, |
| 65 | CPE_FIELD_OTHERcxx . . $ CPE_FIELD_OTHER. = 10, |
| 66 | |
| 67 | CPE_TOTAL_FIELDNUMcxx . . $ CPE_TOTAL_FIELDNUM. = 11 |
| 68 | }; |
| 69 | |
| 70 | struct cpe_namecxx . . $ cpe_name# { |
| 71 | // char *uri; // complete URI cache |
| 72 | cpe_format_tcxx . . $ cpe_format_t# formatcxx . . $ cpe_name#format.; |
| 73 | cpe_part_tcxx . . $ cpe_part_t# partcxx . . $ cpe_name#part.; // part |
| 74 | char *vendorcxx . . $ cpe_name#vendor.; // vendor |
| 75 | char *productcxx . . $ cpe_name#product.; // product |
| 76 | char *versioncxx . . $ cpe_name#version.; // version |
| 77 | char *updatecxx . . $ cpe_name#update.; // update |
| 78 | /* also used to pack the 4 extended attributes to CPE 2.2 URIs |
| 79 | we always load these into the model so the packed format should |
| 80 | never appear in the edition field itself |
| 81 | */ |
| 82 | char *editioncxx . . $ cpe_name#edition.; |
| 83 | char *languagecxx . . $ cpe_name#language.; // language |
| 84 | |
| 85 | /* extended attributes */ |
| 86 | char *sw_editioncxx . . $ cpe_name#sw_edition.; |
| 87 | char *target_swcxx . . $ cpe_name#target_sw.; |
| 88 | char *target_hwcxx . . $ cpe_name#target_hw.; |
| 89 | char *othercxx . . $ cpe_name#other.; |
| 90 | /* end of extended attributes */ |
| 91 | }; |
| 92 | |
| 93 | /* h - hardware |
| 94 | * o - OS |
| 95 | * a - application |
| 96 | */ |
| 97 | //static const char *CPE_PART_CHAR[] = { NULL, "h", "o", "a" }; |
| 98 | |
| 99 | static const struct oscap_string_mapcxx . . $ oscap_string_map# CPE_PART_MAPcxx . . $ CPE_PART_MAP.[] = { |
| 100 | { CPE_PART_HWcxx . . $ CPE_PART_HW., "h" }, |
| 101 | { CPE_PART_OScxx . . $ CPE_PART_OS., "o" }, |
| 102 | { CPE_PART_APPcxx . . $ CPE_PART_APP., "a" }, |
| 103 | { CPE_PART_NONEcxx . . $ CPE_PART_NONE., NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! } |
| 104 | }; |
| 105 | |
| 106 | char **cpe_uri_splitcxx . . $ cpe_uri_split(25e857aacd75b4b6).(char *str, const char *delim); |
| 107 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_urldecodecxx . . $ cpe_urldecode(c6b7e35ff6de5671).(char *str); |
| 108 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpestring_comp_decodecxx . . $ cpestring_comp_decode(c6b7e35ff6de5671).(char *str); |
| 109 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_name_checkcxx . . $ cpe_name_check(c5f7da30cbc0f4e9).(const char *str); |
| 110 | static const char *cpe_get_fieldcxx . . $ cpe_get_field(8e35ce781e7edb).(const struct cpe_namecxx . . $ cpe_name# *cpe, int idx); |
| 111 | static const char *as_strcxx . . $ as_str(fb58d2e09a2a1ce6).(const char *str); |
| 112 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_set_fieldcxx . . $ cpe_set_field(d389ca41e18f977).(struct cpe_namecxx . . $ cpe_name# *cpe, int idx, const char *newval); |
| 113 | |
| 114 | static int cpe_fields_numcxx . . $ cpe_fields_num(64abfa155ff63f51).(const struct cpe_namecxx . . $ cpe_name# *cpe) |
| 115 | { |
| 116 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(cpe); |
| 117 | |
| 118 | if (cpe == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 119 | return 0; |
| 120 | int maxnum = 0; |
| 121 | int i; |
| 122 | for (i = 0; i < CPE_TOTAL_FIELDNUMcxx . . $ CPE_TOTAL_FIELDNUM.; ++i) |
| 123 | if (cpe_get_fieldcxx . . $ cpe_get_field(8e35ce781e7edb).(cpe, i)) |
| 124 | maxnum = i + 1; |
| 125 | return maxnum; |
| 126 | } |
| 127 | |
| 128 | static const char *cpe_get_fieldcxx . . $ cpe_get_field(8e35ce781e7edb).(const struct cpe_namecxx . . $ cpe_name# *cpe, int idx) |
| 129 | { |
| 130 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(cpe); |
| 131 | |
| 132 | if (cpe == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 133 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 134 | |
| 135 | switch (idx) { |
| 136 | case 0: |
| 137 | return oscap_enum_to_stringcxx . . $ oscap_enum_to_string(64165c519d473d40).(CPE_PART_MAPcxx . . $ CPE_PART_MAP., cpe->partcxx . . $ cpe_name#part.); |
| 138 | case 1: |
| 139 | return cpe->vendorcxx . . $ cpe_name#vendor.; |
| 140 | case 2: |
| 141 | return cpe->productcxx . . $ cpe_name#product.; |
| 142 | case 3: |
| 143 | return cpe->versioncxx . . $ cpe_name#version.; |
| 144 | case 4: |
| 145 | return cpe->updatecxx . . $ cpe_name#update.; |
| 146 | case 5: |
| 147 | return cpe->editioncxx . . $ cpe_name#edition.; |
| 148 | case 6: |
| 149 | return cpe->languagecxx . . $ cpe_name#language.; |
| 150 | case 7: |
| 151 | return cpe->sw_editioncxx . . $ cpe_name#sw_edition.; |
| 152 | case 8: |
| 153 | return cpe->target_swcxx . . $ cpe_name#target_sw.; |
| 154 | case 9: |
| 155 | return cpe->target_hwcxx . . $ cpe_name#target_hw.; |
| 156 | case 10: |
| 157 | return cpe->othercxx . . $ cpe_name#other.; |
| 158 | default: |
| 159 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(false); |
| 160 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_set_fieldcxx . . $ cpe_set_field(d389ca41e18f977).(struct cpe_namecxx . . $ cpe_name# * cpe, int idx, const char *newval) |
| 165 | { |
| 166 | |
| 167 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(cpe); |
| 168 | /*__attribute__nonnull__(newval); <-- can't be here, we want to set NULL */ |
| 169 | |
| 170 | if (cpe == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 171 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 172 | |
| 173 | char **fieldptr = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 174 | switch (idx) { |
| 175 | case 0: |
| 176 | cpe->partcxx . . $ cpe_name#part. = oscap_string_to_enumcxx . . $ oscap_string_to_enum(851d6ce10579b7d8).(CPE_PART_MAPcxx . . $ CPE_PART_MAP., newval); |
| 177 | return cpe->partcxx . . $ cpe_name#part. != CPE_PART_NONEcxx . . $ CPE_PART_NONE.; |
| 178 | case 1: |
| 179 | fieldptr = &cpe->vendorcxx . . $ cpe_name#vendor.; |
| 180 | break; |
| 181 | case 2: |
| 182 | fieldptr = &cpe->productcxx . . $ cpe_name#product.; |
| 183 | break; |
| 184 | case 3: |
| 185 | fieldptr = &cpe->versioncxx . . $ cpe_name#version.; |
| 186 | break; |
| 187 | case 4: |
| 188 | fieldptr = &cpe->updatecxx . . $ cpe_name#update.; |
| 189 | break; |
| 190 | case 5: |
| 191 | fieldptr = &cpe->editioncxx . . $ cpe_name#edition.; |
| 192 | break; |
| 193 | case 6: |
| 194 | fieldptr = &cpe->languagecxx . . $ cpe_name#language.; |
| 195 | break; |
| 196 | case 7: |
| 197 | fieldptr = &cpe->sw_editioncxx . . $ cpe_name#sw_edition.; |
| 198 | break; |
| 199 | case 8: |
| 200 | fieldptr = &cpe->target_swcxx . . $ cpe_name#target_sw.; |
| 201 | break; |
| 202 | case 9: |
| 203 | fieldptr = &cpe->target_hwcxx . . $ cpe_name#target_hw.; |
| 204 | break; |
| 205 | case 10: |
| 206 | fieldptr = &cpe->othercxx . . $ cpe_name#other.; |
| 207 | break; |
| 208 | |
| 209 | default: |
| 210 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(false); |
| 211 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 212 | } |
| 213 | |
| 214 | freecxx . . $ free(5d22bdacc48458e8).(*fieldptr); |
| 215 | if (newval && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(newval, "") == 0) |
| 216 | newval = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 217 | if (newval != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 218 | *fieldptr = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(newval); |
| 219 | else |
| 220 | *fieldptr = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 221 | |
| 222 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 223 | } |
| 224 | |
| 225 | struct cpe_namecxx . . $ cpe_name# *cpe_name_newcxx . . $ cpe_name_new(dfbdfc9fcef857b).(const char *cpestr) |
| 226 | { |
| 227 | |
| 228 | int i; |
| 229 | struct cpe_namecxx . . $ cpe_name# *cpe; |
| 230 | |
| 231 | cpe_format_tcxx . . $ cpe_format_t# format = cpe_name_get_format_of_strcxx . . $ cpe_name_get_format_of_str(1af0b57d976473a4).(cpestr); |
| 232 | if (cpestr && format == CPE_FORMAT_UNKNOWNcxx . . $ CPE_FORMAT_UNKNOWN.) |
| 233 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 234 | |
| 235 | cpe = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct cpe_namecxx . . $ cpe_name#)); |
| 236 | if (cpe == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 237 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 238 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(cpe, 0, sizeof(struct cpe_namecxx . . $ cpe_name#)); // zero memory |
| 239 | |
| 240 | // remember the detected format so that we save with the same format |
| 241 | cpe_name_set_formatcxx . . $ cpe_name_set_format(8ea6244cb4fc9cf0).(cpe, format); |
| 242 | |
| 243 | if (cpestr) { |
| 244 | if (format == CPE_FORMAT_URIcxx . . $ CPE_FORMAT_URI.) { |
| 245 | char *data_ = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(cpestr + 5); // without 'cpe:/' |
| 246 | char **fields_ = oscap_splitcxx . . $ oscap_split(25e857aacd75b4b6).(data_, ":"); |
| 247 | for (i = 0; fields_[i]; ++i) |
| 248 | { |
| 249 | if (i == CPE_FIELD_EDITIONcxx . . $ CPE_FIELD_EDITION.) |
| 250 | { |
| 251 | // extended properties may be packed in "edition" field |
| 252 | if (strlencxx . . $ strlen(751346f8406fd082).(fields_[i]) >= 2 && fields_[i][0] == '~') { |
| 253 | // first character is ~, that means that extended |
| 254 | // attributes are embedded into "edition" field |
| 255 | |
| 256 | char **extended_attribs = oscap_splitcxx . . $ oscap_split(25e857aacd75b4b6).(fields_[i] + 1 * sizeof(char), "~"); |
| 257 | // the first extended attribute is actually the edition |
| 258 | fields_[i] = extended_attribs[0]; |
| 259 | // the rest are ~-encoded extended attributes |
| 260 | for (int j = 0; j < 5 && extended_attribs[1 + j] != NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; ++j) { |
| 261 | if (!cpe_urldecodecxx . . $ cpe_urldecode(c6b7e35ff6de5671).(extended_attribs[1 + j])) { |
| 262 | freecxx . . $ free(5d22bdacc48458e8).(extended_attribs); |
| 263 | freecxx . . $ free(5d22bdacc48458e8).(data_); |
| 264 | freecxx . . $ free(5d22bdacc48458e8).(fields_); |
| 265 | cpe_name_freecxx . . $ cpe_name_free(6799d02d05c0f5d7).(cpe); |
| 266 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 267 | } |
| 268 | |
| 269 | cpe_set_fieldcxx . . $ cpe_set_field(d389ca41e18f977).(cpe, CPE_BASIC_FIELDNUMcxx . . $ CPE_BASIC_FIELDNUM. + j, extended_attribs[1 + j]); |
| 270 | } |
| 271 | |
| 272 | freecxx . . $ free(5d22bdacc48458e8).(extended_attribs); // we have used all the pointed to data |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | if (!cpe_urldecodecxx . . $ cpe_urldecode(c6b7e35ff6de5671).(fields_[i])) { |
| 277 | freecxx . . $ free(5d22bdacc48458e8).(data_); |
| 278 | freecxx . . $ free(5d22bdacc48458e8).(fields_); |
| 279 | cpe_name_freecxx . . $ cpe_name_free(6799d02d05c0f5d7).(cpe); |
| 280 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 281 | } |
| 282 | |
| 283 | cpe_set_fieldcxx . . $ cpe_set_field(d389ca41e18f977).(cpe, i, fields_[i]); |
| 284 | } |
| 285 | |
| 286 | freecxx . . $ free(5d22bdacc48458e8).(data_); |
| 287 | freecxx . . $ free(5d22bdacc48458e8).(fields_); |
| 288 | } |
| 289 | else if (format == CPE_FORMAT_STRINGcxx . . $ CPE_FORMAT_STRING.) { |
| 290 | char *data_ = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(cpestr + 8); // without 'cpe:2.3:' |
| 291 | char **fields_ = oscap_splitcxx . . $ oscap_split(25e857aacd75b4b6).(data_, ":"); |
| 292 | for (i = 0; fields_[i] && i < CPE_TOTAL_FIELDNUMcxx . . $ CPE_TOTAL_FIELDNUM.; ++i) |
| 293 | { |
| 294 | if (!cpestring_comp_decodecxx . . $ cpestring_comp_decode(c6b7e35ff6de5671).(fields_[i])) { |
| 295 | freecxx . . $ free(5d22bdacc48458e8).(data_); |
| 296 | freecxx . . $ free(5d22bdacc48458e8).(fields_); |
| 297 | cpe_name_freecxx . . $ cpe_name_free(6799d02d05c0f5d7).(cpe); |
| 298 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 299 | } |
| 300 | |
| 301 | cpe_set_fieldcxx . . $ cpe_set_field(d389ca41e18f977).(cpe, i, fields_[i]); |
| 302 | } |
| 303 | |
| 304 | freecxx . . $ free(5d22bdacc48458e8).(data_); |
| 305 | freecxx . . $ free(5d22bdacc48458e8).(fields_); |
| 306 | } else if (format == CPE_FORMAT_WFNcxx . . $ CPE_FORMAT_WFN.) { |
| 307 | /* FIXME: Do something here or remove the branch */ |
| 308 | } |
| 309 | } |
| 310 | return cpe; |
| 311 | } |
| 312 | |
| 313 | struct cpe_namecxx . . $ cpe_name# * cpe_name_clonecxx . . $ cpe_name_clone(9f8de1d0fa045834).(struct cpe_namecxx . . $ cpe_name# * old_name) |
| 314 | { |
| 315 | struct cpe_namecxx . . $ cpe_name# * new_name = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(struct cpe_namecxx . . $ cpe_name#)); |
| 316 | if (new_name == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 317 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 318 | |
| 319 | new_name->formatcxx . . $ cpe_name#format. = old_name->formatcxx . . $ cpe_name#format.; |
| 320 | new_name->partcxx . . $ cpe_name#part. = old_name->partcxx . . $ cpe_name#part.; |
| 321 | new_name->vendorcxx . . $ cpe_name#vendor. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old_name->vendorcxx . . $ cpe_name#vendor.); |
| 322 | new_name->productcxx . . $ cpe_name#product. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old_name->productcxx . . $ cpe_name#product.); |
| 323 | new_name->versioncxx . . $ cpe_name#version. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old_name->versioncxx . . $ cpe_name#version.); |
| 324 | new_name->updatecxx . . $ cpe_name#update. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old_name->updatecxx . . $ cpe_name#update.); |
| 325 | new_name->editioncxx . . $ cpe_name#edition. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old_name->editioncxx . . $ cpe_name#edition.); |
| 326 | new_name->languagecxx . . $ cpe_name#language. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old_name->languagecxx . . $ cpe_name#language.); |
| 327 | new_name->sw_editioncxx . . $ cpe_name#sw_edition. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old_name->sw_editioncxx . . $ cpe_name#sw_edition.); |
| 328 | new_name->target_swcxx . . $ cpe_name#target_sw. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old_name->target_swcxx . . $ cpe_name#target_sw.); |
| 329 | new_name->target_hwcxx . . $ cpe_name#target_hw. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old_name->target_hwcxx . . $ cpe_name#target_hw.); |
| 330 | new_name->othercxx . . $ cpe_name#other. = oscap_strdupcxx . . $ oscap_strdup(a8b8e32347182212).(old_name->othercxx . . $ cpe_name#other.); |
| 331 | |
| 332 | return new_name; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Takes given urlencoded string and replaces all occurences of % followed by |
| 337 | * 2 hex digits with a character. |
| 338 | * |
| 339 | * The operation is done in-place and is destructive to the data, even in |
| 340 | * case of a failure! |
| 341 | * |
| 342 | * @see cpe_urlencode |
| 343 | */ |
| 344 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_urldecodecxx . . $ cpe_urldecode(c6b7e35ff6de5671).(char *str) |
| 345 | { |
| 346 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(str); |
| 347 | |
| 348 | char *inptr, *outptr; |
| 349 | |
| 350 | for (inptr = outptr = str; *inptr; ++inptr) { |
| 351 | if (*inptr == '%') { |
| 352 | if (isxdigitcxx . . $ `<external>/17904084882347303253/ctype.h:199:10`!(inptr[1]) && isxdigitcxx . . $ `<external>/17904084882347303253/ctype.h:199:10`!(inptr[2])) { |
| 353 | char hex[3] = { inptr[1], inptr[2], '\0' }; |
| 354 | unsigned out; |
| 355 | sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(hex, "%x", &out); |
| 356 | if (out == 0) { |
| 357 | // %00 encoded in the URI is definitely invalid |
| 358 | *outptr++ = '\0'; |
| 359 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 360 | } |
| 361 | *outptr++ = out; |
| 362 | inptr += 2; |
| 363 | } else { |
| 364 | // % followed by characters that are not hex digits is invalid |
| 365 | *outptr = '\0'; |
| 366 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 367 | } |
| 368 | } else |
| 369 | *outptr++ = *inptr; |
| 370 | } |
| 371 | *outptr = '\0'; |
| 372 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Takes given string and replaces occurences of non-alphanumber characters |
| 377 | * except -._~ with % followed by hex digits representing that particular |
| 378 | * character. |
| 379 | * |
| 380 | * cpe_urlencode(" abc") would return "%20abc", |
| 381 | * cpe_urlencode("%") would return "%25". |
| 382 | */ |
| 383 | static char *cpe_urlencodecxx . . $ cpe_urlencode(a8b8e32347182212).(const char *str) |
| 384 | { |
| 385 | if (str == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 386 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 387 | |
| 388 | // allocate enough space |
| 389 | // in the worst case (all characters need to be replaced), the memory |
| 390 | // we will need is 3 times the size of input, + 1 for the terminating \0 |
| 391 | char *result = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(strlencxx . . $ strlen(751346f8406fd082).(str) * 3 * sizeof(char) + 1); |
| 392 | char *out = result; |
| 393 | |
| 394 | for (const char *in = str; *in != '\0'; ++in, ++out) { |
| 395 | if (isalnumcxx . . $ `<external>/17904084882347303253/ctype.h:189:10`!(*in) || strchrcxx . . $ strchr(2050848944e00d54).("-._~", *in)) |
| 396 | *out = *in; |
| 397 | else { |
| 398 | // this char shall be %-encoded |
| 399 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(out, 4, "%%%02X", *in); // we write 3 chars and \0 |
| 400 | out += 2; // for loop does another ++, giving us += 3 effectively |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | // if the last character was alphanumeric we need to terminate |
| 405 | // if the last character was non-alphanum we will have 2 consecutive |
| 406 | // \0s at the end of the string which doesn't hurt anything |
| 407 | *out = '\0'; |
| 408 | |
| 409 | return result; |
| 410 | } |
| 411 | |
| 412 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpestring_comp_decodecxx . . $ cpestring_comp_decode(c6b7e35ff6de5671).(char *str) |
| 413 | { |
| 414 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(str); |
| 415 | |
| 416 | char *inptr, *outptr; |
| 417 | |
| 418 | for (inptr = outptr = str; *inptr; ++inptr) { |
| 419 | if (*inptr == '\\' && *(inptr + sizeof(char)) == ':') { |
| 420 | *outptr = ':'; |
| 421 | inptr++; |
| 422 | } |
| 423 | else if (*inptr == '%') { |
| 424 | if (isxdigitcxx . . $ `<external>/17904084882347303253/ctype.h:199:10`!(inptr[1]) && isxdigitcxx . . $ `<external>/17904084882347303253/ctype.h:199:10`!(inptr[2])) { |
| 425 | char hex[3] = { inptr[1], inptr[2], '\0' }; |
| 426 | unsigned out; |
| 427 | sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(hex, "%x", &out); |
| 428 | if (out == 0) { |
| 429 | // %00 encoded in the URI is definitely invalid |
| 430 | *outptr++ = '\0'; |
| 431 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 432 | } |
| 433 | *outptr++ = out; |
| 434 | inptr += 2; |
| 435 | } else { |
| 436 | // % followed by characters that are not hex digits is invalid |
| 437 | *outptr = '\0'; |
| 438 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 439 | } |
| 440 | } else |
| 441 | *outptr++ = *inptr; |
| 442 | } |
| 443 | *outptr = '\0'; |
| 444 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 445 | } |
| 446 | |
| 447 | static char *cpestring_comp_encodecxx . . $ cpestring_comp_encode(a8b8e32347182212).(const char *str) |
| 448 | { |
| 449 | if (str == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 450 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 451 | |
| 452 | // allocate enough space |
| 453 | // in the worst case (all characters need to be replaced), the memory |
| 454 | // we will need is 3 times the size of input, + 1 for the terminating \0 |
| 455 | char *result = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(strlencxx . . $ strlen(751346f8406fd082).(str) * 3 * sizeof(char) + 1); |
| 456 | char *out = result; |
| 457 | |
| 458 | for (const char *in = str; *in != '\0'; ++in, ++out) { |
| 459 | if (isalnumcxx . . $ `<external>/17904084882347303253/ctype.h:189:10`!(*in) || strchrcxx . . $ strchr(2050848944e00d54).("._~", *in)) { |
| 460 | *out = *in; |
| 461 | } |
| 462 | else if (*in == '\\') { |
| 463 | // anything escaped stays escaped |
| 464 | *(out++) = *(in++); |
| 465 | *(out) = *(in); |
| 466 | } |
| 467 | else if (*in == ':') { |
| 468 | *(out++) = '\\'; |
| 469 | *(out) = *in; |
| 470 | } |
| 471 | else if (*in == '*') { |
| 472 | *out = *in; |
| 473 | } |
| 474 | else if (*in == '-') { |
| 475 | *out = *in; |
| 476 | } |
| 477 | else { |
| 478 | // this char shall be %-encoded |
| 479 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(out, 4, "%%%02X", *in); // we write 3 chars and \0 |
| 480 | out += 2; // for loop does another ++, giving us += 3 effectively |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | // if the last character was alphanumeric we need to terminate |
| 485 | // if the last character was non-alphanum we will have 2 consecutive |
| 486 | // \0s at the end of the string which doesn't hurt anything |
| 487 | *out = '\0'; |
| 488 | |
| 489 | return result; |
| 490 | } |
| 491 | |
| 492 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_has_extended_attributescxx . . $ cpe_has_extended_attributes(500221e3d00318a9).(const struct cpe_namecxx . . $ cpe_name# *cpe) |
| 493 | { |
| 494 | return cpe && ( |
| 495 | (cpe->sw_editioncxx . . $ cpe_name#sw_edition. && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(cpe->sw_editioncxx . . $ cpe_name#sw_edition., "")) || |
| 496 | (cpe->target_swcxx . . $ cpe_name#target_sw. && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(cpe->target_swcxx . . $ cpe_name#target_sw., "")) || |
| 497 | (cpe->target_hwcxx . . $ cpe_name#target_hw. && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(cpe->target_hwcxx . . $ cpe_name#target_hw., "")) || |
| 498 | (cpe->othercxx . . $ cpe_name#other. && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(cpe->othercxx . . $ cpe_name#other., "")) |
| 499 | ); |
| 500 | } |
| 501 | |
| 502 | static char *cpe_pack_extended_attributescxx . . $ cpe_pack_extended_attributes(ca24c8d7625ff2e2).(const struct cpe_namecxx . . $ cpe_name# *cpe) |
| 503 | { |
| 504 | char* encoded_edition = cpe_urlencodecxx . . $ cpe_urlencode(a8b8e32347182212).(cpe->editioncxx . . $ cpe_name#edition. ? cpe->editioncxx . . $ cpe_name#edition. : ""); |
| 505 | char* encoded_sw_edition = cpe_urlencodecxx . . $ cpe_urlencode(a8b8e32347182212).(cpe->sw_editioncxx . . $ cpe_name#sw_edition. ? cpe->sw_editioncxx . . $ cpe_name#sw_edition. : ""); |
| 506 | char* encoded_target_sw = cpe_urlencodecxx . . $ cpe_urlencode(a8b8e32347182212).(cpe->target_swcxx . . $ cpe_name#target_sw. ? cpe->target_swcxx . . $ cpe_name#target_sw. : ""); |
| 507 | char* encoded_target_hw = cpe_urlencodecxx . . $ cpe_urlencode(a8b8e32347182212).(cpe->target_hwcxx . . $ cpe_name#target_hw. ? cpe->target_hwcxx . . $ cpe_name#target_hw. : ""); |
| 508 | char* encoded_other = cpe_urlencodecxx . . $ cpe_urlencode(a8b8e32347182212).(cpe->othercxx . . $ cpe_name#other. ? cpe->othercxx . . $ cpe_name#other. : ""); |
| 509 | |
| 510 | char* ret = oscap_sprintfcxx . . $ oscap_sprintf(a849077ff1b8d812).("~%s~%s~%s~%s~%s", |
| 511 | encoded_edition, |
| 512 | encoded_sw_edition, |
| 513 | encoded_target_sw, |
| 514 | encoded_target_hw, |
| 515 | encoded_other |
| 516 | ); |
| 517 | |
| 518 | freecxx . . $ free(5d22bdacc48458e8).(encoded_edition); |
| 519 | freecxx . . $ free(5d22bdacc48458e8).(encoded_sw_edition); |
| 520 | freecxx . . $ free(5d22bdacc48458e8).(encoded_target_sw); |
| 521 | freecxx . . $ free(5d22bdacc48458e8).(encoded_target_hw); |
| 522 | freecxx . . $ free(5d22bdacc48458e8).(encoded_other); |
| 523 | |
| 524 | return ret; |
| 525 | } |
| 526 | |
| 527 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_name_match_onecxx . . $ cpe_name_match_one(4808e5a017f8458a).(const struct cpe_namecxx . . $ cpe_name# * cpe, const struct cpe_namecxx . . $ cpe_name# * against) |
| 528 | { |
| 529 | |
| 530 | int i; |
| 531 | if (cpe == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! || against == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 532 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 533 | |
| 534 | int cpefn = cpe_fields_numcxx . . $ cpe_fields_num(64abfa155ff63f51).(cpe); |
| 535 | if (cpe_fields_numcxx . . $ cpe_fields_num(64abfa155ff63f51).(against) < cpefn) |
| 536 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 537 | |
| 538 | for (i = 0; i < cpefn; ++i) { |
| 539 | const char *cpefield = cpe_get_fieldcxx . . $ cpe_get_field(8e35ce781e7edb).(cpe, i); |
| 540 | if (cpefield && oscap_strcasecmpcxx . . $ oscap_strcasecmp(5ae29d726ae57f88).(cpefield, as_strcxx . . $ as_str(fb58d2e09a2a1ce6).(cpe_get_fieldcxx . . $ cpe_get_field(8e35ce781e7edb).(against, i))) != 0) |
| 541 | return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 542 | } |
| 543 | |
| 544 | return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 545 | } |
| 546 | |
| 547 | cpe_format_tcxx . . $ cpe_format_t# cpe_name_get_format_of_strcxx . . $ cpe_name_get_format_of_str(1af0b57d976473a4).(const char *str) |
| 548 | { |
| 549 | if (str == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 550 | return CPE_FORMAT_UNKNOWNcxx . . $ CPE_FORMAT_UNKNOWN.; |
| 551 | |
| 552 | oscap_pcre_tcxx . . $ oscap_pcre_t# *re; |
| 553 | char *error; |
| 554 | int erroffset; |
| 555 | int rc; |
| 556 | int ovector[30]; |
| 557 | |
| 558 | // The regex was taken from the official XSD at |
| 559 | // http://scap.nist.gov/schema/cpe/2.3/cpe-naming_2.3.xsd |
| 560 | // [c] was replaced with [cC] here and in the schemas |
| 561 | |
| 562 | re = oscap_pcre_compilecxx . . $ oscap_pcre_compile(29ca11f2d36a957a).("^[cC][pP][eE]:/[AHOaho]?(:[A-Za-z0-9\\._\\-~%]*){0,6}$", 0, &error, &erroffset); |
| 563 | if (re == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 564 | oscap_pcre_err_freecxx . . $ oscap_pcre_err_free(fda57c8427c60377).(error); |
| 565 | return CPE_FORMAT_UNKNOWNcxx . . $ CPE_FORMAT_UNKNOWN.; |
| 566 | } |
| 567 | rc = oscap_pcre_execcxx . . $ oscap_pcre_exec(7630dfd25fd504ec).(re, str, strlencxx . . $ strlen(751346f8406fd082).(str), 0, 0, ovector, 30); |
| 568 | oscap_pcre_freecxx . . $ oscap_pcre_free(804bb72472b0846e).(re); |
| 569 | |
| 570 | if (rc >= 0) |
| 571 | return CPE_FORMAT_URIcxx . . $ CPE_FORMAT_URI.; |
| 572 | |
| 573 | // The regex was taken from the official XSD at |
| 574 | // http://scap.nist.gov/schema/cpe/2.3/cpe-naming_2.3.xsd |
| 575 | re = oscap_pcre_compilecxx . . $ oscap_pcre_compile(29ca11f2d36a957a).("^cpe:2\\.3:[aho\\*\\-](:(((\\?*|\\*?)([a-zA-Z0-9\\-\\._]|(\\\\[\\\\\\*\\?!\"#$$%&'\\(\\)\\+,/:;<=>@\\[\\]\\^`\\{\\|}~]))+(\\?*|\\*?))|[\\*\\-])){5}(:(([a-zA-Z]{2,3}(-([a-zA-Z]{2}|[0-9]{3}))?)|[\\*\\-]))(:(((\\?*|\\*?)([a-zA-Z0-9\\-\\._]|(\\\\[\\\\\\*\\?!\"#$$%&'\\(\\)\\+,/:;<=>@\\[\\]\\^`\\{\\|}~]))+(\\?*|\\*?))|[\\*\\-])){4}$", 0, &error, &erroffset); |
| 576 | if (re == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 577 | oscap_pcre_err_freecxx . . $ oscap_pcre_err_free(fda57c8427c60377).(error); |
| 578 | return CPE_FORMAT_UNKNOWNcxx . . $ CPE_FORMAT_UNKNOWN.; |
| 579 | } |
| 580 | rc = oscap_pcre_execcxx . . $ oscap_pcre_exec(7630dfd25fd504ec).(re, str, strlencxx . . $ strlen(751346f8406fd082).(str), 0, 0, ovector, 30); |
| 581 | oscap_pcre_freecxx . . $ oscap_pcre_free(804bb72472b0846e).(re); |
| 582 | |
| 583 | if (rc >= 0) |
| 584 | return CPE_FORMAT_STRINGcxx . . $ CPE_FORMAT_STRING.; |
| 585 | |
| 586 | // FIXME: This should be way more strict |
| 587 | re = oscap_pcre_compilecxx . . $ oscap_pcre_compile(29ca11f2d36a957a).("^wfn:\\[.+\\]$", OSCAP_PCRE_OPTS_CASELESScxx . . $ OSCAP_PCRE_OPTS_CASELESS., &error, &erroffset); |
| 588 | if (re == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) { |
| 589 | oscap_pcre_err_freecxx . . $ oscap_pcre_err_free(fda57c8427c60377).(error); |
| 590 | return CPE_FORMAT_UNKNOWNcxx . . $ CPE_FORMAT_UNKNOWN.; |
| 591 | } |
| 592 | rc = oscap_pcre_execcxx . . $ oscap_pcre_exec(7630dfd25fd504ec).(re, str, strlencxx . . $ strlen(751346f8406fd082).(str), 0, 0, ovector, 30); |
| 593 | oscap_pcre_freecxx . . $ oscap_pcre_free(804bb72472b0846e).(re); |
| 594 | |
| 595 | if (rc >= 0) |
| 596 | return CPE_FORMAT_WFNcxx . . $ CPE_FORMAT_WFN.; |
| 597 | |
| 598 | return CPE_FORMAT_UNKNOWNcxx . . $ CPE_FORMAT_UNKNOWN.; |
| 599 | } |
| 600 | |
| 601 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cpe_name_checkcxx . . $ cpe_name_check(c5f7da30cbc0f4e9).(const char *str) |
| 602 | { |
| 603 | return cpe_name_get_format_of_strcxx . . $ cpe_name_get_format_of_str(1af0b57d976473a4).(str) != CPE_FORMAT_UNKNOWNcxx . . $ CPE_FORMAT_UNKNOWN.; |
| 604 | } |
| 605 | |
| 606 | static const char *as_strcxx . . $ as_str(fb58d2e09a2a1ce6).(const char *str) |
| 607 | { |
| 608 | if (str == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 609 | return ""; |
| 610 | return str; |
| 611 | } |
| 612 | |
| 613 | char *cpe_name_get_as_formatcxx . . $ cpe_name_get_as_format(d944afa77bbd3357).(const struct cpe_namecxx . . $ cpe_name# *cpe, cpe_format_tcxx . . $ cpe_format_t# format) |
| 614 | { |
| 615 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(cpe); |
| 616 | |
| 617 | if (format == CPE_FORMAT_URIcxx . . $ CPE_FORMAT_URI.) |
| 618 | { |
| 619 | int len = 16; |
| 620 | int i; |
| 621 | char *result; |
| 622 | char* part[CPE_BASIC_FIELDNUMcxx . . $ CPE_BASIC_FIELDNUM.] = { NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! }; // CPE URI parts |
| 623 | |
| 624 | if (cpe == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 625 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 626 | |
| 627 | // get individual parts (%-encoded) |
| 628 | for (i = 0; i < CPE_BASIC_FIELDNUMcxx . . $ CPE_BASIC_FIELDNUM.; ++i) { |
| 629 | if (i == CPE_FIELD_EDITIONcxx . . $ CPE_FIELD_EDITION. && cpe_has_extended_attributescxx . . $ cpe_has_extended_attributes(500221e3d00318a9).(cpe)) |
| 630 | part[i] = cpe_pack_extended_attributescxx . . $ cpe_pack_extended_attributes(ca24c8d7625ff2e2).(cpe); |
| 631 | else |
| 632 | part[i] = cpe_urlencodecxx . . $ cpe_urlencode(a8b8e32347182212).(as_strcxx . . $ as_str(fb58d2e09a2a1ce6).(cpe_get_fieldcxx . . $ cpe_get_field(8e35ce781e7edb).(cpe, i))); |
| 633 | |
| 634 | len += strlencxx . . $ strlen(751346f8406fd082).(part[i]); |
| 635 | } |
| 636 | |
| 637 | result = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(len * sizeof(char)); |
| 638 | if (result == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 639 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 640 | |
| 641 | // create the URI |
| 642 | i = snprintfcxx . . $ snprintf(ea502d73e74c754c).(result, len, "cpe:/%s:%s:%s:%s:%s:%s:%s", |
| 643 | part[0], part[1], part[2], part[3], part[4], part[5], part[6] |
| 644 | ); |
| 645 | |
| 646 | // free individual parts |
| 647 | for (int j = 0; j < CPE_BASIC_FIELDNUMcxx . . $ CPE_BASIC_FIELDNUM.; ++j) |
| 648 | freecxx . . $ free(5d22bdacc48458e8).(part[j]); |
| 649 | |
| 650 | // trim trailing colons |
| 651 | while (result[--i] == ':') |
| 652 | result[i] = '\0'; |
| 653 | |
| 654 | return result; |
| 655 | } |
| 656 | else if (format == CPE_FORMAT_STRINGcxx . . $ CPE_FORMAT_STRING.) |
| 657 | { |
| 658 | int len = 19; |
| 659 | int i; |
| 660 | char *result; |
| 661 | char* part[CPE_TOTAL_FIELDNUMcxx . . $ CPE_TOTAL_FIELDNUM.] = { NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`! }; // CPE string parts |
| 662 | |
| 663 | if (cpe == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 664 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 665 | |
| 666 | // get individual parts (%-encoded) |
| 667 | for (i = 0; i < CPE_TOTAL_FIELDNUMcxx . . $ CPE_TOTAL_FIELDNUM.; ++i) { |
| 668 | part[i] = cpestring_comp_encodecxx . . $ cpestring_comp_encode(a8b8e32347182212).(as_strcxx . . $ as_str(fb58d2e09a2a1ce6).(cpe_get_fieldcxx . . $ cpe_get_field(8e35ce781e7edb).(cpe, i))); |
| 669 | |
| 670 | len += strlencxx . . $ strlen(751346f8406fd082).(part[i]); |
| 671 | } |
| 672 | |
| 673 | result = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(len * sizeof(char)); |
| 674 | if (result == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 675 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 676 | |
| 677 | // create the URI |
| 678 | i = snprintfcxx . . $ snprintf(ea502d73e74c754c).(result, len, "cpe:2.3:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s", |
| 679 | part[0], part[1], part[2], part[3], part[4], part[5], part[6], |
| 680 | part[7], part[8], part[9], part[10] |
| 681 | ); |
| 682 | |
| 683 | // free individual parts |
| 684 | for (int j = 0; j < CPE_TOTAL_FIELDNUMcxx . . $ CPE_TOTAL_FIELDNUM.; ++j) |
| 685 | freecxx . . $ free(5d22bdacc48458e8).(part[j]); |
| 686 | |
| 687 | return result; |
| 688 | } |
| 689 | else |
| 690 | { |
| 691 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!; |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | char *cpe_name_get_as_strcxx . . $ cpe_name_get_as_str(ca24c8d7625ff2e2).(const struct cpe_namecxx . . $ cpe_name# *cpe) |
| 696 | { |
| 697 | cpe_format_tcxx . . $ cpe_format_t# format = cpe_name_get_formatcxx . . $ cpe_name_get_format(3d8320da7db56924).(cpe); |
| 698 | |
| 699 | return cpe_name_get_as_formatcxx . . $ cpe_name_get_as_format(d944afa77bbd3357).(cpe, format); |
| 700 | } |
| 701 | |
| 702 | int cpe_name_writecxx . . $ cpe_name_write(8b00dff880ab70e4).(const struct cpe_namecxx . . $ cpe_name# *cpe, FILEcxx . . $ FILE# * f) |
| 703 | { |
| 704 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(cpe); |
| 705 | __attribute__nonnull__cxx . . $ `src/common/util.h:39:9`!(f); |
| 706 | |
| 707 | int ret; |
| 708 | char *uri; |
| 709 | |
| 710 | uri = cpe_name_get_as_strcxx . . $ cpe_name_get_as_str(ca24c8d7625ff2e2).(cpe); |
| 711 | if (uri == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 712 | return EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`!; |
| 713 | |
| 714 | ret = fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(f, "%s", uri); |
| 715 | |
| 716 | freecxx . . $ free(5d22bdacc48458e8).(uri); |
| 717 | return ret; |
| 718 | } |
| 719 | |
| 720 | void cpe_name_freecxx . . $ cpe_name_free(6799d02d05c0f5d7).(struct cpe_namecxx . . $ cpe_name# *cpe) |
| 721 | { |
| 722 | if (cpe == NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!) |
| 723 | return; |
| 724 | |
| 725 | int i; |
| 726 | for (i = 0; i < CPE_TOTAL_FIELDNUMcxx . . $ CPE_TOTAL_FIELDNUM.; ++i) |
| 727 | cpe_set_fieldcxx . . $ cpe_set_field(d389ca41e18f977).(cpe, i, NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!); |
| 728 | freecxx . . $ free(5d22bdacc48458e8).(cpe); |
| 729 | } |
| 730 | |
| 731 | const char * cpe_name_supportedcxx . . $ cpe_name_supported(33a1f659e94feb42).(void) |
| 732 | { |
| 733 | return CPE_URI_SUPPORTEDcxx . . $ `src/CPE/cpename.c:47:9`!; |
| 734 | } |
| 735 | |
| 736 | OSCAP_ACCESSOR_SIMPLEcxx . . $ `src/common/util.h:258:9`!(cpe_format_t, cpe_name, format) |
| 737 | OSCAP_ACCESSOR_SIMPLEcxx . . $ `src/common/util.h:258:9`!(cpe_part_t, cpe_name, part) |
| 738 | OSCAP_ACCESSOR_STRINGcxx . . $ `src/common/util.h:245:9`!(cpe_name, vendor) |
| 739 | OSCAP_ACCESSOR_STRINGcxx . . $ `src/common/util.h:245:9`!(cpe_name, product) |
| 740 | OSCAP_ACCESSOR_STRINGcxx . . $ `src/common/util.h:245:9`!(cpe_name, version) |
| 741 | OSCAP_ACCESSOR_STRINGcxx . . $ `src/common/util.h:245:9`!(cpe_name, update) |
| 742 | OSCAP_ACCESSOR_STRINGcxx . . $ `src/common/util.h:245:9`!(cpe_name, edition) |
| 743 | OSCAP_ACCESSOR_STRINGcxx . . $ `src/common/util.h:245:9`!(cpe_name, language) |
| 744 | OSCAP_ACCESSOR_STRINGcxx . . $ `src/common/util.h:245:9`!(cpe_name, sw_edition) |
| 745 | OSCAP_ACCESSOR_STRINGcxx . . $ `src/common/util.h:245:9`!(cpe_name, target_sw) |
| 746 | OSCAP_ACCESSOR_STRINGcxx . . $ `src/common/util.h:245:9`!(cpe_name, target_hw) |
| 747 | OSCAP_ACCESSOR_STRINGcxx . . $ `src/common/util.h:245:9`!(cpe_name, other) |