Skip to content

Commit

Permalink
hpclient.c msglen bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bg6cq committed Jun 23, 2012
1 parent 305f46b commit 9d410db
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions libhpfeeds/tools/hpclient.c
Expand Up @@ -44,19 +44,20 @@ u_char *read_msg(int s) {
u_char *buffer;
u_int32_t msglen;

if (read(s, &msglen, 4) == -1) {
if (read(s, &msglen, 4) != 4) {
perror("read()");
exit(EXIT_FAILURE);
}

if ((buffer = malloc(msglen)) == NULL) {
if ((buffer = malloc(ntohl(msglen))) == NULL) {
perror("malloc()");
exit(EXIT_FAILURE);
}

*(u_int32_t *) buffer = msglen;
msglen = ntohl(msglen);

if (read(s, buffer + 4, msglen - 4) == -1) {
if (read(s, buffer + 4, msglen - 4) != (msglen - 4)) {
perror("read()");
exit(EXIT_FAILURE);
}
Expand Down

0 comments on commit 9d410db

Please sign in to comment.