Apply last_patch46 from vodz, to fix buffer overflows noted by

Gerardo Puga, and to optimize for size a little bit.  Thanks vodz
This commit is contained in:
Eric Andersen 2002-06-22 17:20:50 +00:00
parent 61f83059c1
commit 8b1aa4d749

View File

@ -188,10 +188,15 @@ do_mount(char *specialfile, char *dir, char *filesystemtype,
} }
static void paste_str(char **s1, const char *s2)
{
*s1 = xrealloc(*s1, strlen(*s1)+strlen(s2)+1);
strcat(*s1, s2);
}
/* Seperate standard mount options from the nonstandard string options */ /* Seperate standard mount options from the nonstandard string options */
static void static void
parse_mount_options(char *options, int *flags, char *strflags) parse_mount_options(char *options, int *flags, char **strflags)
{ {
while (options) { while (options) {
int gotone = FALSE; int gotone = FALSE;
@ -212,20 +217,16 @@ parse_mount_options(char *options, int *flags, char *strflags)
f++; f++;
} }
#if defined CONFIG_FEATURE_MOUNT_LOOP #if defined CONFIG_FEATURE_MOUNT_LOOP
if (! gotone && !strcasecmp("loop", options)) { /* loop device support */ if (!strcasecmp("loop", options)) { /* loop device support */
use_loop = TRUE; use_loop = TRUE;
gotone = TRUE; gotone = TRUE;
} }
#endif #endif
if (*strflags && strflags != '\0' && ! gotone) { if (! gotone) {
char *temp = strflags; if (**strflags) /* have previous parsed options */
paste_str(strflags, ",");
temp += strlen(strflags); paste_str(strflags, options);
*temp++ = ',';
*temp++ = '\0';
} }
if (! gotone)
strcat(strflags, options);
if (comma) { if (comma) {
*comma = ','; *comma = ',';
options = ++comma; options = ++comma;
@ -310,7 +311,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
return (TRUE); return (TRUE);
} }
void show_mounts(void) static void show_mounts(void)
{ {
#if defined CONFIG_FEATURE_USE_DEVPS_PATCH #if defined CONFIG_FEATURE_USE_DEVPS_PATCH
int fd, i, numfilesystems; int fd, i, numfilesystems;
@ -375,25 +376,25 @@ void show_mounts(void)
extern int mount_main(int argc, char **argv) extern int mount_main(int argc, char **argv)
{ {
struct stat statbuf; struct stat statbuf;
char string_flags_buf[1024] = ""; char *string_flags = xstrdup("");
char *string_flags = string_flags_buf; char *extra_opts;
char *extra_opts = string_flags_buf;
int flags = 0; int flags = 0;
char *filesystemType = "auto"; char *filesystemType = "auto";
char *device = xmalloc(PATH_MAX); char *device = xmalloc(PATH_MAX);
char *directory = xmalloc(PATH_MAX); char *directory = xmalloc(PATH_MAX);
struct mntent *m = NULL;
int all = FALSE; int all = FALSE;
int fakeIt = FALSE; int fakeIt = FALSE;
int useMtab = TRUE; int useMtab = TRUE;
int rc = EXIT_FAILURE; int rc = EXIT_FAILURE;
int fstabmount = FALSE; FILE *f = 0;
int opt; int opt;
/* Parse options */ /* Parse options */
while ((opt = getopt(argc, argv, "o:rt:wafnv")) > 0) { while ((opt = getopt(argc, argv, "o:rt:wafnv")) > 0) {
switch (opt) { switch (opt) {
case 'o': case 'o':
parse_mount_options(optarg, &flags, string_flags); parse_mount_options(optarg, &flags, &string_flags);
break; break;
case 'r': case 'r':
flags |= MS_RDONLY; flags |= MS_RDONLY;
@ -437,9 +438,7 @@ extern int mount_main(int argc, char **argv)
directory = simplify_path(argv[optind + 1]); directory = simplify_path(argv[optind + 1]);
if (all || optind + 1 == argc) { if (all || optind + 1 == argc) {
struct mntent *m = NULL; f = setmntent("/etc/fstab", "r");
FILE *f = setmntent("/etc/fstab", "r");
fstabmount = TRUE;
if (f == NULL) if (f == NULL)
perror_msg_and_die( "\nCannot read /etc/fstab"); perror_msg_and_die( "\nCannot read /etc/fstab");
@ -460,16 +459,15 @@ extern int mount_main(int argc, char **argv)
if (all || flags == 0) { // Allow single mount to override fstab flags if (all || flags == 0) { // Allow single mount to override fstab flags
flags = 0; flags = 0;
string_flags = string_flags_buf; string_flags[0] = 0;
*string_flags = '\0'; parse_mount_options(m->mnt_opts, &flags, &string_flags);
parse_mount_options(m->mnt_opts, &flags, string_flags);
} }
strcpy(device, m->mnt_fsname); strcpy(device, m->mnt_fsname);
strcpy(directory, m->mnt_dir); strcpy(directory, m->mnt_dir);
filesystemType = xstrdup(m->mnt_type); filesystemType = xstrdup(m->mnt_type);
singlemount: singlemount:
string_flags = xstrdup(string_flags); extra_opts = string_flags;
rc = EXIT_SUCCESS; rc = EXIT_SUCCESS;
#ifdef CONFIG_NFSMOUNT #ifdef CONFIG_NFSMOUNT
if (strchr(device, ':') != NULL) { if (strchr(device, ':') != NULL) {
@ -488,10 +486,10 @@ singlemount:
if (! all) if (! all)
break; break;
} }
if (fstabmount) if (f)
endmntent(f); endmntent(f);
if (! all && fstabmount && m == NULL) if (! all && f && m == NULL)
fprintf(stderr, "Can't find %s in /etc/fstab\n", device); fprintf(stderr, "Can't find %s in /etc/fstab\n", device);
return rc; return rc;