$OpenBSD: patch-src_do_c,v 1.2 2004/08/08 14:02:11 sturm Exp $
--- src/do.c.orig	Wed Jun  9 08:50:19 2004
+++ src/do.c	Mon Aug  2 13:35:37 2004
@@ -76,9 +76,9 @@ for (ip = VMOUNTLIST; ip != NULL; ip=ip-
          continue;
          }
 
-      strcpy(VBUFF,ip->name);
+      (void)strlcpy(VBUFF,ip->name,sizeof(VBUFF));
       AddSlash(VBUFF);
-      strcat(VBUFF,dirp->d_name);
+      (void)strlcat(VBUFF,dirp->d_name,sizeof(VBUFF));
 
       if (IsHomeDir(VBUFF))
          {
@@ -230,13 +230,13 @@ do
       case crayos:
                     if (buf1[0] == '/')
                        {
-                       strcpy(host,VDEFAULTBINSERVER.name);
-                       strcpy(mounton,buf3);
+                       (void)strlcpy(host,VDEFAULTBINSERVER.name,sizeof(host));
+                       (void)strlcpy(mounton,buf3,sizeof(mounton));
                        }
                     else
                        {
                        sscanf(buf1,"%[^:]",host);
-                       strcpy(mounton,buf3);
+                       (void)strlcpy(mounton,buf3,sizeof(mounton));
                        }
 
                     break;
@@ -246,13 +246,13 @@ do
       case hp:      
                     if (buf3[0] == '/')
                        {
-                       strcpy(host,VDEFAULTBINSERVER.name);
-                       strcpy(mounton,buf1);
+                       (void)strlcpy(host,VDEFAULTBINSERVER.name,sizeof(host));
+                       (void)strlcpy(mounton,buf1,sizeof(mounton));
                        }
                     else
                        {
                        sscanf(buf3,"%[^:]",host);
-                       strcpy(mounton,buf1);
+                       (void)strlcpy(mounton,buf1,sizeof(mounton));
                        }
 
                     break;
@@ -261,18 +261,18 @@ do
 
                     if (buf1[0] == '/')
                        {
-                       strcpy(host,VDEFAULTBINSERVER.name);
-                       strcpy(mounton,buf2);
+                       (void)strlcpy(host,VDEFAULTBINSERVER.name,sizeof(host));
+                       (void)strlcpy(mounton,buf2,sizeof(host));
                        }
                     else
                        {
-                       strcpy(host,buf1);
-                       strcpy(mounton,buf3);
+                       (void)strlcpy(host,buf1,sizeof(host));
+                       (void)strlcpy(mounton,buf3,sizeof(mounton));
                        }
                     break;
 
-      case cfnt:    strcpy(mounton,buf2);
-                    strcpy(host,buf1);
+      case cfnt:    (void)strlcpy(mounton,buf2,sizeof(mounton));
+                    (void)strlcpy(host,buf1,sizeof(host));
                     break;
       case unused1:
       case unused2:
@@ -344,12 +344,12 @@ for (ptr = VMAKEPATH; ptr != NULL; ptr=p
             pathbuff[0]='\0';
             basename[0]='\0';     
             
-            strcpy(pathbuff,ip2->name);
+            (void)strlcpy(pathbuff,ip2->name,sizeof(pathbuff));
             AddSlash(pathbuff);
-            strcat(pathbuff,ip1->name);
+            (void)strlcat(pathbuff,ip1->name,sizeof(pathbuff));
             AddSlash(pathbuff);
-            strcat(pathbuff,"*/");   
-            strcat(pathbuff,ptr->path+5);
+            (void)strlcat(pathbuff,"*/",sizeof(pathbuff));
+            (void)strlcat(pathbuff,ptr->path+5,sizeof(pathbuff));
             
             ExpandWildCardsAndDo(pathbuff,basename,DirectoriesWrapper,ptr);  
             }
@@ -633,7 +633,7 @@ if (strcmp(VDEFAULTBINSERVER.name,mailho
    return;
    }
 
-snprintf(lmailpath,CF_BUFSIZE,"%s:%s",mailhost,VMAILDIR[VSYSTEMHARDCLASS]);
+snprintf(lmailpath,CF_MAXVARSIZE,"%s:%s",mailhost,VMAILDIR[VSYSTEMHARDCLASS]);
 
 
 if (IsItemIn(VMOUNTED,lmailpath))                             /* Remote file system mounted on */
@@ -643,9 +643,9 @@ if (IsItemIn(VMOUNTED,lmailpath))       
    return;
    }
 
-strcpy(mailserver,VMAILDIR[VSYSTEMHARDCLASS]);
+(void)strlcpy(mailserver,VMAILDIR[VSYSTEMHARDCLASS],sizeof(mailserver));
 AddSlash(mailserver);
-strcat(mailserver,".");
+(void)strlcat(mailserver,".",sizeof(mailserver));
 
 MakeDirectoriesFor(mailserver,'n');                                  /* Check directory is in place */
 
@@ -713,9 +713,9 @@ if (always || (strncmp(VMAILSERVER,VFQNA
          continue;
          }
 
-      strcpy(VBUFF,spooldir);
+      (void)strlcpy(VBUFF,spooldir,sizeof(VBUFF));
       AddSlash(VBUFF);
-      strcat(VBUFF,dirp->d_name);
+      (void)strlcat(VBUFF,dirp->d_name,sizeof(VBUFF));
 
       if (stat(VBUFF,&statbuf) != -1)
          {
@@ -1190,9 +1190,9 @@ if (!IsPrivileged())                    
           }
        pathbuff[0]='\0';
        basename[0]='\0';
-       strcpy(pathbuff,ip2->name);
+       (void)strlcpy(pathbuff,ip2->name,sizeof(pathbuff));
        AddSlash(pathbuff);
-       strcat(pathbuff,ip1->name);
+       (void)strlcat(pathbuff,ip1->name,sizeof(pathbuff));
        
        ExpandWildCardsAndDo(pathbuff,basename,RecHomeTidyWrapper,NULL);
        }
@@ -1429,6 +1429,7 @@ void GetSetuidLog()
   struct Item *ip;
   FILE *fp;
   char *sp;
+  size_t buflen;
 
 if (!IsPrivileged())                     /* Ignore this if not root */
    {
@@ -1455,7 +1456,8 @@ else
          FatalError("GetSetuidList() couldn't allocate memory #1");
          }
 
-      if ((sp = malloc(strlen(VBUFF)+2)) == NULL)
+      buflen = strlen(VBUFF) + 2;
+      if ((sp = malloc(buflen)) == NULL)
          {
          perror("malloc");
          FatalError("GetSetuidList() couldn't allocate memory #2");
@@ -1472,7 +1474,7 @@ else
 
       Debug2("SETUID-LOG: %s\n",VBUFF);
 
-      strcpy(sp,VBUFF);
+      (void)strlcpy(sp,VBUFF,buflen);
       ip->name = sp;
       ip->next = NULL;
       filetop = ip;
@@ -1767,7 +1769,7 @@ for (dp = VDISABLELIST; dp != NULL; dp=d
                }
             else
                {
-               strcpy(path,workname);
+               (void)strlcpy(path,workname,sizeof(path));
                ChopLastNode(path);
                AddSlash(path);
                if (BufferOverflow(path,dp->destination))
@@ -1778,13 +1780,13 @@ for (dp = VDISABLELIST; dp != NULL; dp=d
                   ReleaseCurrentLock();
                   continue;
                   }
-               strcat(path,dp->destination);
+               (void)strlcat(path,dp->destination,sizeof(path));
                }
             }
          else
             {
-            strcpy(path,workname);
-            strcat(path,".cfdisabled");
+            (void)strlcpy(path,workname,sizeof(path));
+            (void)strlcat(path,".cfdisabled",sizeof(path));
             }
          
          snprintf(OUTPUT,CF_BUFSIZE*2,"Disabling/renaming file %s to %s\n",workname,path);
@@ -1912,15 +1914,15 @@ for (mp = VMOUNTABLES; mp != NULL; mp=mp
    
    Debug("Mount: checking %s\n",mp->filesystem);
 
-   strcpy(maketo,mountdir);
+   (void)strlcpy(maketo,mountdir,sizeof(maketo));
 
    if (maketo[strlen(maketo)-1] == '/')
       {
-      strcat(maketo,".");
+      (void)strlcat(maketo,".",sizeof(maketo));
       }
    else
       {
-      strcat(maketo,"/.");
+      (void)strlcat(maketo,"/.",sizeof(maketo));
       }
 
    if (strcmp(host,VDEFAULTBINSERVER.name) == 0) /* A host never mounts itself nfs */
@@ -1932,11 +1934,11 @@ for (mp = VMOUNTABLES; mp != NULL; mp=mp
    /* HvB: Bas van der Vlies */
    if ( mp->readonly ) 
       {
-      strcpy(mountmode, "ro");
+      (void)strlcpy(mountmode, "ro", sizeof(mountmode));
       }
    else
       {
-      strcpy(mountmode, "rw");
+      (void)strlcpy(mountmode, "rw", sizeof(mountmode));
       }
 
    if (IsHomeDir(mountdir))
@@ -2006,15 +2008,15 @@ for (mp = VMISCMOUNT; mp != NULL; mp=mp-
       mp->done = 'y';
       }
    
-   strcpy(maketo,mp->onto);
+   (void)strlcpy(maketo,mp->onto,sizeof(maketo));
 
    if (maketo[strlen(maketo)-1] == '/')
       {
-      strcat(maketo,".");
+      (void)strlcat(maketo,".",sizeof(maketo));
       }
    else
       {
-      strcat(maketo,"/.");
+      (void)strlcat(maketo,"/.",sizeof(maketo));
       }
 
    if (strcmp(host,VDEFAULTBINSERVER.name) == 0) /* A host never mounts itself nfs */
@@ -2168,8 +2170,8 @@ for (ptr=VUNMOUNT; ptr != NULL; ptr=ptr-
       {
       if (VSYSTEMHARDCLASS == aix)
          {
-         strcpy (VBUFF,fs);
-         strcat (VBUFF,":");
+         (void)strlcpy (VBUFF,fs,sizeof(VBUFF));
+         (void)strlcat (VBUFF,":",sizeof(VBUFF));
          
          item = LocateNextItemContaining(filelist,VBUFF);
          
@@ -2193,8 +2195,8 @@ for (ptr=VUNMOUNT; ptr != NULL; ptr=ptr-
          
          if (VSYSTEMHARDCLASS == ultrx)   /* ensure name is not just a substring */
             {
-            strcpy (VBUFF,ptr->name);
-            strcat (VBUFF,":");
+            (void)strlcpy (VBUFF,ptr->name,sizeof(VBUFF));
+            (void)strlcat (VBUFF,":",sizeof(VBUFF));
             DeleteItemContaining(&filelist,VBUFF);
             }
          else
@@ -2585,14 +2587,14 @@ for (ip = VTIMEZONE; ip != NULL; ip=ip->
 #ifdef NT
    
    tzset();
-   strcpy(tz,timezone());
+   (void)strlcpy(tz,timezone(),sizeof(tz));
    
 #else
 #ifndef AOS
 #ifndef SUN4
 
    tzset();
-   strcpy(tz,tzname[0]);
+   (void)strlcpy(tz,tzname[0],sizeof(tz));
 
 #else
 
@@ -2600,7 +2602,7 @@ for (ip = VTIMEZONE; ip != NULL; ip=ip->
       {
       printf("Couldn't read system clock\n\n");
       }
-   strcpy(tz,localtime(&tloc)->tm_zone);
+   (void)strlcpy(tz,localtime(&tloc)->tm_zone,sizeof(tz));
       
 #endif /* SUN4 */
 #endif /* AOS  */
@@ -2840,14 +2842,14 @@ if (S_ISDIR(statbuf.st_mode))
 
       filecount++;
 
-      strcpy(buff,name);
+      (void)strlcpy(buff,name,sizeof(buff));
 
       if (buff[strlen(buff)] != '/')
          {
-         strcat(buff,"/");
+         (void)strlcat(buff,"/",sizeof(buff));
          }
 
-      strcat(buff,dirp->d_name);
+      (void)strlcat(buff,dirp->d_name,sizeof(buff));
 
       if (lstat(buff,&localstat) == -1)
          {
@@ -2875,14 +2877,14 @@ if (S_ISDIR(statbuf.st_mode))
 
    if (sizeinbytes < SENSIBLEFSSIZE)
       {
-      snprintf(OUTPUT,CF_BUFSIZE*2,"File system %s is suspiciously small! (%d bytes)\n",name,sizeinbytes);
+      snprintf(OUTPUT,CF_BUFSIZE*2,"File system %s is suspiciously small! (%ld bytes)\n",name,sizeinbytes);
       CfLog(cferror,OUTPUT,"");
       return(false);
       }
 
    if (filecount < SENSIBLEFILECOUNT)
       {
-      snprintf(OUTPUT,CF_BUFSIZE*2,"Filesystem %s has only %d files/directories.\n",name,filecount);
+      snprintf(OUTPUT,CF_BUFSIZE*2,"Filesystem %s has only %ld files/directories.\n",name,filecount);
       CfLog(cferror,OUTPUT,"");
       return(false);
       }
@@ -2930,7 +2932,7 @@ for (dirp = readdir(dirh); dirp != NULL;
       continue;
       }
    
-   strcpy(pcwd,name);                                   /* Assemble pathname */
+   (void)strlcpy(pcwd,name,sizeof(pcwd));                                   /* Assemble pathname */
    AddSlash(pcwd);
 
    if (BufferOverflow(pcwd,dirp->d_name))
@@ -2939,7 +2941,7 @@ for (dirp = readdir(dirh); dirp != NULL;
       return true;
       }
 
-   strcat(pcwd,dirp->d_name);
+   (void)strlcat(pcwd,dirp->d_name,sizeof(pcwd));
 
    if (lstat(dirp->d_name,&statbuf) == -1)
       {
@@ -2983,9 +2985,9 @@ void InstallMountedItem(char *host,char 
 
 { char buf[CF_BUFSIZE];
  
-strcpy (buf,host);
-strcat (buf,":");
-strcat (buf,mountdir);
+(void)strlcpy (buf,host,sizeof(buf));
+(void)strlcat (buf,":",sizeof(buf));
+(void)strlcat (buf,mountdir,sizeof(buf));
  
 if (IsItemIn(VMOUNTED,buf))
    {
@@ -3087,16 +3089,16 @@ if (MatchStringInFstab(mountpt))
       CfLog(cfinform,"---------------------------------------------------","");
       
       /* delete current fstab entry and unmount if necessary */
-      snprintf(mountspec,CF_BUFSIZE,".+:%s",mountpt);
+      snprintf(mountspec,MAXPATHLEN,".+:%s",mountpt);
       mntentry = LocateItemContainingRegExp(VMOUNTED,mountspec);
       if (mntentry)
          {
          sscanf(mntentry->name,"%[^:]:",mountspec);  /* extract current host */
-         strcat(mountspec,":");
-         strcat(mountspec,mountpt);
+         (void)strlcat(mountspec,":",sizeof(mountspec));
+         (void)strlcat(mountspec,mountpt,sizeof(mountspec));
          }
       else  /* mountpt isn't mounted, so Unmount can use dummy host name */
-          snprintf(mountspec,CF_BUFSIZE,"host:%s",mountpt);
+          snprintf(mountspec,MAXPATHLEN,"host:%s",mountpt);
       
       /* delete current fstab entry and unmount if necessary (don't rmdir) */
       cleaner.name        = mountspec;
@@ -3245,14 +3247,14 @@ for (ip1 = VHOMEPATLIST; ip1 != NULL; ip
          }
       pathbuff[0]='\0';
       basename[0]='\0';
-      strcpy(pathbuff,ip2->name);
+      (void)strlcpy(pathbuff,ip2->name,sizeof(pathbuff));
       AddSlash(pathbuff);
-      strcat(pathbuff,ip1->name);
+      (void)strlcat(pathbuff,ip1->name,sizeof(pathbuff));
       AddSlash(pathbuff);
       
       if (strncmp(ptr->path,"home/",5) == 0) /* home/subdir */
          {
-         strcat(pathbuff,"*");
+         (void)strlcat(pathbuff,"*",sizeof(pathbuff));
          AddSlash(pathbuff);
          
          if (*(ptr->path+4) != '/')
@@ -3263,7 +3265,7 @@ for (ip1 = VHOMEPATLIST; ip1 != NULL; ip
             }
          else
             {
-            strcat(pathbuff,ptr->path+5);
+            (void)strlcat(pathbuff,ptr->path+5,sizeof(pathbuff));
             }
          
          ExpandWildCardsAndDo(pathbuff,basename,RecFileCheck,ptr);
@@ -3294,11 +3296,11 @@ void EditItemsInResolvConf(struct Item *
     
     if (isdigit((int)*(work)))
        {
-       snprintf(buf,CF_BUFSIZE,"nameserver %s",work);
+       (void)snprintf(buf,CF_MAXVARSIZE,"nameserver %s",work);
        }
     else
        {
-       strncpy(buf,work,CF_MAXVARSIZE-1);
+       (void)strlcpy(buf,work,sizeof(buf));
        }
     
     DeleteItemMatching(list,buf); /* del+prep = move to head of list */
@@ -3370,7 +3372,7 @@ if (strlen(extract) == 0)
    {
    if (isdir)
       {
-      strcat(buffer,"/");
+      (void)strlcat(buffer,"/",CF_EXPANDSIZE);
       }
    (*function)(buffer,argptr);
    return;
@@ -3378,20 +3380,20 @@ if (strlen(extract) == 0)
  
 if (! IsWildCard(extract))
    {
-   strcat(buffer,"/");
+   (void)strlcat(buffer,"/",CF_EXPANDSIZE);
    if (BufferOverflow(buffer,extract))
        {
        snprintf(OUTPUT,CF_BUFSIZE*2,"Culprit %s\n",extract);
        CfLog(cferror,OUTPUT,"");
        exit(0);
        }
-   strcat(buffer,extract);
+   (void)strlcat(buffer,extract,CF_EXPANDSIZE);
    ExpandWildCardsAndDo(rest,buffer,function,argptr);
    return;
    }
 else
    { 
-   strcat(buffer,"/");
+   (void)strlcat(buffer,"/",CF_EXPANDSIZE);
    
    if ((dirh=opendir(buffer)) == NULL)
       {
@@ -3401,7 +3403,7 @@ else
       }
 
    count = 0;
-   strcpy(construct,buffer);                 /* save relative path */
+   (void)strlcpy(construct,buffer,sizeof(construct));                 /* save relative path */
  
    for (dp = readdir(dirh); dp != 0; dp = readdir(dirh))
       {
@@ -3411,8 +3413,8 @@ else
          }
 
       count++;
-      strcpy(buffer,construct);
-      strcat(buffer,dp->d_name);
+      (void)strlcpy(buffer,construct,CF_EXPANDSIZE);
+      (void)strlcat(buffer,dp->d_name,CF_EXPANDSIZE);
 
       if (stat(buffer,&statbuf) == -1)
          {
