From b47b97c2602bdd784b0f63dc3e971e023f48e260 Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Wed, 2 Mar 2022 12:38:12 -0800
Subject: [PATCH] Detect smb_[f]allocdat() failure in editmsg()

CID 319091
---
 src/sbbs3/writemsg.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/sbbs3/writemsg.cpp b/src/sbbs3/writemsg.cpp
index 52771a23f3..92769641c5 100644
--- a/src/sbbs3/writemsg.cpp
+++ b/src/sbbs3/writemsg.cpp
@@ -1681,6 +1681,12 @@ bool sbbs_t::editmsg(smb_t* smb, smbmsg_t *msg)
 		smb_close_da(smb);
 	}
 
+	if(offset < 0) {
+		smb_unlocksmbhdr(smb);
+		errormsg(WHERE,ERR_ALLOC,msgtmp,length);
+		return false;
+	}
+
 	msg->hdr.offset=(uint32_t)offset;
 	if((file=open(msgtmp,O_RDONLY|O_BINARY))==-1
 		|| (instream=fdopen(file,"rb"))==NULL) {
-- 
GitLab