Description:Null terminate mbuf so garbage not added to end of received message.
Author: Chris Good <chris.good@ozemail.com.au>
Bug-Debian: https://bugs.debian.org/763122
Forwarded: no
Last-Update: 2024-11-29
---
--- netkit-rwall-salsa.orig/rwall/rwall.c	2024-11-29 21:56:28.120641596 +0100
+++ netkit-rwall-salsa/rwall/rwall.c	2024-11-29 21:56:36.480694964 +0100
@@ -30,6 +30,11 @@
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * 30/03/2014 chris.good@ozemail.com.au Null terminate mbuf so garbage not
+ *		added to end of received message.
+ *	Refer:
+ *	https://bugs.launchpad.net/ubuntu/+source/netkit-rwall/+bug/1277981
  */
 
 char copyright[] =
@@ -167,7 +172,7 @@
 		exit(1);
 	}
 	mbufsize = sbuf.st_size;
-	if (!(mbuf = malloc(mbufsize))) {
+	if (!(mbuf = malloc(mbufsize + 1))) {
 		(void)fprintf(stderr, "wall: out of memory.\n");
 		exit(1);
 	}
@@ -175,5 +180,6 @@
 		(void)fprintf(stderr, "wall: can't read temporary file.\n");
 		exit(1);
 	}
+	mbuf[mbufsize] = '\0';
 	(void)close(fd);
 }
