This is a general bounded-buffer patch for sysinstall plus it fixes
PR misc/18466 (limited 'device name' size screws up FTP installs).
It does not fix all the potential buffer overflows -- there are still
a lot of strcpy's, but it gets half way there with the introduction
and use of safe_asprintf().
My recommendation is that (eventually) the entire program use asprintf
rather then statically-bounded buffers to hold things.
I don't have time to test this extensively so if the maintainer of
sysinstall wants it (I believe that's you, Jordan!), you'll need to
review it and perhaps test it a little then give me the commit goahead.
Note that simply increasing the DEV_NAME_MAX as a quick solution is
not safe, there are a couple of places where an unbounded sprintf()
was being used with the device name as an argument.
-Matt
Index: anonFTP.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/anonFTP.c,v
retrieving revision 1.29
diff -u -r1.29 anonFTP.c
--- anonFTP.c 2000/01/25 19:16:31 1.29
+++ anonFTP.c 2000/05/14 17:44:11
@@ -168,7 +168,7 @@
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) {
@@ -207,7 +207,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 **/
@@ -217,7 +217,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);
@@ -250,7 +250,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);
@@ -296,7 +296,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: config.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/config.c,v
retrieving revision 1.156.2.1
diff -u -r1.156.2.1 config.c
--- config.c 2000/03/30 08:12:02 1.156.2.1
+++ config.c 2000/05/14 17:46:38
@@ -238,11 +238,11 @@
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
- fprintf(fstab, "/dev/%s\t\t%s\tcd9660\tro,noauto\t0\t0\n", devs[i]->name,
cdname);
+ fprintf(fstab, "/dev/%s\t\t%s\tcd9660\tro,noauto\t0\t0\n", devs[i]->pname,
+cdname);
}
/* And finally, a /proc. */
@@ -364,6 +364,8 @@
}
}
+#define URMSIZE 21
+
/* Set up the make.conf file */
void
configMake_conf(char *config)
@@ -373,8 +375,8 @@
FILE *fp;
if (!file_readable(config)) {
- char *line = malloc(21);
- sprintf(line, "USA_RESIDENT=%s\n", USAResident ? "YES" : "NO");
+ char *line = malloc(URMSIZE);
+ snprintf(line, URMSIZE, "USA_RESIDENT=%s\n", USAResident ? "YES" : "NO");
lines[0] = line;
nlines = 1;
}
@@ -386,7 +388,7 @@
if (!strncmp(lines[i], "USA_RESIDENT", 12)) {
free(lines[i]);
lines[i] = malloc(21); /* big enough */
- sprintf(lines[i], "USA_RESIDENT=%s\n", USAResident ? "YES" : "NO");
+ snprintf(lines[i], URMSIZE, "USA_RESIDENT=%s\n", USAResident ? "YES" :
+"NO");
}
}
}
@@ -865,7 +867,7 @@
vsystem("echo '#' >> /etc/exports");
vsystem("echo '# You should replace these lines with your actual exported
filesystems.' >> /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);
}
Index: devices.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/devices.c,v
retrieving revision 1.117
diff -u -r1.117 devices.c
--- devices.c 2000/03/08 18:14:19 1.117
+++ devices.c 2000/05/14 17:49:02
@@ -132,8 +132,9 @@
dev = safe_malloc(sizeof(Device));
bzero(dev, sizeof(Device));
- if (name)
- SAFE_STRCPY(dev->name, name);
+ if (name == NULL)
+ name = "";
+ safe_asprintf(&dev->pname, "%s", name);
return dev;
}
@@ -408,13 +409,11 @@
close(fd);
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);
+ safe_asprintf(&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);
+ safe_asprintf(&newdesc, cp, "PPP interface", try, j + 1);
deviceRegister("ppp0", newdesc, strdup(try), DEVICE_TYPE_NETWORK,
TRUE, mediaInitNetwork,
NULL, mediaShutdownNetwork, NULL);
if (isDebug())
@@ -440,8 +439,8 @@
if (!d)
msgFatal("Unable to open disk %s", names[i]);
- deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK, FALSE,
- dummyInit, dummyGet, dummyShutdown, d);
+ deviceRegister(names[i], names[i], d->name, DEVICE_TYPE_DISK,
+ FALSE, dummyInit, dummyGet, dummyShutdown, d);
if (isDebug())
msgDebug("Found a disk device named %s\n", names[i]);
@@ -453,11 +452,14 @@
/* Got one! */
snprintf(devname, sizeof devname, "/dev/%s", c1->name);
- dev = deviceRegister(c1->name, c1->name, strdup(devname),
DEVICE_TYPE_DOS, TRUE,
- mediaInitDOS, mediaGetDOS, mediaShutdownDOS,
NULL);
+ dev = deviceRegister(c1->name, c1->name, strdup(devname),
+ DEVICE_TYPE_DOS, TRUE, mediaInitDOS, mediaGetDOS,
+ mediaShutdownDOS, NULL);
dev->private = c1;
- if (isDebug())
- msgDebug("Found a DOS partition %s on drive %s\n", c1->name,
d->name);
+ if (isDebug()) {
+ msgDebug("Found a DOS partition %s on drive %s\n",
+ c1->name, d->name);
+ }
}
}
}
@@ -487,7 +489,7 @@
j = 0;
for (i = 0; i < numDevs; i++) {
- if ((!name || !strcmp(Devices[i]->name, name))
+ if ((!name || !strcmp(Devices[i]->pname, name))
&& (class == DEVICE_TYPE_ANY || class == Devices[i]->type))
found[j++] = Devices[i];
}
@@ -503,7 +505,7 @@
j = 0;
for (i = 0; i < numDevs; i++) {
- if ((!name || !strcmp(Devices[i]->name, name)) &&
+ if ((!name || !strcmp(Devices[i]->pname, name)) &&
(!desc || !strcmp(Devices[i]->description, desc)) &&
(class == DEVICE_TYPE_ANY || class == Devices[i]->type))
found[j++] = Devices[i];
@@ -543,7 +545,7 @@
tmp = (DMenu *)safe_malloc(sizeof(DMenu) + (sizeof(dialogMenuItem) * (numdevs +
1)));
bcopy(menu, tmp, sizeof(DMenu));
for (i = 0; devs[i]; i++) {
- tmp->items[i].prompt = devs[i]->name;
+ tmp->items[i].prompt = devs[i]->pname;
for (j = 0; j < numDevs; j++) {
if (devs[i] == Devices[j]) {
tmp->items[i].title = Devices[j]->description;
Index: disks.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/disks.c,v
retrieving revision 1.118
diff -u -r1.118 disks.c
--- disks.c 2000/02/29 10:40:57 1.118
+++ disks.c 2000/05/14 17:49:17
@@ -146,7 +146,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);
}
Index: dist.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/dist.c,v
retrieving revision 1.175.2.1
diff -u -r1.175.2.1 dist.c
--- dist.c 2000/03/18 08:39:45 1.175.2.1
+++ dist.c 2000/05/14 17:57:59
@@ -831,7 +831,7 @@
else if (me[i].my_bit != DIST_LOCAL) {
status = msgYesNo("Unable to transfer the %s distribution
from\n%s.\n\n"
"Do you want to try to retrieve it again?",
- me[i].my_name, mediaDevice->name);
+ me[i].my_name, mediaDevice->pname);
if (!status)
--i;
}
@@ -849,7 +849,7 @@
}
static void
-printSelected(char *buf, int selected, Distribution *me, int *col)
+printSelected(char *buf, int bufSize, int selected, Distribution *me, int *col)
{
int i;
@@ -869,10 +869,10 @@
*col = 0;
strcat(buf, "\n");
}
- sprintf(&buf[strlen(buf)], " %s", me[i].my_name);
+ snprintf(&buf[strlen(buf)], bufSize - strlen(buf), " %s", me[i].my_name);
/* Recurse if have a sub-distribution */
if (me[i].my_dist)
- printSelected(buf, *(me[i].my_mask), me[i].my_dist, col);
+ printSelected(buf, bufSize, *(me[i].my_mask), me[i].my_dist, col);
}
}
@@ -934,7 +934,7 @@
buf[0] = '\0';
dialog_clear_norefresh();
- printSelected(buf, Dists, DistTable, &col);
+ printSelected(buf, sizeof(buf), Dists, DistTable, &col);
dialog_clear_norefresh();
if (col) {
msgConfirm("Couldn't extract the following distributions. This may\n"
Index: doc.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/doc.c,v
retrieving revision 1.29
diff -u -r1.29 doc.c
--- doc.c 2000/02/26 12:35:00 1.29
+++ doc.c 2000/05/14 17:56:30
@@ -113,7 +113,7 @@
where = strcpy(target, "http://www.freebsd.org/handbook");
}
if (where) {
- sprintf(tmp, "%s %s", browser, target);
+ snprintf(tmp, sizeof(tmp), "%s %s", browser, target);
systemExecute(tmp);
return DITEM_SUCCESS;
}
Index: floppy.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/floppy.c,v
retrieving revision 1.34
diff -u -r1.34 floppy.c
--- floppy.c 1999/08/28 01:34:12 1.34
+++ floppy.c 2000/05/14 17:28:52
@@ -95,7 +95,7 @@
if (mount("msdos", mp, MNT_RDONLY, (caddr_t)&dosargs) == -1) {
if (mount("ufs", mp, MNT_RDONLY, (caddr_t)&u_args) == -1) {
msgConfirm("Error mounting floppy %s (%s) on %s : %s",
- dev->name, dev->devname, mp, strerror(errno));
+ dev->pname, dev->devname, mp, strerror(errno));
return FALSE;
}
}
Index: ftp.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/ftp.c,v
retrieving revision 1.37
diff -u -r1.37 ftp.c
--- ftp.c 1999/08/28 01:34:13 1.37
+++ ftp.c 2000/05/14 17:50:45
@@ -112,14 +112,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));
}
msgNotify("Logging in to %s@%s..", login_name, hostname);
if ((OpenConn = ftpLogin(hostname, login_name, password, FtpPort, isDebug(),
&code)) == NULL) {
@@ -216,17 +216,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;
Index: http.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/http.c,v
retrieving revision 1.2
diff -u -r1.2 http.c
--- http.c 2000/01/25 05:56:48 1.2
+++ http.c 2000/05/14 17:50:57
@@ -50,7 +50,7 @@
return FALSE;
}
- sprintf(req,"GET / HTTP/1.0\r\n\r\n");
+ snprintf(req, sizeof(req), "GET / HTTP/1.0\r\n\r\n");
write(s,req,strlen(req));
/*
* scan the headers of the response
@@ -119,7 +119,7 @@
return NULL;
}
- sprintf(req,"GET %s/%s/%s%s HTTP/1.0\r\n\r\n",
+ snprintf(req, sizeof(req), "GET %s/%s/%s%s HTTP/1.0\r\n\r\n",
variable_get(VAR_FTP_PATH), variable_get(VAR_RELNAME),
file, variable_get(VAR_HTTP_FTP_MODE));
Index: install.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/install.c,v
retrieving revision 1.268.2.3
diff -u -r1.268.2.3 install.c
--- install.c 2000/03/18 20:13:47 1.268.2.3
+++ install.c 2000/05/14 17:51:28
@@ -535,9 +535,9 @@
if (!msgYesNo("Would you like to configure any Ethernet or SLIP/PPP network
devices?")) {
Device *tmp = tcpDeviceSelect();
- if (tmp && !((DevInfo *)tmp->private)->use_dhcp && !msgYesNo("Would you
like to bring the %s interface up right now?", tmp->name))
+ if (tmp && !((DevInfo *)tmp->private)->use_dhcp && !msgYesNo("Would you
+like to bring the %s interface up right now?", tmp->pname))
if (!tmp->init(tmp))
- msgConfirm("Initialization of %s device failed.", tmp->name);
+ msgConfirm("Initialization of %s device failed.", tmp->pname);
}
dialog_clear_norefresh();
}
@@ -907,7 +907,7 @@
command_clear();
if (swapdev && RunningAsInit) {
/* As the very first thing, try to get ourselves some swap space */
- sprintf(dname, "/dev/%s", swapdev->name);
+ snprintf(dname, sizeof(dname), "/dev/%s", swapdev->name);
if (!Fake && (!MakeDevChunk(swapdev, "/dev") || !file_readable(dname))) {
msgConfirm("Unable to make device node for %s in /dev!\n"
"The creation of filesystems will be aborted.", dname);
@@ -929,7 +929,7 @@
if (rootdev && RunningAsInit) {
/* Next, create and/or mount the root device */
- sprintf(dname, "/dev/r%s", rootdev->name);
+ snprintf(dname, sizeof(dname), "/dev/r%s", rootdev->name);
if (!Fake && (!MakeDevChunk(rootdev, "/dev") || !file_readable(dname))) {
msgConfirm("Unable to make device node for %s in /dev!\n"
"The creation of filesystems will be aborted.", dname);
@@ -964,7 +964,7 @@
}
/* Switch to block device */
- sprintf(dname, "/dev/%s", rootdev->name);
+ snprintf(dname, sizeof(dname), "/dev/%s", rootdev->name);
if (Mount("/mnt", dname)) {
msgConfirm("Unable to mount the root file system on %s! Giving up.",
dname);
return DITEM_FAILURE | DITEM_RESTORE;
@@ -1012,7 +1012,7 @@
if (c2 == swapdev)
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();
@@ -1027,7 +1027,7 @@
else if (c1->type == fat && c1->private_data && (root->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);
}
}
Index: label.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/label.c,v
retrieving revision 1.98
diff -u -r1.98 label.c
--- label.c 2000/02/29 10:40:59 1.98
+++ label.c 2000/05/14 17:51:49
@@ -899,7 +899,7 @@
char osize[80];
u_long flags = 0;
- sprintf(osize, "%d", sz);
+ snprintf(osize, sizeof(osize), "%d", sz);
val = msgGetInput(osize,
"Please specify the partition size in blocks or
append a trailing G for\n"
"gigabytes, M for megabytes, or C for cylinders.\n"
@@ -1095,7 +1095,7 @@
if (!devs[i]->enabled)
continue;
- else if ((d = Open_Disk(devs[i]->name)) != NULL) {
+ else if ((d = Open_Disk(devs[i]->pname)) != NULL) {
Free_Disk(devs[i]->private);
devs[i]->private = d;
diskPartition(devs[i]);
@@ -1160,7 +1160,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;
}
Index: media.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/media.c,v
retrieving revision 1.107
diff -u -r1.107 media.c
--- media.c 2000/01/25 05:56:49 1.107
+++ media.c 2000/05/14 17:52:24
@@ -351,7 +351,12 @@
variable_unset(VAR_FTP_PATH);
return DITEM_FAILURE;
}
- SAFE_STRCPY(ftpDevice.name, cp);
+ if (ftpDevice.pname) {
+ free(ftpDevice.pname);
+ ftpDevice.pname = NULL;
+ }
+ safe_asprintf(&ftpDevice.pname, "%s", cp);
+
SAFE_STRCPY(hostname, cp + 6);
if (!networkDev || msgYesNo("You've already done the network configuration
once,\n"
@@ -489,10 +494,14 @@
return DITEM_FAILURE;
/* If they gave us a CDROM or something, try and pick a better name */
+ if (ufsDevice.pname) {
+ free(ufsDevice.pname);
+ ufsDevice.pname = NULL;
+ }
if (statfs(cp, &st))
- strcpy(ufsDevice.name, "ufs");
+ safe_asprintf(&ufsDevice.pname, "ufs");
else
- strcpy(ufsDevice.name, st.f_fstypename);
+ safe_asprintf(&ufsDevice.pname, "%s", st.f_fstypename);
ufsDevice.type = DEVICE_TYPE_UFS;
ufsDevice.init = dummyInit;
@@ -522,8 +531,12 @@
msgConfirm("Invalid NFS path specification. Must be of the form:\n"
"host:/full/pathname/to/FreeBSD/distdir");
return DITEM_FAILURE;
+ }
+ if (nfsDevice.pname) {
+ free(nfsDevice.pname);
+ nfsDevice.pname = NULL;
}
- SAFE_STRCPY(nfsDevice.name, hostname);
+ safe_asprintf(&nfsDevice.pname, "%s", hostname);
*idx = '\0';
if (!networkDev || msgYesNo("You've already done the network configuration
once,\n"
"would you like to skip over it now?") != 0) {
Index: misc.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/misc.c,v
retrieving revision 1.40
diff -u -r1.40 misc.c
--- misc.c 1999/11/27 14:33:07 1.40
+++ misc.c 2000/05/14 17:55:41
@@ -34,6 +34,7 @@
#include "sysinstall.h"
#include <ctype.h>
#include <unistd.h>
+#include <stdarg.h>
#include <sys/stat.h>
#include <sys/errno.h>
#include <sys/file.h>
@@ -209,6 +210,17 @@
if (!ptr)
msgFatal("Out of memory!");
return ptr;
+}
+
+void
+safe_asprintf(char **pptr, const char *ctl, ...)
+{
+ va_list va;
+
+ va_start(va, ctl);
+ if (vasprintf(pptr, ctl, va) < 0)
+ msgFatal("Out of memory!");
+ va_end(va);
}
/* Create a path biased from the VAR_INSTALL_ROOT variable (if not /) */
Index: network.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/network.c,v
retrieving revision 1.46
diff -u -r1.46 network.c
--- network.c 1999/12/17 02:46:04 1.46
+++ network.c 2000/05/14 17:36:20
@@ -61,7 +61,7 @@
return TRUE;
if (isDebug())
- msgDebug("Init routine called for network device %s.\n", dev->name);
+ msgDebug("Init routine called for network device %s.\n", dev->pname);
if (!file_readable("/etc/resolv.conf")) {
if (DITEM_STATUS(configResolv(NULL)) == DITEM_FAILURE) {
@@ -79,7 +79,7 @@
kill(pppPID, SIGTERM);
pppPID = 0;
}
- if (!strncmp("ppp", dev->name, 3)) { /* PPP? */
+ if (!strncmp("ppp", dev->pname, 3)) { /* PPP? */
if (!(pppPID = startPPP(dev))) {
msgConfirm("Unable to start PPP! This installation method cannot be
used.");
return FALSE;
@@ -87,7 +87,7 @@
networkInitialized = TRUE;
return TRUE;
}
- else if (!strncmp("sl", dev->name, 2)) { /* SLIP? */
+ else if (!strncmp("sl", dev->pname, 2)) { /* SLIP? */
char *val;
char attach[256];
@@ -123,20 +123,20 @@
restorescr(w);
}
- snprintf(ifconfig, 255, "%s%s", VAR_IFCONFIG, dev->name);
+ snprintf(ifconfig, sizeof(ifconfig), "%s%s", VAR_IFCONFIG, dev->pname);
cp = variable_get(ifconfig);
if (!cp) {
msgConfirm("The %s device is not configured. You will need to do so\n"
- "in the Networking configuration menu before proceeding.",
dev->name);
+ "in the Networking configuration menu before proceeding.",
+dev->pname);
return FALSE;
}
else if (!strcmp(cp, "DHCP"))
goto bail;
- msgDebug("ifconfig %s %s", dev->name, cp);
- i = vsystem("ifconfig %s %s", dev->name, cp);
+ msgDebug("ifconfig %s %s", dev->pname, cp);
+ i = vsystem("ifconfig %s %s", dev->pname, cp);
if (i) {
msgConfirm("Unable to configure the %s interface!\n"
- "This installation method cannot be used.", dev->name);
+ "This installation method cannot be used.", dev->pname);
return FALSE;
}
@@ -164,20 +164,20 @@
if (!RunningAsInit || !networkInitialized)
return;
- msgDebug("Shutdown called for network device %s\n", dev->name);
+ msgDebug("Shutdown called for network device %s\n", dev->pname);
/* Not a serial device? */
- if (strncmp("sl", dev->name, 2) && strncmp("ppp", dev->name, 3)) {
+ if (strncmp("sl", dev->pname, 2) && strncmp("ppp", dev->pname, 3)) {
int i;
char ifconfig[255];
- snprintf(ifconfig, 255, "%s%s", VAR_IFCONFIG, dev->name);
+ snprintf(ifconfig, sizeof(ifconfig), "%s%s", VAR_IFCONFIG, dev->pname);
cp = variable_get(ifconfig);
if (!cp)
return;
- msgDebug("ifconfig %s down", dev->name);
- i = vsystem("ifconfig %s down", dev->name);
+ msgDebug("ifconfig %s down", dev->pname);
+ i = vsystem("ifconfig %s down", dev->pname);
if (i)
- msgConfirm("Warning: Unable to down the %s interface properly", dev->name);
+ msgConfirm("Warning: Unable to down the %s interface properly",
+dev->pname);
cp = variable_get(VAR_GATEWAY);
if (cp) {
msgDebug("Deleting default route.");
Index: nfs.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/nfs.c,v
retrieving revision 1.21
diff -u -r1.21 nfs.c
--- nfs.c 1999/12/17 02:46:04 1.21
+++ nfs.c 2000/05/14 17:36:36
@@ -59,11 +59,11 @@
if (Mkdir(mountpoint))
return FALSE;
- msgNotify("Mounting %s over NFS on %s", dev->name, mountpoint);
+ msgNotify("Mounting %s over NFS on %s", dev->pname, mountpoint);
if (vsystem("mount_nfs %s %s %s %s",
variable_get(VAR_SLOW_ETHER) ? "-r 1024 -w 1024" : "",
- variable_get(VAR_NFS_SECURE) ? "-P" : "", dev->name, mountpoint)) {
- msgConfirm("Error mounting %s on %s: %s.", dev->name, mountpoint,
strerror(errno));
+ variable_get(VAR_NFS_SECURE) ? "-P" : "", dev->pname, mountpoint)) {
+ msgConfirm("Error mounting %s on %s: %s.", dev->pname, mountpoint,
+strerror(errno));
if (netDevice)
netDevice->shutdown(netDevice);
restorescr(w);
@@ -71,7 +71,7 @@
}
NFSMounted = TRUE;
if (isDebug())
- msgDebug("Mounted NFS device %s onto %s\n", dev->name, mountpoint);
+ msgDebug("Mounted NFS device %s onto %s\n", dev->pname, mountpoint);
restorescr(w);
return TRUE;
}
Index: options.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/options.c,v
retrieving revision 1.70
diff -u -r1.70 options.c
--- options.c 1999/12/19 20:41:06 1.70
+++ options.c 2000/05/14 17:52:30
@@ -165,7 +165,7 @@
return (char *)opt.data;
case OPT_IS_INT:
- sprintf(ival, "%d", (int)opt.data);
+ snprintf(ival, sizeof(ival), "%d", (int)opt.data);
return ival;
case OPT_IS_FUNC:
Index: package.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/package.c,v
retrieving revision 1.90.2.1
diff -u -r1.90.2.1 package.c
--- package.c 2000/03/18 08:45:35 1.90.2.1
+++ package.c 2000/05/14 17:52:48
@@ -144,12 +144,12 @@
if (!index(name, '/')) {
if (!strpbrk(name, "-_"))
- sprintf(path, "packages/Latest/%s.tgz", name);
+ snprintf(path, sizeof(path), "packages/Latest/%s.tgz", name);
else
- sprintf(path, "packages/All/%s%s", name, strstr(name, ".tgz") ? "" :
".tgz");
+ snprintf(path, sizeof(path), "packages/All/%s%s", name, strstr(name,
+".tgz") ? "" : ".tgz");
}
else
- sprintf(path, "%s%s", name, strstr(name, ".tgz") ? "" : ".tgz");
+ snprintf(path, sizeof(path), "%s%s", name, strstr(name, ".tgz") ? "" : ".tgz");
/* We have a path, call the device strategy routine to get the file */
fp = dev->get(dev, path, TRUE);
@@ -162,7 +162,7 @@
signal(SIGPIPE, catch_pipe);
dialog_clear_norefresh();
- msgNotify("Adding %s%s\nfrom %s", path, depended ? " (as a dependency)" : "",
dev->name);
+ msgNotify("Adding %s%s\nfrom %s", path, depended ? " (as a dependency)" : "",
+dev->pname);
pipe(pfd);
pid = fork();
if (!pid) {
Index: pccard.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/pccard.c,v
retrieving revision 1.10
diff -u -r1.10 pccard.c
--- pccard.c 2000/01/14 19:05:55 1.10
+++ pccard.c 2000/05/14 17:52:56
@@ -79,7 +79,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",
Index: sysinstall.h
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/sysinstall.h,v
retrieving revision 1.186
diff -u -r1.186 sysinstall.h
--- sysinstall.h 2000/03/12 03:57:26 1.186
+++ sysinstall.h 2000/05/14 17:56:04
@@ -55,7 +55,6 @@
/*** Defines ***/
/* device limits */
-#define DEV_NAME_MAX 64 /* The maximum length of a device name */
#define DEV_MAX 100 /* The maximum number of devices we'll
deal with */
#define INTERFACE_MAX 50 /* Maximum number of network interfaces we'll
deal with */
#define IO_ERROR -2 /* Status code for I/O error rather than
normal EOF */
@@ -250,7 +249,7 @@
/* A "device" from sysinstall's point of view */
typedef struct _device {
- char name[DEV_NAME_MAX];
+ char *pname;
char *description;
char *devname;
DeviceType type;
@@ -640,6 +639,7 @@
extern void safe_free(void *ptr);
extern void *safe_malloc(size_t size);
extern void *safe_realloc(void *orig, size_t size);
+extern void safe_asprintf(char **pptr, const char *ctl, ...);
extern dialogMenuItem *item_add(dialogMenuItem *list, char *prompt, char *title,
int (*checked)(dialogMenuItem *self),
int (*fire)(dialogMenuItem *self),
Index: tape.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/tape.c,v
retrieving revision 1.22
diff -u -r1.22 tape.c
--- tape.c 1999/12/17 02:46:04 1.22
+++ tape.c 2000/05/14 17:53:07
@@ -70,7 +70,7 @@
if (!tapeInitted) {
WINDOW *w = savescr();
- msgDebug("Tape init routine called for %s (private dir is %s)\n", dev->name,
dev->private);
+ msgDebug("Tape init routine called for %s (private dir is %s)\n", dev->pname,
+dev->private);
Mkdir(dev->private);
if (chdir(dev->private)) {
msgConfirm("Unable to CD to %s before extracting tape!\n"
@@ -79,7 +79,7 @@
}
/* We know the tape is already in the drive, so go for it */
msgNotify("First extracting distributions from %s...", dev->description);
- if (!strcmp(dev->name, "rft0"))
+ if (!strcmp(dev->pname, "rft0"))
i = vsystem("ft | cpio -idum %s --block-size %s", cpioVerbosity(),
mediaTapeBlocksize());
else
i = vsystem("cpio -idum %s --block-size %s -I %s", cpioVerbosity(),
mediaTapeBlocksize(), dev->devname);
@@ -96,13 +96,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: tcpip.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/tcpip.c,v
retrieving revision 1.103
diff -u -r1.103 tcpip.c
--- tcpip.c 2000/02/20 21:58:10 1.103
+++ tcpip.c 2000/05/14 17:53:32
@@ -157,7 +157,7 @@
int i, j;
/* Bah, now we have to kludge getting the information from ifconfig */
- snprintf(cmd, sizeof cmd, "ifconfig %s", devp->name);
+ snprintf(cmd, sizeof cmd, "ifconfig %s", devp->pname);
ifp = popen(cmd, "r");
if (ifp) {
j = fread(data, 1, sizeof(data), ifp);
@@ -224,7 +224,7 @@
Mkdir("/var/run");
Mkdir("/tmp");
msgNotify("Scanning for DHCP servers...");
- if (0 == vsystem("dhclient -1 %s", devp->name)) {
+ if (0 == vsystem("dhclient -1 %s", devp->pname)) {
dhcpGetInfo(devp);
use_dhcp = TRUE;
}
@@ -240,7 +240,7 @@
if (!ipaddr[0]) {
if ((cp = variable_get(VAR_IPADDR)) != NULL)
SAFE_STRCPY(ipaddr, cp);
- else if ((cp = variable_get(string_concat3(devp->name, "_", VAR_IPADDR)))
!= NULL)
+ else if ((cp = variable_get(string_concat3(devp->pname, "_", VAR_IPADDR)))
+!= NULL)
SAFE_STRCPY(ipaddr, cp);
}
@@ -248,7 +248,7 @@
if (!netmask[0]) {
if ((cp = variable_get(VAR_NETMASK)) != NULL)
SAFE_STRCPY(netmask, cp);
- else if ((cp = variable_get(string_concat3(devp->name, "_", VAR_NETMASK)))
!= NULL)
+ else if ((cp = variable_get(string_concat3(devp->pname, "_",
+VAR_NETMASK))) != NULL)
SAFE_STRCPY(netmask, cp);
}
@@ -256,7 +256,7 @@
if (!extras[0]) {
if ((cp = variable_get(VAR_EXTRAS)) != NULL)
SAFE_STRCPY(extras, cp);
- else if ((cp = variable_get(string_concat3(devp->name, "_", VAR_EXTRAS)))
!= NULL)
+ else if ((cp = variable_get(string_concat3(devp->pname, "_", VAR_EXTRAS)))
+!= NULL)
SAFE_STRCPY(extras, cp);
}
}
@@ -310,7 +310,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->pname);
mvwaddstr(ds_win, TCP_DIALOG_Y + 9, TCP_DIALOG_X + 14, title);
/* Some more initialisation before we go into the main input loop */
@@ -383,11 +383,11 @@
SAFE_STRCPY(di->extras, extras);
di->use_dhcp = use_dhcp;
- sprintf(ifn, "%s%s", VAR_IFCONFIG, devp->name);
+ snprintf(ifn, sizeof(ifn), "%s%s", VAR_IFCONFIG, devp->pname);
if (use_dhcp)
- sprintf(temp, "DHCP");
+ snprintf(temp, sizeof(temp), "DHCP");
else
- sprintf(temp, "inet %s %s netmask %s", ipaddr, extras, netmask);
+ snprintf(temp, sizeof(temp), "inet %s %s netmask %s", ipaddr, extras,
+netmask);
variable_set2(ifn, temp, 1);
pccard = variable_get("_pccard_install");
if (pccard && strcmp(pccard, "YES") == 0) {
@@ -397,8 +397,8 @@
if (!ifaces)
variable_set2(VAR_INTERFACES, ifaces = "lo0", 1);
/* Only add it if it's not there already */
- if (strcmp(ifaces, "auto") && !strstr(ifaces, devp->name)) {
- sprintf(ifn, "%s %s", devp->name, ifaces);
+ if (strcmp(ifaces, "auto") && !strstr(ifaces, devp->pname)) {
+ snprintf(ifn, sizeof(ifn), "%s %s", devp->pname, ifaces);
variable_set2(VAR_INTERFACES, ifn, 1);
}
if (!use_dhcp)
@@ -481,8 +481,8 @@
Device *tmp;
tmp = tcpDeviceSelect();
- if (tmp && tmp->private && !((DevInfo *)tmp->private)->use_dhcp &&
!msgYesNo("Would you like to bring the %s interface up right now?", tmp->name))
+ if (tmp && tmp->private && !((DevInfo *)tmp->private)->use_dhcp &&
+!msgYesNo("Would you like to bring the %s interface up right now?", tmp->pname))
if (!tmp->init(tmp))
- msgConfirm("Initialization of %s device failed.", tmp->name);
+ msgConfirm("Initialization of %s device failed.", tmp->pname);
return DITEM_SUCCESS;
}
Index: wizard.c
===================================================================
RCS file: /home/ncvs/src/release/sysinstall/wizard.c,v
retrieving revision 1.15
diff -u -r1.15 wizard.c
--- wizard.c 1999/08/28 01:34:22 1.15
+++ wizard.c 2000/05/14 17:53:40
@@ -70,7 +70,7 @@
char **cp,*cmds[200];
int ncmd,i;
- sprintf(myprompt,"%s> ", d->name);
+ snprintf(myprompt, sizeof(myprompt), "%s> ", d->name);
while(1) {
printf("--==##==--\n");
Debug_Disk(d);
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message