$OpenBSD: patch-src_do_c,v 1.5 2005/10/27 21:47:28 sturm Exp $ --- src/do.c.orig Thu Sep 8 16:31:21 2005 +++ src/do.c Fri Oct 21 16:35:55 2005 @@ -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)) { @@ -231,13 +231,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; @@ -247,13 +247,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; @@ -262,18 +262,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: @@ -345,12 +345,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); } @@ -636,7 +636,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 */ @@ -646,9 +646,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 */ @@ -716,9 +716,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) { @@ -1194,9 +1194,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); } @@ -1434,6 +1434,7 @@ void GetSetuidLog() struct Item *ip; FILE *fp; char *sp; + size_t buflen; if (!IsPrivileged()) /* Ignore this if not root */ { @@ -1460,7 +1461,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"); @@ -1477,7 +1479,7 @@ else Debug2("SETUID-LOG: %s\n",VBUFF); - strcpy(sp,VBUFF); + (void)strlcpy(sp,VBUFF,buflen); ip->name = sp; ip->next = NULL; filetop = ip; @@ -1768,7 +1770,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)) @@ -1779,13 +1781,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 (pending repository move)\n",workname,path); @@ -1913,15 +1915,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 */ @@ -1933,11 +1935,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)) @@ -2007,15 +2009,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 */ @@ -2170,8 +2172,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); @@ -2195,8 +2197,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 @@ -2577,14 +2579,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 @@ -2592,7 +2594,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 */ @@ -2750,8 +2752,8 @@ for (ptr = VPKG; ptr != NULL; ptr=ptr->n } /* Finally add the name to the list. */ - strcat(package_install_list[ptr->pkgmgr], ptr->name); - strcat(package_install_list[ptr->pkgmgr], " "); + (void)strlcat(package_install_list[ptr->pkgmgr], ptr->name, CF_BUFSIZE); + (void)strlcat(package_install_list[ptr->pkgmgr], " ", CF_BUFSIZE); } } @@ -2890,14 +2892,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) { @@ -2925,14 +2927,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); } @@ -2980,7 +2982,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)) @@ -2989,7 +2991,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) { @@ -3033,9 +3035,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)) { @@ -3138,16 +3140,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; @@ -3296,14 +3298,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) != '/') @@ -3314,7 +3316,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); @@ -3349,7 +3351,7 @@ void EditItemsInResolvConf(struct Item * } else { - strncpy(buf,work,CF_MAXVARSIZE-1); + (void)strlcpy(buf,work,sizeof(buf)); } DeleteItemMatching(list,buf); /* del+prep = move to head of list */ @@ -3421,7 +3423,7 @@ if (strlen(extract) == 0) { if (isdir) { - strcat(buffer,"/"); + (void)strlcat(buffer,"/",CF_EXPANDSIZE); } (*function)(buffer,argptr); return; @@ -3429,20 +3431,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) { @@ -3452,7 +3454,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)) { @@ -3462,8 +3464,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) {