[hobbit] Here are possible patches affecting hobbitfetch
Steinar M. Skúlason
steinarms at gmail.com
Thu Feb 18 14:50:46 CET 2010
Thanks for your effort Cade, I applied your patches on latest from svn -
version 4.3.0
and it has been working for 3days now.
Best Regards,
Steinar M.
On Mon, Feb 15, 2010 at 4:21 PM, Cade Robinson <cade.robinson at gmail.com>wrote:
>
>
> I have been having some issues with hobbitfetch and have modified a few
> files to fix them. At least my definition of fixed in that hobbitfetch
> now works - but the way they are fixed may not be right.
>
> include/libbbgen.h
> Change IP_ADDR_STRLEN from 16 to 22.
> The reason is that I was getting reports from IP:port and that is 22
> chars with the trailing NULL. At 16 I was getting multi-source reports
> and the the host shown in "Status message received from" was truncated
> otherwise.
>
> hobbitd/hobbitd.c
> Again related to the above - took out he %16s because my host could be
> 22 chars.
>
> hobbitd/hobbitfetch.c
> Lowered res from 100 to 25 - same as above so it could really be 22. Not
> much of a change but save a bit of mem.
>
> Change the read to read two less bytes than sizeof(buf) and set buf[n-1]
> to NULL. This is in case 8192 bytes are sent/read. Since buf is 8192
> elements long the last element is 8191 not 8192 so buf[n]=\0; when 8192
> bytes are read causes a segfault. I think the same should be done in
> msgcache.c as well but I haven't seen anything over 100 bytes be sent to
> msgcache.
>
>
>
>
> Here are the patches:
> Index: include/libbbgen.h
> ===================================================================
> --- include/libbbgen.h (revision 6223)
> +++ include/libbbgen.h (working copy)
> @@ -27,7 +27,7 @@
> #define STRBUF(buf) (buf->s)
> #define STRBUFLEN(buf) (buf->used)
>
> -#define IP_ADDR_STRLEN 16
> +#define IP_ADDR_STRLEN 22
>
> #include "version.h"
> #include "config.h"
> Index: hobbitd/hobbitd.c
> ===================================================================
> --- hobbitd/hobbitd.c (revision 6223)
> +++ hobbitd/hobbitd.c (working copy)
> @@ -2789,7 +2789,7 @@
> /* Pick out the real sender of this message */
> msgfrom = strstr(currmsg, "\nStatus message
> received from ");
> if (msgfrom) {
> - sscanf(msgfrom, "\nStatus message
> received from %16s\n", sender);
> + sscanf(msgfrom, "\nStatus message
> received from %s\n", sender);
> *msgfrom = '\0';
> }
>
> @@ -2866,7 +2866,7 @@
> else if (strncmp(msg->buf, "status", 6) == 0) {
> msgfrom = strstr(msg->buf, "\nStatus message received
> from ");
> if (msgfrom) {
> - sscanf(msgfrom, "\nStatus message received from
> %16s\n", sender);
> + sscanf(msgfrom, "\nStatus message received from
> %s\n", sender);
> *msgfrom = '\0';
> }
>
> @@ -2907,7 +2907,7 @@
>
> msgfrom = strstr(msg->buf, "\nStatus message received
> from ");
> if (msgfrom) {
> - sscanf(msgfrom, "\nStatus message received from
> %16s\n", sender);
> + sscanf(msgfrom, "\nStatus message received from
> %s\n", sender);
> *msgfrom = '\0';
> }
>
> @@ -3668,7 +3668,7 @@
> if (msgfrom) {
> char *ipline = strstr(msgfrom, "\nClientIP:");
> if (ipline) {
> - sscanf(ipline, "\nClientIP:%16s\n",
> sender);
> + sscanf(ipline, "\nClientIP:%s\n",
> sender);
> }
> }
>
> Index: hobbitd/hobbitfetch.c
> ===================================================================
> --- hobbitd/hobbitfetch.c (revision 6223)
> +++ hobbitd/hobbitfetch.c (working copy)
> @@ -100,7 +100,7 @@
>
> char *addrstring(struct sockaddr_in *addr)
> {
> - static char res[100];
> + static char res[25];
>
> sprintf(res, "%s:%d", inet_ntoa(addr->sin_addr),
> ntohs(addr->sin_port));
> return res;
> @@ -346,7 +346,7 @@
> char buf[8192];
>
> /* Read data from a peer connection (client or server) */
> - n = read(conn->sockfd, buf, sizeof(buf));
> + n = read(conn->sockfd, buf, sizeof(buf)-2);
> if (n == -1) {
> /* Read failure */
> time_t now = gettimer();
> @@ -361,7 +361,7 @@
> /* Save the data */
> dbgprintf("Got %d bytes of data from %s (req %lu)\n",
> n, addrstring(&conn->caddr), conn->seq);
> - buf[n] = '\0';
> + buf[n+1] = '\0';
> addtobuffer(conn->msgbuf, buf);
> }
> else if (n == 0) {
>
>
>
> To unsubscribe from the hobbit list, send an e-mail to
> hobbit-unsubscribe at hswn.dk
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20100218/3c0d146e/attachment.html>
More information about the Xymon
mailing list