value = g_strdup(g_strchomp(tmp));
if (strcmp(clamd_tokens[0], token) == 0) {
/* UNIX socket */
- Socket = (Clamd_Socket *) malloc(sizeof(Clamd_Socket *));
+ Socket = (Clamd_Socket *) malloc(sizeof(Clamd_Socket));
if (Socket) {
Socket->socket.host = NULL;
Socket->socket.port = -1;
else if (strcmp(clamd_tokens[1], token) == 0) {
/* INET socket */
if (! Socket) {
- Socket = (Clamd_Socket *) malloc(sizeof(Clamd_Socket *));
+ Socket = (Clamd_Socket *) malloc(sizeof(Clamd_Socket));
if (Socket) {
Socket->socket.path = NULL;
Socket->socket.port = -1;
memset(buf, '\0', sizeof(buf));
while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
buf[n_read] = '\0';
- if (buf[strlen(buf) - 1] == '\n')
- buf[strlen(buf) - 1] = '\0';
+ if (buf[n_read - 1] == '\n')
+ buf[n_read - 1] = '\0';
debug_print("Ping result: %s\n", buf);
if (strcmp("PONG", buf) == 0)
connect = TRUE;
return NO_CONNECTION;
}
memset(buf, '\0', sizeof(buf));
- while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
- buf[n_read] = '\0';
- if (buf[strlen(buf) - 1] == '\n')
- buf[strlen(buf) - 1] = '\0';
+ while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
+ buf[n_read] = '\0';
+ if (buf[n_read - 1] == '\n')
+ buf[n_read - 1] = '\0';
debug_print("Version: %s\n", buf);
}
close(sock);
return NO_CONNECTION;
}
- while ((count = read(fd, (void *) buf, sizeof(buf))) > 0) {
- buf[sizeof(buf) - 1] = '\0';
- if (buf[strlen(buf) - 1] == '\n')
- buf[strlen(buf) - 1] = '\0';
- debug_print("read: %ld bytes\n", count);
+ while ((count = read(fd, (void *) buf, BUFSIZ - 1)) > 0) {
+ buf[count] = '\0';
+ if (buf[count - 1] == '\n')
+ buf[count - 1] = '\0';
debug_print("chunk size: %ld\n", count);
chunk = htonl(count);
*res = g_strconcat("ERROR -> ", _("Socket write error"), NULL);
return SCAN_ERROR;
}
- memset(buf, '\0', sizeof(buf));
+ memset(buf, '\0', BUFSIZ - 1);
}
if (count == -1) {
close(fd);
*res = g_strconcat("ERROR -> ", _("Socket read error"), NULL);
return SCAN_ERROR;
}
+ (*res)[n_read] = '\0';
debug_print("received: %s\n", *res);
return OK;
}
debug_print("copy to buf: %s\n", tmp);
memcpy(&buf, tmp, BUFSIZ);
g_free(tmp);
+ debug_print("response: %s\n", buf);
}
else {
command = g_strconcat(scan, " ", path, "\n", NULL);
}
g_free(command);
memset(buf, '\0', sizeof(buf));
+ /* shouldn't we read only once here? we're checking the last response line anyway */
while ((n_read = read(sock, buf, BUFSIZ - 1)) > 0) {
buf[n_read] = '\0';
- if (buf[strlen(buf) - 1] == '\n')
- buf[strlen(buf) - 1] = '\0';
+ if (buf[n_read - 1] == '\n')
+ buf[n_read - 1] = '\0';
+ debug_print("response: %s\n", buf);
+ }
+ if (n_read == 0) {
+ buf[n_read] = '\0';
+ debug_print("response: %s\n", buf);
}
}
- debug_print("response: %s\n", buf);
if (strstr(buf, "ERROR")) {
stat = SCAN_ERROR;
result->msg = g_strdup(buf);