Skip to content

Commit 62165f7

Browse files
committed
Merge remote-tracking branch 'remotes/makaopior/feature/encoding-fix'
# Conflicts: # WhoisClient.NET/WhoisClient.cs
2 parents 16566b2 + f641e07 commit 62165f7

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
v.5.3.0
22
- Fixed potential infinite loop in socket reading method
3+
- Fixed potential response string corruption for registries which use multi-byte encoding
34

45
v.5.2.0
56
- Moved TcpClient creation to separate class, enabling usage in special cases like flowing traffic through SOCKS proxy

WhoisClient.NET/WhoisClient.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ private static string RawQuery(string query, EndPoint server, IQueryOptions opti
298298
return string.Empty;
299299
}
300300

301-
var res = new StringBuilder();
301+
var responseBytes = new List<byte>(4096);
302302
try
303303
{
304304
using (var s = tcpClient.GetStream())
@@ -317,12 +317,12 @@ private static string RawQuery(string query, EndPoint server, IQueryOptions opti
317317
do
318318
{
319319
cbRead = s.Read(readBuff, 0, readBuff.Length);
320-
res.Append(options.Encoding.GetString(readBuff, 0, cbRead));
320+
responseBytes.AddRange(readBuff.Take(cbRead));
321321
if (cbRead > 0)
322322
Thread.Sleep(100);
323323
} while (cbRead > 0);
324324

325-
return res.ToString();
325+
return options.Encoding.GetString(responseBytes.ToArray());
326326
}
327327
}
328328
catch
@@ -333,7 +333,7 @@ private static string RawQuery(string query, EndPoint server, IQueryOptions opti
333333
if (options.RethrowExceptions)
334334
throw;
335335

336-
return res.ToString();
336+
return options.Encoding.GetString(responseBytes.ToArray());
337337
}
338338
finally
339339
{
@@ -405,7 +405,7 @@ private static async Task<string> RawQueryAsync(string query, EndPoint server, I
405405
return string.Empty;
406406
}
407407

408-
var res = new StringBuilder();
408+
var responseBytes = new List<byte>(4096);
409409
try
410410
{
411411
using (var s = tcpClient.GetStream())
@@ -424,12 +424,12 @@ private static async Task<string> RawQueryAsync(string query, EndPoint server, I
424424
do
425425
{
426426
cbRead = await s.ReadAsync(readBuff, 0, buffSize, token).ConfigureAwait(false);
427-
res.Append(options.Encoding.GetString(readBuff, 0, cbRead));
427+
responseBytes.AddRange(readBuff.Take(cbRead));
428428
if (cbRead > 0)
429429
await Task.Delay(100, token).ConfigureAwait(false);
430430
} while (cbRead > 0);
431431

432-
return res.ToString();
432+
return options.Encoding.GetString(responseBytes.ToArray());
433433
}
434434
}
435435
catch (Exception)
@@ -440,7 +440,7 @@ private static async Task<string> RawQueryAsync(string query, EndPoint server, I
440440
if (options.RethrowExceptions)
441441
throw;
442442

443-
return res.ToString();
443+
return options.Encoding.GetString(responseBytes.ToArray());
444444
}
445445
finally
446446
{

0 commit comments

Comments
 (0)