check for overflow in getrawlist()
[unix-history] / usr / src / usr.bin / mail / vars.c
index 63c7a96..3d82f73 100644 (file)
@@ -1,4 +1,12 @@
-#
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)vars.c      5.2 (Berkeley) %G%";
+#endif not lint
 
 #include "rcv.h"
 
 
 #include "rcv.h"
 
@@ -8,8 +16,6 @@
  * Variable handling stuff.
  */
 
  * Variable handling stuff.
  */
 
-static char *SccsId = "@(#)vars.c      2.1 %G%";
-
 /*
  * Assign a value to a variable.
  */
 /*
  * Assign a value to a variable.
  */
@@ -59,7 +65,8 @@ vcopy(str)
 
        if (equal(str, ""))
                return("");
 
        if (equal(str, ""))
                return("");
-       top = calloc(strlen(str)+1, 1);
+       if ((top = calloc(strlen(str)+1, 1)) == NULL)
+               panic ("Out of memory");
        cp = top;
        cp2 = str;
        while (*cp++ = *cp2++)
        cp = top;
        cp2 = str;
        while (*cp++ = *cp2++)
@@ -148,11 +155,14 @@ printgroup(name)
 hash(name)
        char name[];
 {
 hash(name)
        char name[];
 {
-       register int h;
+       register unsigned h;
        register char *cp;
 
        for (cp = name, h = 0; *cp; h = (h << 2) + *cp++)
                ;
        register char *cp;
 
        for (cp = name, h = 0; *cp; h = (h << 2) + *cp++)
                ;
-       h &= ~0100000;
+       if (h < 0)
+               h = -h;
+       if (h < 0)
+               h = 0;
        return(h % HSHSIZE);
 }
        return(h % HSHSIZE);
 }