Skip to content

Commit dfeff2b

Browse files
committed
Fixed buffer overflow in the files promise
Ticket: SEC-1892 Changelog: Title Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech> (cherry picked from commit f3388b1)
1 parent 5dad623 commit dfeff2b

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

cf-agent/verify_files.c

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
#include <evalfunction.h>
6161
#include <changes_chroot.h> /* PrepareChangesChroot(), RecordFileChangedInChroot() */
6262
#include <cf3.defs.h>
63+
#include <logging.h>
64+
#include <stddef.h>
65+
#include <string.h>
6366

6467
static PromiseResult FindFilePromiserObjects(EvalContext *ctx, const Promise *pp);
6568
static PromiseResult VerifyFilePromise(EvalContext *ctx, char *path, const Promise *pp);
@@ -1013,12 +1016,26 @@ PromiseResult ScheduleEditOperation(EvalContext *ctx, char *filename,
10131016
if ((vp = PromiseGetConstraintAsRval(pp, "edit_line", RVAL_TYPE_FNCALL)))
10141017
{
10151018
fp = (FnCall *) vp;
1016-
strcpy(edit_bundle_name, fp->name);
1019+
size_t ret = strlcpy(edit_bundle_name, fp->name, sizeof(edit_bundle_name));
1020+
if (ret >= sizeof(edit_bundle_name))
1021+
{
1022+
Log(LOG_LEVEL_ERR,
1023+
"The edit_line bundle name is too long (%zu >= %zu)",
1024+
ret, sizeof(edit_bundle_name));
1025+
goto exit;
1026+
}
10171027
args = fp->args;
10181028
}
10191029
else if ((vp = PromiseGetConstraintAsRval(pp, "edit_line", RVAL_TYPE_SCALAR)))
10201030
{
1021-
strcpy(edit_bundle_name, (char *) vp);
1031+
size_t ret = strlcpy(edit_bundle_name, (char *) vp, sizeof(edit_bundle_name));
1032+
if (ret >= sizeof(edit_bundle_name))
1033+
{
1034+
Log(LOG_LEVEL_ERR,
1035+
"The edit_line bundle name is too long (%zu >= %zu)",
1036+
ret, sizeof(edit_bundle_name));
1037+
goto exit;
1038+
}
10221039
args = NULL;
10231040
}
10241041
else
@@ -1051,12 +1068,26 @@ PromiseResult ScheduleEditOperation(EvalContext *ctx, char *filename,
10511068
if ((vp = PromiseGetConstraintAsRval(pp, "edit_xml", RVAL_TYPE_FNCALL)))
10521069
{
10531070
fp = (FnCall *) vp;
1054-
strcpy(edit_bundle_name, fp->name);
1071+
size_t ret = strlcpy(edit_bundle_name, fp->name, sizeof(edit_bundle_name));
1072+
if (ret >= sizeof(edit_bundle_name))
1073+
{
1074+
Log(LOG_LEVEL_ERR,
1075+
"The edit_xml bundle name is too long (%zu >= %zu)",
1076+
ret, sizeof(edit_bundle_name));
1077+
goto exit;
1078+
}
10551079
args = fp->args;
10561080
}
10571081
else if ((vp = PromiseGetConstraintAsRval(pp, "edit_xml", RVAL_TYPE_SCALAR)))
10581082
{
1059-
strcpy(edit_bundle_name, (char *) vp);
1083+
size_t ret = strlcpy(edit_bundle_name, (char *) vp, sizeof(edit_bundle_name));
1084+
if (ret >= sizeof(edit_bundle_name))
1085+
{
1086+
Log(LOG_LEVEL_ERR,
1087+
"The edit_xml bundle name is too long (%zu >= %zu)",
1088+
ret, sizeof(edit_bundle_name));
1089+
goto exit;
1090+
}
10601091
args = NULL;
10611092
}
10621093
else

0 commit comments

Comments
 (0)