From aaa250d157ba68e55983f3aa88ac9364d06e70d3 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Wed, 1 Nov 2017 22:41:05 +0000
Subject: [PATCH] Hopefully fix issue with converting auxattr with bit 31 set
 to/from JS value: Poll with results "closed" (only visible to pollster until
 the poll is closed) have bit 31 set in the auxattr message header field.
 Reportedly (by Nightfox) this causes Error: can't convert 2147483648 to an
 integer when attempting to use this message in JS. I could'vd sworn I've
 solved this problem before, but maybe that was with JS-C v1.5 - anyway, first
 convert to double using JS_ValueToNumber and then typecast to uint32. We
 probably will need to do something similar with the time values in year 2038
 (holding my breath).

---
 src/sbbs3/js_msgbase.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/sbbs3/js_msgbase.c b/src/sbbs3/js_msgbase.c
index 4a7c915e57..7d1474c45d 100644
--- a/src/sbbs3/js_msgbase.c
+++ b/src/sbbs3/js_msgbase.c
@@ -58,6 +58,16 @@ typedef struct
 
 static const char* getprivate_failure = "line %d %s %s JS_GetPrivate failed";
 
+JSBool JS_ValueToUint32(JSContext *cx, jsval v, uint32 *ip)
+{
+	jsdouble d;
+
+	if(!JS_ValueToNumber(cx, v, &d))
+		return JS_FALSE;
+	*ip = (uint32)d;
+	return JS_TRUE;
+}
+
 /* Destructor */
 
 static void js_finalize_msgbase(JSContext *cx, JSObject *obj)
@@ -747,7 +757,7 @@ static BOOL parse_header_object(JSContext* cx, private_t* p, JSObject* hdr, smbm
 			msg->idx.votes=msg->hdr.votes;
 	}
 	if(JS_GetProperty(cx, hdr, "auxattr", &val) && !JSVAL_NULL_OR_VOID(val)) {
-		if(!JS_ValueToInt32(cx,val,&i32))
+		if(!JS_ValueToUint32(cx,val,&i32))
 			goto err;
 		msg->hdr.auxattr=i32;
 	}
-- 
GitLab