[Midnightbsd-cvs] src: usr.sbin/sysinstall: replace some of the string functions with

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Fri May 2 02:41:01 EDT 2008


Log Message:
-----------
replace some of the string functions with their "safe" equivalents.  Most of the usages were fine anyway.  It's just easier to audit.

Modified Files:
--------------
    src/usr.sbin/sysinstall:
        anonFTP.c (r1.4 -> r1.5)
        config.c (r1.9 -> r1.10)
        devices.c (r1.6 -> r1.7)
        dhcp.c (r1.2 -> r1.3)
        disks.c (r1.3 -> r1.4)
        dist.c (r1.5 -> r1.6)
        doc.c (r1.3 -> r1.4)
        ftp.c (r1.3 -> r1.4)
        http.c (r1.2 -> r1.3)
        index.c (r1.2 -> r1.3)
        install.c (r1.5 -> r1.6)
        label.c (r1.6 -> r1.7)
        media.c (r1.4 -> r1.5)
        misc.c (r1.3 -> r1.4)
        modules.c (r1.2 -> r1.3)
        msg.c (r1.2 -> r1.3)
        network.c (r1.2 -> r1.3)
        options.c (r1.2 -> r1.3)
        pccard.c (r1.2 -> r1.3)
        tape.c (r1.3 -> r1.4)
        tcpip.c (r1.3 -> r1.4)
        ttys.c (r1.2 -> r1.3)
        wizard.c (r1.2 -> r1.3)

-------------- next part --------------
Index: tcpip.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/tcpip.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -L usr.sbin/sysinstall/tcpip.c -L usr.sbin/sysinstall/tcpip.c -u -r1.3 -r1.4
--- usr.sbin/sysinstall/tcpip.c
+++ usr.sbin/sysinstall/tcpip.c
@@ -515,7 +515,7 @@
     draw_box(ds_win, TCP_DIALOG_Y + 9, TCP_DIALOG_X + 8, TCP_DIALOG_HEIGHT - 13, TCP_DIALOG_WIDTH - 17,
 	     dialog_attr, border_attr);
     wattrset(ds_win, dialog_attr);
-    sprintf(title, " Configuration for Interface %s ", devp->name);
+    snprintf(title, sizeof(title), " Configuration for Interface %s ", devp->name);
     mvwaddstr(ds_win, TCP_DIALOG_Y + 9, TCP_DIALOG_X + 14, title);
 
     /* Some more initialisation before we go into the main input loop */
@@ -531,13 +531,13 @@
 	     * class A/B network).
 	     */
 	    if (!netmask[0]) {
-		strcpy(netmask, "255.255.255.0");
+		strlcpy(netmask, "255.255.255.0", sizeof(netmask));
 		RefreshStringObj(layout[LAYOUT_NETMASK].obj);
 		++filled;
 	    }
 	    if (!index(hostname, '.') && domainname[0]) {
-		strcat(hostname, ".");
-		strcat(hostname, domainname);
+		strlcat(hostname, ".", sizeof(hostname));
+		strlcat(hostname, domainname, sizeof(hostname));
 		RefreshStringObj(layout[LAYOUT_HOSTNAME].obj);
 		++filled;
 	    }
@@ -596,14 +596,14 @@
 	if (use_dhcp || ipaddr[0])
 	    ipv4_enable = TRUE;
 	if (ipv4_enable) {
-	    sprintf(ifn, "%s%s", VAR_IFCONFIG, devp->name);
+	    snprintf(ifn, sizeof(ifn), "%s%s", VAR_IFCONFIG, devp->name);
 	    if (use_dhcp) {
 		if (strlen(extras) > 0)
-		    sprintf(temp, "DHCP %s", extras);
+		    snprintf(temp, sizeof(temp), "DHCP %s", extras);
 		else
-		    sprintf(temp, "DHCP");
+		    snprintf(temp, sizeof(temp), "DHCP");
 	    } else
-		sprintf(temp, "inet %s %s netmask %s",
+		snprintf(temp, sizeof(temp), "inet %s %s netmask %s",
 			ipaddr, extras, netmask);
 	    variable_set2(ifn, temp, 1);
 	}
Index: dist.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/dist.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -L usr.sbin/sysinstall/dist.c -L usr.sbin/sysinstall/dist.c -u -r1.5 -r1.6
--- usr.sbin/sysinstall/dist.c
+++ usr.sbin/sysinstall/dist.c
@@ -348,7 +348,7 @@
     cp = alloca(strlen(tmp) + 1);
     if (!cp)
 	msgFatal("Couldn't alloca() %d bytes!\n", (int)(strlen(tmp) + 1));
-    strcpy(cp, tmp);
+    strlcpy(cp, tmp, sizeof(cp));
     while (cp) {
 	if ((cp2 = index(cp, ' ')) != NULL)
 	    *(cp2++) = '\0';
@@ -721,7 +721,7 @@
 	*col += strlen(me[i].my_name);
 	if (*col > 50) {
 	    *col = 0;
-	    strcat(buf, "\n");
+	    strlcat(buf, "\n", sizeof(buf));
 	}
 	sprintf(&buf[strlen(buf)], " %s", me[i].my_name);
 
Index: options.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/options.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L usr.sbin/sysinstall/options.c -L usr.sbin/sysinstall/options.c -u -r1.2 -r1.3
--- usr.sbin/sysinstall/options.c
+++ usr.sbin/sysinstall/options.c
@@ -178,7 +178,7 @@
 	return (char *)opt.data;
 
     case OPT_IS_INT:
-	sprintf(ival, "%lu", (long)opt.data);
+	snprintf(ival, sizeof(ival), "%lu", (long)opt.data);
 	return ival;
 
     case OPT_IS_FUNC:
Index: install.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/install.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -L usr.sbin/sysinstall/install.c -L usr.sbin/sysinstall/install.c -u -r1.5 -r1.6
--- usr.sbin/sysinstall/install.c
+++ usr.sbin/sysinstall/install.c
@@ -943,7 +943,7 @@
     command_clear();
     if (SwapChunk && RunningAsInit) {
 	/* As the very first thing, try to get ourselves some swap space */
-	sprintf(dname, "/dev/%s", SwapChunk->name);
+	snprintf(dname, sizeof(dname), "/dev/%s", SwapChunk->name);
 	if (!Fake && !file_readable(dname)) {
 	    msgConfirm("Unable to find device node for %s in /dev!\n"
 		       "The creation of filesystems will be aborted.", dname);
@@ -965,7 +965,7 @@
 
     if (RootChunk && RunningAsInit) {
 	/* Next, create and/or mount the root device */
-	sprintf(dname, "/dev/%s", RootChunk->name);
+	snprintf(dname, sizeof(dname), "/dev/%s", RootChunk->name);
 	if (!Fake && !file_readable(dname)) {
 	    msgConfirm("Unable to make device node for %s in /dev!\n"
 		       "The creation of filesystems will be aborted.", dname);
@@ -1014,7 +1014,7 @@
 	}
 
 	/* Switch to block device */
-	sprintf(dname, "/dev/%s", RootChunk->name);
+	snprintf(dname, sizeof(dname), "/dev/%s", RootChunk->name);
 	if (Mount("/mnt", dname)) {
 	    msgConfirm("Unable to mount the root file system on %s!  Giving up.", dname);
 	    return DITEM_FAILURE | DITEM_RESTORE;
@@ -1070,7 +1070,7 @@
 			if (c2 == RootChunk)
 			    continue;
 
-			sprintf(dname, "%s/dev/%s",
+			snprintf(dname, sizeof(dname), "%s/dev/%s",
 			    RunningAsInit ? "/mnt" : "", c2->name);
 
 			if (tmp->do_newfs && (!upgrade ||
@@ -1095,7 +1095,7 @@
 
 			if (c2 == SwapChunk)
 			    continue;
-			sprintf(fname, "%s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name);
+			snprintf(fname, sizeof(fname), "%s/dev/%s", RunningAsInit ? "/mnt" : "", c2->name);
 			i = (Fake || swapon(fname));
 			if (!i) {
 			    dialog_clear_norefresh();
@@ -1111,7 +1111,8 @@
 		(root->do_newfs || upgrade)) {
 		char name[FILENAME_MAX];
 
-		sprintf(name, "%s/%s", RunningAsInit ? "/mnt" : "", ((PartInfo *)c1->private_data)->mountpoint);
+		snprintf(name, sizeof(name), "%s/%s", RunningAsInit ? "/mnt" : "", 
+		    ((PartInfo *)c1->private_data)->mountpoint);
 		Mkdir(name);
 	    }
 #if defined(__ia64__)
@@ -1120,7 +1121,7 @@
 		PartInfo *pi = (PartInfo *)c1->private_data;
 		char *p;
 
-		sprintf(dname, "%s/dev/%s", RunningAsInit ? "/mnt" : "",
+		snprintf(dname, sizeof(dname), "%s/dev/%s", RunningAsInit ? "/mnt" : "",
 		    c1->name);
 
 		if (pi->do_newfs && (!upgrade ||
Index: devices.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/devices.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -L usr.sbin/sysinstall/devices.c -L usr.sbin/sysinstall/devices.c -u -r1.6 -r1.7
--- usr.sbin/sysinstall/devices.c
+++ usr.sbin/sysinstall/devices.c
@@ -428,12 +428,12 @@
 		    cp = device_names[i].description;
 		    /* Serial devices get a slip and ppp device each, if supported */
 		    newdesc = safe_malloc(strlen(cp) + 40);
-		    sprintf(newdesc, cp, "SLIP interface", try, j + 1);
+		    snprintf(newdesc, sizeof(newdesc), cp, "SLIP interface", try, j + 1);
 		    deviceRegister("sl0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork,
 				   NULL, mediaShutdownNetwork, NULL);
 		    msgDebug("Add mapping for %s to sl0\n", try);
 		    newdesc = safe_malloc(strlen(cp) + 50);
-		    sprintf(newdesc, cp, "PPP interface", try, j + 1);
+		    snprintf(newdesc, sizeof(newdesc), cp, "PPP interface", try, j + 1);
 		    deviceRegister("ppp0", newdesc, strdup(try), DEVICE_TYPE_NETWORK, TRUE, mediaInitNetwork,
 				   NULL, mediaShutdownNetwork, NULL);
 		    if (isDebug())
Index: modules.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/modules.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L usr.sbin/sysinstall/modules.c -L usr.sbin/sysinstall/modules.c -u -r1.2 -r1.3
--- usr.sbin/sysinstall/modules.c
+++ usr.sbin/sysinstall/modules.c
@@ -64,10 +64,10 @@
 	while ((dp = readdir(dirp))) {
 	    if (dp->d_namlen < (sizeof(".ko") - 1)) continue;
 	    if (strcmp(dp->d_name + dp->d_namlen - (sizeof(".ko") - 1), ".ko") == 0) {
-		strcpy(module, MODULESDIR);
-		strcat(module, "/");
-		strcat(module, dp->d_name);
-		strcpy(desc, module);
+		strlcpy(module, MODULESDIR, sizeof(module));
+		strlcat(module, "/", sizeof(module));
+		strlcat(module, dp->d_name, sizeof(module));
+		strlcpy(desc, module, sizeof(desc));
 		len = strlen(desc);
 		strcpy(desc + (len - (sizeof(".ko") - 1)), ".dsc");
 		fd = open(module, O_RDONLY);
Index: anonFTP.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/anonFTP.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -L usr.sbin/sysinstall/anonFTP.c -L usr.sbin/sysinstall/anonFTP.c -u -r1.4 -r1.5
--- usr.sbin/sysinstall/anonFTP.c
+++ usr.sbin/sysinstall/anonFTP.c
@@ -169,7 +169,8 @@
 	return DITEM_SUCCESS; 	/* succeeds if already exists */
     }
     
-    sprintf(pwline, "%s:*:%s:%d::0:0:%s:%s:/nonexistent\n", FTP_NAME, tconf.uid, gid, tconf.comment, tconf.homedir);
+    snprintf(pwline, sizeof(pwline), "%s:*:%s:%d::0:0:%s:%s:/nonexistent\n", 
+        FTP_NAME, tconf.uid, gid, tconf.comment, tconf.homedir);
     
     fptr = fopen(_PATH_MASTERPASSWD,"a");
     if (! fptr) {
@@ -208,7 +209,7 @@
 	     ANONFTP_DIALOG_HEIGHT - 11, ANONFTP_DIALOG_WIDTH - 17,
 	     dialog_attr, border_attr);
     wattrset(ds_win, dialog_attr);
-    sprintf(title, " Path Configuration ");
+    snprintf(title, sizeof(title), " Path Configuration ");
     mvwaddstr(ds_win, ANONFTP_DIALOG_Y + 7, ANONFTP_DIALOG_X + 22, title);
     
     /** Initialize the config Data Structure **/
@@ -218,7 +219,7 @@
     SAFE_STRCPY(tconf.upload, FTP_UPLOAD);
     SAFE_STRCPY(tconf.comment, FTP_COMMENT);
     SAFE_STRCPY(tconf.homedir, FTP_HOMEDIR);
-    sprintf(tconf.uid, "%d", FTP_UID);
+    snprintf(tconf.uid, sizeof(tconf.uid), "%d", FTP_UID);
     
     /* Some more initialisation before we go into the main input loop */
     obj = initLayoutDialog(ds_win, layout, ANONFTP_DIALOG_X, ANONFTP_DIALOG_Y, &max);
@@ -267,7 +268,7 @@
     
     /*** Use defaults for any invalid values ***/
     if (atoi(tconf.uid) <= 0)
-	sprintf(tconf.uid, "%d", FTP_UID);
+	snprintf(tconf.uid, sizeof(tconf.uid), "%d", FTP_UID);
     
     if (!tconf.group[0])
 	SAFE_STRCPY(tconf.group, FTP_GROUP);
@@ -311,7 +312,7 @@
 	if (!msgYesNo("Create a welcome message file for anonymous FTP users?")) {
 	    char cmd[256];
 	    vsystem("echo Your welcome message here. > %s/etc/%s", tconf.homedir, MOTD_FILE);
-	    sprintf(cmd, "%s %s/etc/%s", variable_get(VAR_EDITOR), tconf.homedir, MOTD_FILE);
+	    snprintf(cmd, sizeof(cmd), "%s %s/etc/%s", variable_get(VAR_EDITOR), tconf.homedir, MOTD_FILE);
 	    if (!systemExecute(cmd))
 		i = DITEM_SUCCESS;
 	    else
Index: ttys.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/ttys.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L usr.sbin/sysinstall/ttys.c -L usr.sbin/sysinstall/ttys.c -u -r1.2 -r1.3
--- usr.sbin/sysinstall/ttys.c
+++ usr.sbin/sysinstall/ttys.c
@@ -64,7 +64,7 @@
 		   strerror(errno));
 	return;
     }
-    strcpy(templ, _PATH_TTYS _X_EXTENSION);
+    strlcpy(templ, _PATH_TTYS _X_EXTENSION, sizeof(templ));
     if ((t = mkstemp(templ)) < 0) {
 	msgConfirm("Can't create %s: %s", templ, strerror(errno));
 	(void)fclose(fp);
Index: wizard.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/wizard.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L usr.sbin/sysinstall/wizard.c -L usr.sbin/sysinstall/wizard.c -u -r1.2 -r1.3
--- usr.sbin/sysinstall/wizard.c
+++ usr.sbin/sysinstall/wizard.c
@@ -35,8 +35,8 @@
     u_long l;
     int i,j,fd;
 
-    strcpy(device,"/dev/");
-    strcat(device,d->name);
+    strlcpy(device,"/dev/", sizeof(device));
+    strlcat(device,d->name, sizeof(device));
 
     fd = open(device,O_RDWR);
     if (fd < 0) {
@@ -73,7 +73,7 @@
     int ncmd,i;
 
     systemSuspendDialog();
-    sprintf(myprompt,"%s> ", d->name);
+    snprintf(myprompt, sizeof(myprompt), "%s> ", d->name);
     while(1) {
 	printf("--==##==--\n");
 	Debug_Disk(d);
@@ -128,19 +128,6 @@
 	    free(cp);
 	    continue;
 	}
-#ifdef PC98
-	if (!strcasecmp(*cmds,"create") && ncmd == 7) {
-	    printf("Create=%d\n",
-		   Create_Chunk(d,
-				strtol(cmds[1],0,0),
-				strtol(cmds[2],0,0),
-				strtol(cmds[3],0,0),
-				strtol(cmds[4],0,0),
-				strtol(cmds[5],0,0),
-				cmds[6]));
-	    continue;
-	}
-#else
 	if (!strcasecmp(*cmds,"create") && ncmd == 6) {
 	    printf("Create=%d\n",
 		   Create_Chunk(d,
@@ -151,7 +138,6 @@
 				strtol(cmds[5],0,0), ""));
 	    continue;
 	}
-#endif
 	if (!strcasecmp(*cmds,"read")) {
 	    db = d;
 	    if (ncmd > 1)
@@ -183,11 +169,7 @@
 	printf("dedicate\t\t");
 	printf("bios cyl hd sect\n");
 	printf("collapse [pointer]\t\t");
-#ifdef PC98
-	printf("create offset size enum subtype flags name\n");
-#else
 	printf("create offset size enum subtype flags\n");
-#endif
 	printf("subtype(part): swap=1, ffs=7\t\t");
 	printf("delete pointer\n");
 	printf("list\t\t");
Index: doc.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/doc.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -L usr.sbin/sysinstall/doc.c -L usr.sbin/sysinstall/doc.c -u -r1.3 -r1.4
--- usr.sbin/sysinstall/doc.c
+++ usr.sbin/sysinstall/doc.c
@@ -99,7 +99,7 @@
     if (strstr(str, "Other")) {
 	where = msgGetInput("http://www.midnightbsd.org", "Please enter the URL of the location you wish to visit.");
 	if (where)
-	    strcpy(target, where);
+	    strlcpy(target, where, sizeof(target));
     }
     else if (strstr(str, "FAQ")) {
 	where = strcpy(target, "/usr/share/doc/faq/index.html");
@@ -112,7 +112,7 @@
 	    where = strcpy(target, "http://www.midnightbsd.org/docs");
     }
     if (where) {
-	sprintf(tmp, "%s %s", browser, target);
+	snprintf(tmp, sizeof(tmp), "%s %s", browser, target);
 	systemExecute(tmp);
 	return DITEM_SUCCESS;
     }
Index: disks.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/disks.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -L usr.sbin/sysinstall/disks.c -L usr.sbin/sysinstall/disks.c -u -r1.3 -r1.4
--- usr.sbin/sysinstall/disks.c
+++ usr.sbin/sysinstall/disks.c
@@ -217,7 +217,7 @@
     cp = variable_get(VAR_BOOTMGR);
     if (!cp) {
 	/* Figure out what kind of IPL the user wants */
-	sprintf(str, "Install Boot Manager for drive %s?", dname);
+	snprintf(str, sizeof(str), "Install Boot Manager for drive %s?", dname);
 	MenuIPLType.title = str;
 	i = dmenuOpenSimple(&MenuIPLType, FALSE);
     } else {
@@ -260,7 +260,7 @@
     cp = variable_get(VAR_BOOTMGR);
     if (!cp) {
 	/* Figure out what kind of MBR the user wants */
-	sprintf(str, "Install Boot Manager for drive %s?", dname);
+	snprintf(str, sizeof(str), "Install Boot Manager for drive %s?", dname);
 	MenuMBRType.title = str;
 	i = dmenuOpenSimple(&MenuMBRType, FALSE);
     }
@@ -456,7 +456,7 @@
 			size *= ONE_MEG;
 		    else if (*cp && toupper(*cp) == 'G')
 			size *= ONE_GIG;
-		    sprintf(tmp, "%d", SUBTYPE_FREEBSD);
+		    snprintf(tmp, sizeof(tmp), "%d", SUBTYPE_FREEBSD);
 		    val = msgGetInput(tmp, "Enter type of partition to create:\n\n"
 			"Pressing Enter will choose the default, a native MidnightBSD\n"
 			"slice (type %u).  "
@@ -500,7 +500,7 @@
 		int subtype;
 		chunk_e partitiontype;
 
-		sprintf(tmp, "%d", chunk_info[current_chunk]->subtype);
+		snprintf(tmp, sizeof(tmp), "%d", chunk_info[current_chunk]->subtype);
 		val = msgGetInput(tmp, "New partition type:\n\n"
 		    "Pressing Enter will use the current type. To choose a native\n"
 		    "MidnightBSD slice enter %u.  "
Index: http.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/http.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L usr.sbin/sysinstall/http.c -L usr.sbin/sysinstall/http.c -u -r1.2 -r1.3
--- usr.sbin/sysinstall/http.c
+++ usr.sbin/sysinstall/http.c
@@ -88,7 +88,7 @@
     }
 
     msgNotify("Checking access to\n %s", variable_get(VAR_HTTP_PATH));
-    sprintf(req,"GET %s/ HTTP/1.0\r\n\r\n", variable_get(VAR_HTTP_PATH));
+    snprintf(req, sizeof(req), "GET %s/ HTTP/1.0\r\n\r\n", variable_get(VAR_HTTP_PATH));
     write(s,req,strlen(req));
 /*
  *  scan the headers of the response
@@ -161,7 +161,7 @@
 
     if (strcmp(rel, "__RELEASE") && strcmp(rel, "any"))  {
         for (fdir = 0; ftp_dirs[fdir]; fdir++) {
-            sprintf(req, "%s/%s/%s", variable_get(VAR_FTP_PATH),
+            snprintf(req, sizeof(req), "%s/%s/%s", variable_get(VAR_FTP_PATH),
                 ftp_dirs[fdir], rel);
             variable_set2(VAR_HTTP_PATH, req, 0);
             if (checkAccess(FALSE)) {
@@ -220,7 +220,7 @@
 	return NULL;
     }
 						   
-    sprintf(req,"GET %s/%s%s HTTP/1.0\r\n\r\n",
+    snprintf(req, sizeof(req), "GET %s/%s%s HTTP/1.0\r\n\r\n",
 	    variable_get(VAR_HTTP_PATH), file, variable_get(VAR_HTTP_FTP_MODE));
 
     if (isDebug()) {
Index: index.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/index.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L usr.sbin/sysinstall/index.c -L usr.sbin/sysinstall/index.c -u -r1.2 -r1.3
--- usr.sbin/sysinstall/index.c
+++ usr.sbin/sysinstall/index.c
@@ -268,7 +268,7 @@
 	return 0;
     }
     *tok = '\0';
-    strcpy(to, from);
+    strlcpy(to, from, sizeof(to));
     return tok + 1 - from;
 }
 
Index: network.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/network.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L usr.sbin/sysinstall/network.c -L usr.sbin/sysinstall/network.c -u -r1.2 -r1.3
--- usr.sbin/sysinstall/network.c
+++ usr.sbin/sysinstall/network.c
@@ -240,7 +240,7 @@
     if (devp->private && ((DevInfo *)devp->private)->ipaddr[0])
 	SAFE_STRCPY(myaddr, ((DevInfo *)devp->private)->ipaddr);
     else
-	strcpy(myaddr, "0");
+	strlcpy(myaddr, "0", sizeof(myaddr));
 
     if (!Fake)
 	fp = fopen("/etc/ppp/ppp.linkup", "w");
Index: dhcp.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/dhcp.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L usr.sbin/sysinstall/dhcp.c -L usr.sbin/sysinstall/dhcp.c -u -r1.2 -r1.3
--- usr.sbin/sysinstall/dhcp.c
+++ usr.sbin/sysinstall/dhcp.c
@@ -126,25 +126,25 @@
 		}
 	    }
 	    else
-		strcpy(optbuf, tempbuf);
+		strlcpy(optbuf, tempbuf, sizeof(optbuf));
 
 	    if (!strcasecmp("host-name", optname)) {
-		strcpy(hostname, optbuf);
+		strlcpy(hostname, optbuf, sizeof(hostname));
 	    } else if (!strcasecmp("domain-name", optname)) {
-		strcpy(domain, optbuf);
+		strlcpy(domain, optbuf, sizeof(domain));
 	    } else if (!strcasecmp("fixed-address", optname)) {
-		strcpy(ipaddr, optbuf);
+		strlcpy(ipaddr, optbuf, sizeof(ipaddr));
 	    } else if (!strcasecmp("routers", optname)) {
 		if((tptr = (char *)strchr(optbuf, ',')))
 		    *tptr = '\0';
-		strcpy(gateway, optbuf);
+		strlcpy(gateway, optbuf, sizeof(gateway));
 	    } else if (!strcasecmp("subnet-mask", optname)) {
-		strcpy(netmask, optbuf);
+		strlcpy(netmask, optbuf, sizeof(netmask));
 	    } else if (!strcasecmp("domain-name-servers", optname)) {
 		/* <jkh> ...one value per property */
 		if((tptr = (char *)strchr(optbuf, ',')))
 		    *tptr = '\0';
-		strcpy(nameserver, optbuf);
+		strlcpy(nameserver, optbuf, sizeof(nameserver));
 	    }
 	    if (endedflag) {
 		state = P_STMT;
Index: msg.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/msg.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L usr.sbin/sysinstall/msg.c -L usr.sbin/sysinstall/msg.c -u -r1.2 -r1.3
--- usr.sbin/sysinstall/msg.c
+++ usr.sbin/sysinstall/msg.c
@@ -111,7 +111,7 @@
     int attrs;
 
     errstr = (char *)alloca(FILENAME_MAX);
-    strcpy(errstr, "Warning: ");
+    strlcpy(errstr, "Warning: ", sizeof(errstr));
     va_start(args, fmt);
     vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
     va_end(args);
@@ -134,7 +134,7 @@
     int attrs;
 
     errstr = (char *)alloca(FILENAME_MAX);
-    strcpy(errstr, "Error: ");
+    strlcpy(errstr, "Error: ", sizeof(errstr));
     va_start(args, fmt);
     vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
     va_end(args);
@@ -157,7 +157,7 @@
     int attrs;
 
     errstr = (char *)alloca(FILENAME_MAX);
-    strcpy(errstr, "Fatal Error: ");
+    strlcpy(errstr, "Fatal Error: ", sizeof(errstr));
     va_start(args, fmt);
     vsnprintf((char *)(errstr + strlen(errstr)), FILENAME_MAX, fmt, args);
     va_end(args);
@@ -313,7 +313,7 @@
     if (DebugFD == -1)
 	return;
     dbg = (char *)alloca(FILENAME_MAX);
-    strcpy(dbg, "DEBUG: ");
+    strlcpy(dbg, "DEBUG: ", sizeof(dbg));
     va_start(args, fmt);
     vsnprintf((char *)(dbg + strlen(dbg)), FILENAME_MAX, fmt, args);
     va_end(args);
Index: label.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/label.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -L usr.sbin/sysinstall/label.c -L usr.sbin/sysinstall/label.c -u -r1.6 -r1.7
--- usr.sbin/sysinstall/label.c
+++ usr.sbin/sysinstall/label.c
@@ -364,11 +364,7 @@
 	pi->newfs_data.newfs_ufs.acls = FALSE;
 	pi->newfs_data.newfs_ufs.multilabel = FALSE;
 	pi->newfs_data.newfs_ufs.softupdates = strcmp(mpoint, "/");
-#ifdef PC98
-	pi->newfs_data.newfs_ufs.ufs1 = TRUE;
-#else
 	pi->newfs_data.newfs_ufs.ufs1 = FALSE;
-#endif
     }
 
     return pi;
@@ -493,7 +489,7 @@
 	snprintf(buffer, NEWFS_CMD_ARGS_MAX, "%s", NEWFS_MSDOS_CMD);
 	break;
     case NEWFS_CUSTOM:
-	strcpy(buffer, p->newfs_data.newfs_custom.command);
+	strlcpy(buffer, p->newfs_data.newfs_custom.command, sizeof(buffer));
 	break;
     }
 
@@ -708,14 +704,14 @@
 
 	    /* Now display the newfs field */
 	    if (label_chunk_info[i].type == PART_FAT)
-		strcpy(newfs, "DOS");
+		strlcpy(newfs, "DOS", sizeof(newfs));
 #if defined(__ia64__)
 	    else if (label_chunk_info[i].type == PART_EFI) {
-		strcpy(newfs, "EFI");
+		strlcpy(newfs, "EFI", sizeof(newfs));
 		if (label_chunk_info[i].c->private_data) {
-		    strcat(newfs, "  ");
+		    strlcat(newfs, "  ", sizeof(newfs));
 		    PartInfo *pi = (PartInfo *)label_chunk_info[i].c->private_data;
-		    strcat(newfs, pi->do_newfs ? " Y" : " N");
+		    strlcat(newfs, pi->do_newfs ? " Y" : " N", sizeof(newfs));
 		}
 	    }
 #endif
@@ -724,30 +720,30 @@
 
 		switch (pi->newfs_type) {
 		case NEWFS_UFS:
-			strcpy(newfs, NEWFS_UFS_STRING);
+			strlcpy(newfs, NEWFS_UFS_STRING, sizeof(newfs));
 			if (pi->newfs_data.newfs_ufs.ufs1)
-				strcat(newfs, "1");
+				strlcat(newfs, "1", sizeof(newfs));
 			else
-				strcat(newfs, "2");
+				strlcat(newfs, "2", sizeof(newfs));
 			if (pi->newfs_data.newfs_ufs.softupdates)
-				strcat(newfs, "+S");
+				strlcat(newfs, "+S", sizeof(newfs));
 			else
-				strcat(newfs, "  ");
+				strlcat(newfs, "  ", sizeof(newfs));
 
 			break;
 		case NEWFS_MSDOS:
-			strcpy(newfs, "FAT");
+			strlcpy(newfs, "FAT", sizeof(newfs));
 			break;
 		case NEWFS_CUSTOM:
-			strcpy(newfs, "CUST");
+			strlcpy(newfs, "CUST", sizeof(newfs));
 			break;
 		}
-		strcat(newfs, pi->do_newfs ? " Y" : " N ");
+		strlcat(newfs, pi->do_newfs ? " Y" : " N ", sizeof(newfs));
 	    }
 	    else if (label_chunk_info[i].type == PART_SWAP)
-		strcpy(newfs, "SWAP");
+		strlcpy(newfs, "SWAP", sizeof(newfs));
 	    else
-		strcpy(newfs, "*");
+		strlcpy(newfs, "*", sizeof(newfs));
 	    for (j = 0; j < MAX_MOUNT_NAME && mountpoint[j]; j++)
 		onestr[PART_MOUNT_COL + j] = mountpoint[j];
 	    if (label_chunk_info[i].c->size == 0)
@@ -770,7 +766,7 @@
 
             /*** lazy man's way of expensively padding this string ***/
             while (strlen(onestr) < 37)
-                strcat(onestr, " ");
+                strlcat(onestr, " ", sizeof(newfs));
 
 	    mvwaddstr(ChunkWin, prow, pcol, onestr);
 	    wattrset(ChunkWin, A_NORMAL);
@@ -987,7 +983,7 @@
 		char osize[80];
 		u_long flags = 0;
 
-		sprintf(osize, "%jd", (intmax_t)sz);
+		snprintf(osize, sizeof(osize), "%jd", (intmax_t)sz);
 		val = msgGetInput(osize,
 				  "Please specify the partition size in blocks or append a trailing G for\n"
 #ifdef __ia64__
@@ -1133,7 +1129,7 @@
 			    !strcmp(p->mountpoint, "/usr") ||
 			    !strcmp(p->mountpoint, "/var"))) {
 			msgConfirm("%s is an invalid mount point for a DOS partition!", p->mountpoint);
-			strcpy(p->mountpoint, "/bogus");
+			strlcpy(p->mountpoint, "/bogus", sizeof(p->mountpoint));
 		    }
 		}
 		if (variable_cmp(DISK_LABELLED, "written"))
@@ -1292,7 +1288,7 @@
 
 	default:
 	    beep();
-	    sprintf(_msg, "Invalid key %d - Type F1 or ? for help", key);
+	    snprintf(_msg, sizeof(_msg), "Invalid key %d - Type F1 or ? for help", key);
 	    msg = _msg;
 	    break;
 	}
@@ -1599,7 +1595,7 @@
 		    flags = 0;
 		    if (!strcmp(typ, "swap")) {
 			type = PART_SWAP;
-			strcpy(mpoint, "SWAP");
+			strlcpy(mpoint, "SWAP", sizeof(mpoint));
 		    } else {
 			type = PART_FILESYSTEM;
 			if (!strcmp(mpoint, "/"))
@@ -1642,7 +1638,7 @@
 		if (c1->private_data) {
 		    p = c1->private_data;
 		    p->do_newfs = newfs;
-		    strcpy(p->mountpoint, mpoint);
+		    strlcpy(p->mountpoint, mpoint, sizeof(p->mountpoint));
 		}
 		else {
 		    c1->private_data = new_part(PART_FILESYSTEM, mpoint, newfs);
Index: misc.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/misc.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -L usr.sbin/sysinstall/misc.c -L usr.sbin/sysinstall/misc.c -u -r1.3 -r1.4
--- usr.sbin/sysinstall/misc.c
+++ usr.sbin/sysinstall/misc.c
@@ -328,8 +328,8 @@
 	return DITEM_SUCCESS;
 
     if (*((char *)dev) != '/') {
-    	sprintf(device, "%s/dev/%s", RunningAsInit ? "/mnt" : "", (char *)dev);
-	sprintf(mountpoint, "%s%s", RunningAsInit ? "/mnt" : "", mountp);
+    	snprintf(device, sizeof(device), "%s/dev/%s", RunningAsInit ? "/mnt" : "", (char *)dev);
+	snprintf(mountpoint, sizeof(mountpoint), "%s%s", RunningAsInit ? "/mnt" : "", mountp);
     }
     else {
 	strcpy(device, dev);
@@ -364,12 +364,12 @@
 	return DITEM_SUCCESS;
 
     if (*((char *)dev) != '/') {
-    	sprintf(device, "%s/dev/%s", RunningAsInit ? "/mnt" : "", (char *)dev);
-	sprintf(mountpoint, "%s%s", RunningAsInit ? "/mnt" : "", mountp);
+    	snprintf(device, sizeof(device), "%s/dev/%s", RunningAsInit ? "/mnt" : "", (char *)dev);
+	snprintf(mountpoint, sizeof(mountpoint), "%s%s", RunningAsInit ? "/mnt" : "", mountp);
     }
     else {
-	strcpy(device, dev);
-	strcpy(mountpoint, mountp);
+	strlcpy(device, dev, sizeof(device));
+	strlcpy(mountpoint, mountp, sizeof(mountpoint));
     }
 
     if (Mkdir(mountpoint)) {
Index: config.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/config.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -L usr.sbin/sysinstall/config.c -L usr.sbin/sysinstall/config.c -u -r1.9 -r1.10
--- usr.sbin/sysinstall/config.c
+++ usr.sbin/sysinstall/config.c
@@ -255,7 +255,7 @@
     for (i = 0; i < cnt; i++) {
 	char cdname[10];
 	
-	sprintf(cdname, "/cdrom%s", i ? itoa(i) : "");
+	snprintf(cdname, sizeof(cdname), "/cdrom%s", i ? itoa(i) : "");
 	if (Mkdir(cdname))
 	    msgConfirm("Unable to make mount point for: %s", cdname);
 	else
@@ -838,7 +838,7 @@
 		   "IPv6 must be separately enabled from IPv4 services.\n\n"
                    "Select [Yes] now to invoke an editor on /etc/inetd.conf, or [No] to\n"
                    "use the current settings.\n")) {
-            sprintf(cmd, "%s /etc/inetd.conf", variable_get(VAR_EDITOR));
+            snprintf(cmd, sizeof(cmd), "%s /etc/inetd.conf", variable_get(VAR_EDITOR));
             dialog_clear();
             systemExecute(cmd);
 	}
@@ -877,7 +877,7 @@
 	    vsystem("echo '# You should replace these lines with your actual exported filesystems.' >> /etc/exports");
 	    vsystem("echo \"# Note that BSD's export syntax is 'host-centric' vs. Sun's 'FS-centric' one.\" >> /etc/exports");
 	    vsystem("echo >> /etc/exports");
-	    sprintf(cmd, "%s /etc/exports", variable_get(VAR_EDITOR));
+	    snprintf(cmd, sizeof(cmd), "%s /etc/exports", variable_get(VAR_EDITOR));
 	    dialog_clear();
 	    systemExecute(cmd);
 	}
@@ -933,7 +933,7 @@
 		 "To load /etc/ttys in the editor, select [Yes], otherwise, [No].")) {
     } else {
 	configTtys();
-	sprintf(cmd, "%s /etc/ttys", variable_get(VAR_EDITOR));
+	snprintf(cmd, sizeof(cmd), "%s /etc/ttys", variable_get(VAR_EDITOR));
 	dialog_clear();
 	systemExecute(cmd);
     }
Index: media.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/media.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -L usr.sbin/sysinstall/media.c -L usr.sbin/sysinstall/media.c -u -r1.4 -r1.5
--- usr.sbin/sysinstall/media.c
+++ usr.sbin/sysinstall/media.c
@@ -533,9 +533,9 @@
 
     /* If they gave us a CDROM or something, try and pick a better name */
     if (statfs(cp, &st))
-	strcpy(ufsDevice.name, "ufs");
+	strlcpy(ufsDevice.name, "ufs", sizeof(ufsDevice.name));
     else
-	strcpy(ufsDevice.name, st.f_fstypename);
+	strlcpy(ufsDevice.name, st.f_fstypename, sizeof(ufsDevice.name));
 
     ufsDevice.type = DEVICE_TYPE_UFS;
     ufsDevice.init = dummyInit;
Index: tape.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/tape.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -L usr.sbin/sysinstall/tape.c -L usr.sbin/sysinstall/tape.c -u -r1.3 -r1.4
--- usr.sbin/sysinstall/tape.c
+++ usr.sbin/sysinstall/tape.c
@@ -101,13 +101,13 @@
 	restorescr(w);
     }
 
-    sprintf(buf, "%s/%s", (char *)dev->private, file);
+    snprintf(buf, sizeof(buf), "%s/%s", (char *)dev->private, file);
     if (isDebug())
 	msgDebug("Request for %s from tape (looking in %s)\n", file, buf);
     if (file_readable(buf))
 	fp = fopen(buf, "r");
     else {
-	sprintf(buf, "%s/releases/%s", (char *)dev->private, file);
+	snprintf(buf, sizeof(buf), "%s/releases/%s", (char *)dev->private, file);
 	fp = fopen(buf, "r");
     }
     /* Nuke the files behind us to save space */
Index: pccard.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/pccard.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L usr.sbin/sysinstall/pccard.c -L usr.sbin/sysinstall/pccard.c -u -r1.2 -r1.3
--- usr.sbin/sysinstall/pccard.c
+++ usr.sbin/sysinstall/pccard.c
@@ -189,7 +189,7 @@
 	return;
     }
 
-    sprintf(card_device, CARD_DEVICE, 0);
+    snprintf(card_device, sizeof(card_device), CARD_DEVICE, 0);
 
     if ((fd = open(card_device, O_RDWR)) < 0) {
 	msgDebug("Can't open PC Card controller %s.\n", card_device);
@@ -237,8 +237,8 @@
     if (CardIrq) {
         for (i = 0; i < IRQ_COUNT; i++) {
             if ((CardIrq & IrqTable[i].my_bit) != 0) {
-                sprintf(temp, "%s %s", card_irq, IrqTable[i].my_flag);
-                strcpy(card_irq, temp);
+                snprintf(temp, sizeof(temp), "%s %s", card_irq, IrqTable[i].my_flag);
+                strlcpy(card_irq, temp, sizeof(card_irq));
             }
         } 
     }
@@ -279,9 +279,9 @@
 
     }
 
-    strcpy(pccardd_cmd, "/stand/pccardd ");
-    strcat(pccardd_cmd, card_irq);
-    strcat(pccardd_cmd, " -z");
+    strlcpy(pccardd_cmd, "/stand/pccardd ", pccardd_cmd);
+    strlcat(pccardd_cmd, card_irq, pccardd_cmd);
+    strlcat(pccardd_cmd, " -z", pccardd_cmd);
 
     variable_set2("pccardd_flags", card_irq, 1);
     variable_set2("pccard_enable", "YES", 1);
Index: ftp.c
===================================================================
RCS file: /home/cvs/src/usr.sbin/sysinstall/ftp.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -L usr.sbin/sysinstall/ftp.c -L usr.sbin/sysinstall/ftp.c -u -r1.3 -r1.4
--- usr.sbin/sysinstall/ftp.c
+++ usr.sbin/sysinstall/ftp.c
@@ -118,14 +118,14 @@
     if (variable_get(VAR_FTP_PASS))
 	SAFE_STRCPY(password, variable_get(VAR_FTP_PASS));
     else if (RunningAsInit)
-	sprintf(password, "installer@%s", variable_get(VAR_HOSTNAME));
+	snprintf(password, sizeof(password), "installer@%s", variable_get(VAR_HOSTNAME));
     else {
 	struct passwd *pw;
 	char *user;
 
 	pw = getpwuid(getuid());
 	user = pw ? pw->pw_name : "ftp";
-	sprintf(password, "%s@%s", user, variable_get(VAR_HOSTNAME));
+	snprintf(password, sizeof(password), "%s@%s", user, variable_get(VAR_HOSTNAME));
     }
     af = variable_cmp(VAR_IPV6_ENABLE, "YES") ? AF_INET : AF_UNSPEC;
     msgNotify("Logging in to %s@%s..", login_name, hostname);
@@ -246,17 +246,17 @@
 	    /* Try some alternatives */
 	    switch (nretries++) {
 	    case 1:
-		sprintf(buf, "releases/%s", file);
+		snprintf(buf, sizeof(buf), "releases/%s", file);
 		try = buf;
 		break;
 
 	    case 2:
-		sprintf(buf, "%s/%s", variable_get(VAR_RELNAME), file);
+		snprintf(buf, sizeof(buf), "%s/%s", variable_get(VAR_RELNAME), file);
 		try = buf;
 		break;
 
 	    case 3:
-		sprintf(buf, "%s/releases/%s", variable_get(VAR_RELNAME), file);
+		snprintf(buf, sizeof(buf), "%s/releases/%s", variable_get(VAR_RELNAME), file);
 		try = buf;
 		break;
 


More information about the Midnightbsd-cvs mailing list