From 8a63c9d9cc55b25071bd6d168e1245c28b8dd5c8 Mon Sep 17 00:00:00 2001 From: divverent Date: Wed, 20 Jul 2016 13:13:40 +0000 Subject: [PATCH] Stop using bytes >= 128 in format strings. They break on Android. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12268 d7cf8633-e32d-0410-b094-e92efae38249 --- host_cmd.c | 6 ++++-- netconn.c | 23 +++++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/host_cmd.c b/host_cmd.c index 1f4048fd..a62b0832 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -2615,7 +2615,6 @@ static void Host_Rcon_f (void) // credit: taken from QuakeWorld int i, n; const char *e; lhnetsocket_t *mysocket; - char vabuf[1024]; if (Cmd_Argc() == 1) { @@ -2684,7 +2683,10 @@ static void Host_Rcon_f (void) // credit: taken from QuakeWorld } else { - NetConn_WriteString(mysocket, va(vabuf, sizeof(vabuf), "\377\377\377\377rcon %.*s %s", n, rcon_password.string, Cmd_Args()), &cls.rcon_address); + char buf[1500]; + memcpy(buf, "\377\377\377\377", 4); + dpsnprintf(buf+4, sizeof(buf)-4, "rcon %.*s %s", n, rcon_password.string, Cmd_Args()); + NetConn_WriteString(mysocket, buf, &cls.rcon_address); } } } diff --git a/netconn.c b/netconn.c index 0d9f69e4..72d33263 100755 --- a/netconn.c +++ b/netconn.c @@ -1798,7 +1798,6 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat char ipstring[32]; const char *s; #endif - char vabuf[1024]; // quakeworld ingame packet fromserver = cls.netcon && mysocket == cls.netcon->mysocket && !LHNETADDRESS_Compare(&cls.netcon->peeraddress, peeraddress); @@ -1917,7 +1916,9 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat // update the server IP in the userinfo (QW servers expect this, and it is used by the reconnect command) InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "*ip", addressstring2); // TODO: add userinfo stuff here instead of using NQ commands? - NetConn_WriteString(mysocket, va(vabuf, sizeof(vabuf), "\377\377\377\377connect\\protocol\\darkplaces 3\\protocols\\%s%s\\challenge\\%s", protocolnames, cls.connect_userinfo, string + 10), peeraddress); + memcpy(senddata, "\377\377\377\377", 4); + dpsnprintf(senddata+4, sizeof(senddata)-4, "connect\\protocol\\darkplaces 3\\protocols\\%s%s\\challenge\\%s", protocolnames, cls.connect_userinfo, string + 10); + NetConn_WriteString(mysocket, senddata, peeraddress); return true; } if (length == 6 && !memcmp(string, "accept", 6) && cls.connect_trying) @@ -2121,7 +2122,9 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat cls.qw_qport = qport.integer; // update the server IP in the userinfo (QW servers expect this, and it is used by the reconnect command) InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "*ip", addressstring2); - NetConn_WriteString(mysocket, va(vabuf, sizeof(vabuf), "\377\377\377\377connect %i %i %i \"%s%s\"\n", 28, cls.qw_qport, atoi(string + 1), cls.userinfo, cls.connect_userinfo), peeraddress); + memcpy(senddata, "\377\377\377\377", 4); + dpsnprintf(senddata+4, sizeof(senddata)-4, "connect %i %i %i \"%s%s\"\n", 28, cls.qw_qport, atoi(string + 1), cls.userinfo, cls.connect_userinfo); + NetConn_WriteString(mysocket, senddata, peeraddress); return true; } if (length >= 1 && string[0] == 'j' && cls.connect_trying) @@ -2929,7 +2932,6 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat char senddata[NET_HEADERSIZE+NET_MAXMESSAGE+CRYPTO_HEADERSIZE]; size_t sendlength, response_len; char infostringvalue[MAX_INPUTLINE]; - char vabuf[1024]; if (!sv.active) return false; @@ -3016,7 +3018,8 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat } challenge[i].time = realtime; // send the challenge - dpsnprintf(response, sizeof(response), "\377\377\377\377challenge %s", challenge[i].string); + memcpy(response, "\377\377\377\377", 4); + dpsnprintf(response+4, sizeof(response)-4, "challenge %s", challenge[i].string); response_len = strlen(response) + 1; Crypto_ServerAppendToChallenge(string, length, response, &response_len, sizeof(response)); NetConn_Write(mysocket, response, (int)response_len, peeraddress); @@ -3067,7 +3070,9 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat { if (developer_extra.integer) Con_Printf("Datagram_ParseConnectionless: sending \"reject %s\" to %s.\n", sv_public_rejectreason.string, addressstring2); - NetConn_WriteString(mysocket, va(vabuf, sizeof(vabuf), "\377\377\377\377reject %s", sv_public_rejectreason.string), peeraddress); + memcpy(response, "\377\377\377\377", 4); + dpsnprintf(response+4, sizeof(response)-4, "reject %s", sv_public_rejectreason.string); + NetConn_WriteString(mysocket, response, peeraddress); return true; } @@ -3320,7 +3325,8 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat // save space for the header, filled in later MSG_WriteLong(&sv_message, 0); MSG_WriteByte(&sv_message, CCREP_REJECT); - MSG_WriteString(&sv_message, va(vabuf, sizeof(vabuf), "%s\n", sv_public_rejectreason.string)); + MSG_WriteUnterminatedString(&sv_message, sv_public_rejectreason.string); + MSG_WriteString(&sv_message, "\n"); StoreBigLong(sv_message.data, NETFLAG_CTL | (sv_message.cursize & NETFLAG_LENGTH_MASK)); NetConn_Write(mysocket, sv_message.data, sv_message.cursize, peeraddress); SZ_Clear(&sv_message); @@ -3655,7 +3661,8 @@ void NetConn_QueryMasters(qboolean querydp, qboolean queryqw) cmdname = "getservers"; extraoptions = ""; } - dpsnprintf(request, sizeof(request), "\377\377\377\377%s %s %u empty full%s", cmdname, gamenetworkfiltername, NET_PROTOCOL_VERSION, extraoptions); + memcpy(request, "\377\377\377\377", 4); + dpsnprintf(request+4, sizeof(request)-4, "%s %s %u empty full%s", cmdname, gamenetworkfiltername, NET_PROTOCOL_VERSION, extraoptions); // search internet for (masternum = 0;sv_masters[masternum].name;masternum++) -- 2.39.2