0001-game-Remove-check-for-malformed-IP-in-userinfo.patch

lefo, 31.03.2019 11:02

Download (2.88 KB)

View differences:

src/game/g_client.c
1419 1419
}
1420 1420

  
1421 1421
/**
1422
 * @brief GetParsedIP
1423
 * @param[in] ipadd
1424
 * @return
1425
 *
1426
 * @todo FIXME: IP6
1427
 *
1428
 * @note Courtesy of Dens
1429
 */
1430
const char *GetParsedIP(const char *ipadd)
1431
{
1432
	// code by Dan Pop, http://bytes.com/forum/thread212174.html
1433
	unsigned      b1, b2, b3, b4, port = 0;
1434
	unsigned char c;
1435
	int           rc;
1436
	static char   ipge[20];
1437

  
1438
	if (!Q_strncmp(ipadd, "localhost", 9))
1439
	{
1440
		return "localhost";
1441
	}
1442

  
1443
	rc = sscanf(ipadd, "%3u.%3u.%3u.%3u:%u%c", &b1, &b2, &b3, &b4, &port, &c);
1444
	if (rc < 4 || rc > 5)
1445
	{
1446
		return NULL;
1447
	}
1448
	if ((b1 | b2 | b3 | b4) > 255 || port > 65535)
1449
	{
1450
		return NULL;
1451
	}
1452
	if (strspn(ipadd, "0123456789.:") < strlen(ipadd))
1453
	{
1454
		return NULL;
1455
	}
1456

  
1457
	Com_sprintf(ipge, sizeof(ipge), "%u.%u.%u.%u", b1, b2, b3, b4);
1458
	return ipge;
1459
}
1460

  
1461
/**
1462 1422
 * @brief Based on userinfocheck.lua and combinedfixes.lua
1463 1423
 * @param clientNum - unused
1464 1424
 * @param[in] userinfo
1465 1425
 * @return
1466
 *
1467
 * @note FIXME: IP6
1468 1426
 */
1469 1427
char *CheckUserinfo(int clientNum, char *userinfo)
1470 1428
{
......
1530 1488
	{
1531 1489
		return "Too many IP fields in userinfo.";
1532 1490
	}
1533
	else
1534
	{
1535
		if (GetParsedIP(Info_ValueForKey(userinfo, "ip")) == NULL)
1536
		{
1537
			return "Malformed IP in userinfo.";
1538
		}
1539
	}
1540 1491
	count = 0;
1541 1492

  
1542 1493
	if (length > 9)
1543
-