mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-11 07:17:58 +00:00
Use a more robust mechanism to obtain a \n terminated string over a socket.
This commit is contained in:
parent
2de951518e
commit
fa4c9bf60f
17
util.c
17
util.c
@ -895,8 +895,8 @@ static bool sock_full(SOCKETTYPE sock, bool wait)
|
|||||||
* from the socket and returns that as a malloced char */
|
* from the socket and returns that as a malloced char */
|
||||||
char *recv_line(SOCKETTYPE sock)
|
char *recv_line(SOCKETTYPE sock)
|
||||||
{
|
{
|
||||||
char *sret = NULL, *s;
|
char *sret = NULL, *s, c;
|
||||||
ssize_t len;
|
ssize_t offset = 0;
|
||||||
|
|
||||||
s = alloca(RECVSIZE);
|
s = alloca(RECVSIZE);
|
||||||
if (SOCKETFAIL(recv(sock, s, RECVSIZE, MSG_PEEK))) {
|
if (SOCKETFAIL(recv(sock, s, RECVSIZE, MSG_PEEK))) {
|
||||||
@ -908,12 +908,13 @@ char *recv_line(SOCKETTYPE sock)
|
|||||||
applog(LOG_DEBUG, "Failed to parse a \\n terminated string in recv_line");
|
applog(LOG_DEBUG, "Failed to parse a \\n terminated string in recv_line");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
len = strlen(sret) + 1;
|
|
||||||
/* We know how much data is in the buffer so this read should not fail */
|
do {
|
||||||
if (SOCKETFAIL(recv(sock, s, len, 0)))
|
read(sock, &c, 1);
|
||||||
goto out;
|
memcpy(s + offset++, &c, 1);
|
||||||
if (s)
|
} while (strncmp(&c, "\n", 1));
|
||||||
sret = strdup(strtok(s, "\n"));
|
sret = strdup(s);
|
||||||
|
strcpy(sret + offset - 1, "\0");
|
||||||
out:
|
out:
|
||||||
if (!sret)
|
if (!sret)
|
||||||
clear_sock(sock);
|
clear_sock(sock);
|
||||||
|
Loading…
Reference in New Issue
Block a user