Skip to content

Commit ebeb608

Browse files
committed
Use something else than pointer arithmetics
1 parent fc9d30a commit ebeb608

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/XCCDF/item.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "helpers.h"
4242
#include "xccdf_impl.h"
4343
#include "common/util.h"
44+
#include "oscap_helpers.h"
4445

4546
/* According to `man 3 pcreapi`, the number passed in ovecsize should always
4647
* be a multiple of three.
@@ -767,23 +768,21 @@ void xccdf_item_add_applicable_platform(struct xccdf_item *item, xmlTextReaderPt
767768
int rc = pcre_exec(regex, NULL, platform_idref, strlen(platform_idref), 0, 0, ovector, OVECTOR_LEN);
768769
/* 1 pattern + 2 groups = 3 */
769770
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);
773771
const int first_group_start = ovector[2];
774772
const int first_group_end = ovector[3];
775773
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';
776777
const int second_group_start = ovector[4];
777778
const int second_group_end = ovector[5];
778779
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);
787786
oscap_list_add(item->item.platforms, alternate_platform_idref);
788787
}
789788

0 commit comments

Comments
 (0)