Skip to content

Commit 626942f

Browse files
committed
Fixed buffer overflow in build XPath for edit_xml
Ticket: ENT-13550 Changelog: Title Signed-off-by: Lars Erik Wik <[email protected]>
1 parent 3c1612d commit 626942f

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

cf-agent/files_editxml.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include <promises.h>
3030
#include <files_names.h>
3131
#include <files_edit.h>
32+
#include <stddef.h>
33+
#include <stdio.h>
3234
#include <vars.h>
3335
#include <item_lib.h>
3436
#include <sort.h>
@@ -42,6 +44,7 @@
4244
#include <ornaments.h>
4345
#include <verify_classes.h>
4446
#include <regex.h> /* StringMatch() */
47+
#include <logging.h>
4548

4649
enum editxmltypesequence
4750
{
@@ -351,6 +354,15 @@ static bool VerifyXPathBuild(EvalContext *ctx, const Attributes *attr, const Pro
351354

352355
a.transaction.ifelapsed = CF_EDIT_IFELAPSED;
353356

357+
int ret = snprintf(rawxpath, sizeof(rawxpath), "%s",
358+
a.xml.havebuildxpath ? a.xml.build_xpath : pp->promiser);
359+
if (ret < 0 ||(size_t)ret >= sizeof(rawxpath)) {
360+
Log(LOG_LEVEL_VERBOSE, "Build XPath is too long (%d >= %zu)", ret, sizeof(rawxpath));
361+
RecordFailure(ctx, pp, &a,
362+
"The promised build XPath build is too long");
363+
*result = PromiseResultUpdate(*result, PROMISE_RESULT_FAIL);
364+
return false;
365+
}
354366
if (a.xml.havebuildxpath)
355367
{
356368
strcpy(rawxpath, a.xml.build_xpath);

0 commit comments

Comments
 (0)