Skip to content

Commit c52fe68

Browse files
authored
Merge pull request #5989 from larsewi/xpath
ENT-13550: Fixed buffer overflow in build XPath for edit_xml
2 parents 0024904 + fb474cd commit c52fe68

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

cf-agent/files_editxml.c

Lines changed: 12 additions & 7 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
{
@@ -344,20 +347,22 @@ static PromiseResult KeepEditXmlPromise(EvalContext *ctx, const Promise *pp,
344347
static bool VerifyXPathBuild(EvalContext *ctx, const Attributes *attr, const Promise *pp, EditContext *edcontext, PromiseResult *result)
345348
{
346349
assert(attr != NULL);
350+
assert(pp != NULL);
347351
Attributes a = *attr; // TODO: Remove this copy
348352
xmlDocPtr doc = NULL;
349353
CfLock thislock;
350354
char lockname[CF_BUFSIZE], rawxpath[CF_BUFSIZE] = { 0 };
351355

352356
a.transaction.ifelapsed = CF_EDIT_IFELAPSED;
353357

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

363368
if (!SanityCheckXPathBuild(ctx, &a, pp, result))

libntech

0 commit comments

Comments
 (0)