Add potential buffer overrun check.
[icmp-dn.git] / src / idnlookup.c
index bab502d..0fd367f 100644 (file)
@@ -31,7 +31,9 @@
 #include <sys/types.h>
 #include <sys/poll.h>
 #include <sys/time.h>
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
 
 struct icmphdr {
     u_int8_t type;
@@ -76,6 +78,10 @@ void printdn(FILE *f, unsigned char *dnbuf, size_t size, int onlyfirst)
                fprintf(stderr, "domain name decompression not implemented, aborting\n");
                exit(1);
            }
+           if((int)*p + (p - dnbuf) >= size) {
+               fprintf(stderr, "malformed domain name\n");
+               return;
+           }
            fprintf(f, "%.*s", (int)*p, p + 1);
            p += 1 + (int)*p;
            if(*p != 0)
@@ -277,6 +283,6 @@ int main(int argc, char **argv)
 
 /*
  * Local Variables:
- * compile-command: "gcc -Wall -g -o idnlookup idnlookup.c"
+ * compile-command: "make CFLAGS='-Wall -g'"
  * End:
  */