From a264f55769cd6cfedb842710791d71b11d830091 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 5 Sep 2016 14:29:47 +0200 Subject: [PATCH] diff_grep: add assertions verifying that the buffers are NUL-terminated Before calling regexec() on the file contents, we better be certain that the strings fulfill the contract of C strings assumed by said function. Signed-off-by: Johannes Schindelin --- diffcore-pickaxe.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diffcore-pickaxe.c b/diffcore-pickaxe.c index 55067cab6c..88820b6378 100644 --- a/diffcore-pickaxe.c +++ b/diffcore-pickaxe.c @@ -49,6 +49,8 @@ static int diff_grep(mmfile_t *one, mmfile_t *two, xpparam_t xpp; xdemitconf_t xecfg; + assert(!one || one->ptr[one->size] == '\0'); + assert(!two || two->ptr[two->size] == '\0'); if (!one) return !regexec(regexp, two->ptr, 1, ®match, 0); if (!two)