Browse Source

Ensure test buffers are always '\0' terminated

This caused spurious test failures.

Signed-off-by: Steffen Jaeckel <[email protected]>
Steffen Jaeckel 1 year ago
parent
commit
5a1545a8ae
1 changed files with 2 additions and 1 deletions
  1. 2 1
      tests/common.c

+ 2 - 1
tests/common.c

@@ -103,13 +103,14 @@ static DIR *s_opendir(const char *path, char *mypath, unsigned long l)
 static int s_read_and_process(FILE *f, unsigned long sz, void *ctx, dir_iter_cb process)
 {
    int err = CRYPT_OK;
-   void* buf = XMALLOC(sz);
+   void* buf = XMALLOC(sz + 1);
    if (buf == NULL)
       return CRYPT_MEM;
    if (fread(buf, 1, sz, f) != sz) {
       err = CRYPT_ERROR;
       goto out;
    }
+   ((unsigned char *)buf)[sz] = 0x0;
    err = process(buf, sz, ctx);
 out:
    XFREE(buf);