|
29 | 29 | #include <promises.h> |
30 | 30 | #include <files_names.h> |
31 | 31 | #include <files_edit.h> |
| 32 | +#include <stddef.h> |
| 33 | +#include <stdio.h> |
32 | 34 | #include <vars.h> |
33 | 35 | #include <item_lib.h> |
34 | 36 | #include <sort.h> |
|
42 | 44 | #include <ornaments.h> |
43 | 45 | #include <verify_classes.h> |
44 | 46 | #include <regex.h> /* StringMatch() */ |
| 47 | +#include <logging.h> |
45 | 48 |
|
46 | 49 | enum editxmltypesequence |
47 | 50 | { |
@@ -344,20 +347,22 @@ static PromiseResult KeepEditXmlPromise(EvalContext *ctx, const Promise *pp, |
344 | 347 | static bool VerifyXPathBuild(EvalContext *ctx, const Attributes *attr, const Promise *pp, EditContext *edcontext, PromiseResult *result) |
345 | 348 | { |
346 | 349 | assert(attr != NULL); |
| 350 | + assert(pp != NULL); |
347 | 351 | Attributes a = *attr; // TODO: Remove this copy |
348 | 352 | xmlDocPtr doc = NULL; |
349 | 353 | CfLock thislock; |
350 | 354 | char lockname[CF_BUFSIZE], rawxpath[CF_BUFSIZE] = { 0 }; |
351 | 355 |
|
352 | 356 | a.transaction.ifelapsed = CF_EDIT_IFELAPSED; |
353 | 357 |
|
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; |
361 | 366 | } |
362 | 367 |
|
363 | 368 | if (!SanityCheckXPathBuild(ctx, &a, pp, result)) |
|
0 commit comments