From 065f7f799cb94ee7611b4858581f0efbaffda320 Mon Sep 17 00:00:00 2001
From: Adam Borowski <kilobyte@angband.pl>
Date: Mon, 22 Jul 2019 17:25:48 +0200
Subject: [PATCH] examples: pmemobjfs: fix a string copying corruption

As usually, any use of strncpy() for a C string is a bug.  In this
case, it will never null-terminate the string, then if the malloced
buffer isn't zeroed, the strncat() will skip over some garbage.

Found by gcc-9's new warnings, just enabled in dpkg-buildflags.
---
 src/examples/libpmemobj/pmemobjfs/pmemobjfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/examples/libpmemobj/pmemobjfs/pmemobjfs.c b/src/examples/libpmemobj/pmemobjfs/pmemobjfs.c
index 8a9e99ad8..5267626d2 100644
--- a/src/examples/libpmemobj/pmemobjfs/pmemobjfs.c
+++ b/src/examples/libpmemobj/pmemobjfs/pmemobjfs.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015-2017, Intel Corporation
+ * Copyright 2015-2019, Intel Corporation
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -2377,8 +2377,8 @@ pmemobjfs_tx_ioctl(const char *dir, int req)
 	if (!path)
 		return -1;
 
-	strncpy(path, dir, dirlen);
-	strncat(path, PMEMOBJFS_TMP_TEMPLATE, tmpllen);
+	memcpy(path, dir, dirlen);
+	strcpy(path + dirlen, PMEMOBJFS_TMP_TEMPLATE);
 
 	/* create temporary file */
 	mode_t prev_umask = umask(S_IRWXG | S_IRWXO);
-- 
GitLab