fix copyright and condition notice for new sccs include
[unix-history] / usr / src / lib / libc / net / res_comp.c
index 3eb75d6..155dfab 100644 (file)
@@ -3,21 +3,27 @@
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
- * provided that this notice is preserved and that due credit is given
- * to the University of California at Berkeley. The name of the University
- * may not be used to endorse or promote products derived from this
- * software without specific prior written permission. This software
- * is provided ``as is'' without express or implied warranty.
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)res_comp.c 6.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)res_comp.c 6.16 (Berkeley) %G%";
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
 #include <stdio.h>
 #include <arpa/nameser.h>
 
 #endif /* LIBC_SCCS and not lint */
 
 #include <sys/types.h>
 #include <stdio.h>
 #include <arpa/nameser.h>
 
+static dn_find();
 
 /*
  * Expand compressed domain name 'comp_dn' to full domain name.
 
 /*
  * Expand compressed domain name 'comp_dn' to full domain name.
@@ -37,7 +43,7 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length)
 
        dn = exp_dn;
        cp = comp_dn;
 
        dn = exp_dn;
        cp = comp_dn;
-       eom = exp_dn + length - 1;
+       eom = exp_dn + length;
        /*
         * fetch next label in domain name
         */
        /*
         * fetch next label in domain name
         */
@@ -152,8 +158,11 @@ dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
                                if ((c = *dn++) == '\0')
                                        break;
                        }
                                if ((c = *dn++) == '\0')
                                        break;
                        }
-                       if (cp >= eob)
+                       if (cp >= eob) {
+                               if (msg != NULL)
+                                       *lpp = NULL;
                                return (-1);
                                return (-1);
+                       }
                        *cp++ = c;
                } while ((c = *dn++) != '\0');
                /* catch trailing '.'s but not '..' */
                        *cp++ = c;
                } while ((c = *dn++) != '\0');
                /* catch trailing '.'s but not '..' */
@@ -161,12 +170,18 @@ dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
                        cp--;
                        break;
                }
                        cp--;
                        break;
                }
-               if (l <= 0 || l > MAXLABEL)
+               if (l <= 0 || l > MAXLABEL) {
+                       if (msg != NULL)
+                               *lpp = NULL;
                        return (-1);
                        return (-1);
+               }
                *sp = l;
        }
                *sp = l;
        }
-       if (cp >= eob)
+       if (cp >= eob) {
+               if (msg != NULL)
+                       *lpp = NULL;
                return (-1);
                return (-1);
+       }
        *cp++ = '\0';
        return (cp - comp_dn);
 }
        *cp++ = '\0';
        return (cp - comp_dn);
 }
@@ -224,6 +239,8 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr)
                        switch (n & INDIR_MASK) {
                        case 0:         /* normal case, n == len */
                                while (--n >= 0) {
                        switch (n & INDIR_MASK) {
                        case 0:         /* normal case, n == len */
                                while (--n >= 0) {
+                                       if (*dn == '.')
+                                               goto next;
                                        if (*dn == '\\')
                                                dn++;
                                        if (*dn++ != *cp++)
                                        if (*dn == '\\')
                                                dn++;
                                        if (*dn++ != *cp++)