|
41 | 41 | #include "helpers.h"
|
42 | 42 | #include "xccdf_impl.h"
|
43 | 43 | #include "common/util.h"
|
| 44 | +#include "oscap_helpers.h" |
44 | 45 |
|
45 | 46 | /* According to `man 3 pcreapi`, the number passed in ovecsize should always
|
46 | 47 | * be a multiple of three.
|
@@ -767,23 +768,21 @@ void xccdf_item_add_applicable_platform(struct xccdf_item *item, xmlTextReaderPt
|
767 | 768 | int rc = pcre_exec(regex, NULL, platform_idref, strlen(platform_idref), 0, 0, ovector, OVECTOR_LEN);
|
768 | 769 | /* 1 pattern + 2 groups = 3 */
|
769 | 770 | if (rc == 3) {
|
770 |
| - size_t match_len = ovector[1] - ovector[0]; |
771 |
| - /* match_len + 1 underscore + 1 zero byte */ |
772 |
| - char *alternate_platform_idref = malloc(match_len + 1 + 1); |
773 | 771 | const int first_group_start = ovector[2];
|
774 | 772 | const int first_group_end = ovector[3];
|
775 | 773 | size_t first_group_len = first_group_end - first_group_start;
|
| 774 | + char *first_group = malloc(first_group_len + 1); // + 1 for '\0' |
| 775 | + strncpy(first_group, platform_idref + first_group_start, first_group_len); |
| 776 | + first_group[first_group_len] = '\0'; |
776 | 777 | const int second_group_start = ovector[4];
|
777 | 778 | const int second_group_end = ovector[5];
|
778 | 779 | size_t second_group_len = second_group_end - second_group_start;
|
779 |
| - char *aptr = alternate_platform_idref; |
780 |
| - strncpy(aptr, platform_idref + first_group_start, first_group_len); |
781 |
| - aptr += first_group_len; |
782 |
| - *aptr = '_'; |
783 |
| - aptr++; |
784 |
| - strncpy(aptr, platform_idref + second_group_start, second_group_len); |
785 |
| - aptr += second_group_len; |
786 |
| - *aptr = '\0'; |
| 780 | + char *second_group = malloc(second_group_len + 1); // + 1 for '\0' |
| 781 | + strncpy(second_group, platform_idref + second_group_start, second_group_len); |
| 782 | + second_group[second_group_len] = '\0'; |
| 783 | + char *alternate_platform_idref = oscap_sprintf("%s_%s", first_group, second_group); |
| 784 | + free(first_group); |
| 785 | + free(second_group); |
787 | 786 | oscap_list_add(item->item.platforms, alternate_platform_idref);
|
788 | 787 | }
|
789 | 788 |
|
|
0 commit comments