Permalink
Browse files

hpclient.c msglen bug

  • Loading branch information...
1 parent 305f46b commit 9d410dbb7d460aba9b899b6fa7e5f043da6be45d @bg6cq committed Jun 23, 2012
Showing with 4 additions and 3 deletions.
  1. +4 −3 libhpfeeds/tools/hpclient.c
@@ -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);
}

0 comments on commit 9d410db

Please sign in to comment.