diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-06-22 17:20:50 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-06-22 17:20:50 +0000 |
commit | 8b1aa4d74961cc89f03ff39e036928431dc8d6ce (patch) | |
tree | 737352f92ff02b4530e5f4470a3a7403eccf82c6 | |
parent | 61f83059c1785094bb9f4aad5388166e304dc262 (diff) | |
download | busybox-w32-8b1aa4d74961cc89f03ff39e036928431dc8d6ce.tar.gz busybox-w32-8b1aa4d74961cc89f03ff39e036928431dc8d6ce.tar.bz2 busybox-w32-8b1aa4d74961cc89f03ff39e036928431dc8d6ce.zip |
Apply last_patch46 from vodz, to fix buffer overflows noted by
Gerardo Puga, and to optimize for size a little bit. Thanks vodz
-rw-r--r-- | util-linux/mount.c | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index d58eecaeb..7e91aed63 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -188,10 +188,15 @@ do_mount(char *specialfile, char *dir, char *filesystemtype, | |||
188 | } | 188 | } |
189 | 189 | ||
190 | 190 | ||
191 | static void paste_str(char **s1, const char *s2) | ||
192 | { | ||
193 | *s1 = xrealloc(*s1, strlen(*s1)+strlen(s2)+1); | ||
194 | strcat(*s1, s2); | ||
195 | } | ||
191 | 196 | ||
192 | /* Seperate standard mount options from the nonstandard string options */ | 197 | /* Seperate standard mount options from the nonstandard string options */ |
193 | static void | 198 | static void |
194 | parse_mount_options(char *options, int *flags, char *strflags) | 199 | parse_mount_options(char *options, int *flags, char **strflags) |
195 | { | 200 | { |
196 | while (options) { | 201 | while (options) { |
197 | int gotone = FALSE; | 202 | int gotone = FALSE; |
@@ -212,20 +217,16 @@ parse_mount_options(char *options, int *flags, char *strflags) | |||
212 | f++; | 217 | f++; |
213 | } | 218 | } |
214 | #if defined CONFIG_FEATURE_MOUNT_LOOP | 219 | #if defined CONFIG_FEATURE_MOUNT_LOOP |
215 | if (! gotone && !strcasecmp("loop", options)) { /* loop device support */ | 220 | if (!strcasecmp("loop", options)) { /* loop device support */ |
216 | use_loop = TRUE; | 221 | use_loop = TRUE; |
217 | gotone = TRUE; | 222 | gotone = TRUE; |
218 | } | 223 | } |
219 | #endif | 224 | #endif |
220 | if (*strflags && strflags != '\0' && ! gotone) { | 225 | if (! gotone) { |
221 | char *temp = strflags; | 226 | if (**strflags) /* have previous parsed options */ |
222 | 227 | paste_str(strflags, ","); | |
223 | temp += strlen(strflags); | 228 | paste_str(strflags, options); |
224 | *temp++ = ','; | ||
225 | *temp++ = '\0'; | ||
226 | } | 229 | } |
227 | if (! gotone) | ||
228 | strcat(strflags, options); | ||
229 | if (comma) { | 230 | if (comma) { |
230 | *comma = ','; | 231 | *comma = ','; |
231 | options = ++comma; | 232 | options = ++comma; |
@@ -310,7 +311,7 @@ mount_one(char *blockDevice, char *directory, char *filesystemType, | |||
310 | return (TRUE); | 311 | return (TRUE); |
311 | } | 312 | } |
312 | 313 | ||
313 | void show_mounts(void) | 314 | static void show_mounts(void) |
314 | { | 315 | { |
315 | #if defined CONFIG_FEATURE_USE_DEVPS_PATCH | 316 | #if defined CONFIG_FEATURE_USE_DEVPS_PATCH |
316 | int fd, i, numfilesystems; | 317 | int fd, i, numfilesystems; |
@@ -375,25 +376,25 @@ void show_mounts(void) | |||
375 | extern int mount_main(int argc, char **argv) | 376 | extern int mount_main(int argc, char **argv) |
376 | { | 377 | { |
377 | struct stat statbuf; | 378 | struct stat statbuf; |
378 | char string_flags_buf[1024] = ""; | 379 | char *string_flags = xstrdup(""); |
379 | char *string_flags = string_flags_buf; | 380 | char *extra_opts; |
380 | char *extra_opts = string_flags_buf; | ||
381 | int flags = 0; | 381 | int flags = 0; |
382 | char *filesystemType = "auto"; | 382 | char *filesystemType = "auto"; |
383 | char *device = xmalloc(PATH_MAX); | 383 | char *device = xmalloc(PATH_MAX); |
384 | char *directory = xmalloc(PATH_MAX); | 384 | char *directory = xmalloc(PATH_MAX); |
385 | struct mntent *m = NULL; | ||
385 | int all = FALSE; | 386 | int all = FALSE; |
386 | int fakeIt = FALSE; | 387 | int fakeIt = FALSE; |
387 | int useMtab = TRUE; | 388 | int useMtab = TRUE; |
388 | int rc = EXIT_FAILURE; | 389 | int rc = EXIT_FAILURE; |
389 | int fstabmount = FALSE; | 390 | FILE *f = 0; |
390 | int opt; | 391 | int opt; |
391 | 392 | ||
392 | /* Parse options */ | 393 | /* Parse options */ |
393 | while ((opt = getopt(argc, argv, "o:rt:wafnv")) > 0) { | 394 | while ((opt = getopt(argc, argv, "o:rt:wafnv")) > 0) { |
394 | switch (opt) { | 395 | switch (opt) { |
395 | case 'o': | 396 | case 'o': |
396 | parse_mount_options(optarg, &flags, string_flags); | 397 | parse_mount_options(optarg, &flags, &string_flags); |
397 | break; | 398 | break; |
398 | case 'r': | 399 | case 'r': |
399 | flags |= MS_RDONLY; | 400 | flags |= MS_RDONLY; |
@@ -437,9 +438,7 @@ extern int mount_main(int argc, char **argv) | |||
437 | directory = simplify_path(argv[optind + 1]); | 438 | directory = simplify_path(argv[optind + 1]); |
438 | 439 | ||
439 | if (all || optind + 1 == argc) { | 440 | if (all || optind + 1 == argc) { |
440 | struct mntent *m = NULL; | 441 | f = setmntent("/etc/fstab", "r"); |
441 | FILE *f = setmntent("/etc/fstab", "r"); | ||
442 | fstabmount = TRUE; | ||
443 | 442 | ||
444 | if (f == NULL) | 443 | if (f == NULL) |
445 | perror_msg_and_die( "\nCannot read /etc/fstab"); | 444 | perror_msg_and_die( "\nCannot read /etc/fstab"); |
@@ -460,16 +459,15 @@ extern int mount_main(int argc, char **argv) | |||
460 | 459 | ||
461 | if (all || flags == 0) { // Allow single mount to override fstab flags | 460 | if (all || flags == 0) { // Allow single mount to override fstab flags |
462 | flags = 0; | 461 | flags = 0; |
463 | string_flags = string_flags_buf; | 462 | string_flags[0] = 0; |
464 | *string_flags = '\0'; | 463 | parse_mount_options(m->mnt_opts, &flags, &string_flags); |
465 | parse_mount_options(m->mnt_opts, &flags, string_flags); | ||
466 | } | 464 | } |
467 | 465 | ||
468 | strcpy(device, m->mnt_fsname); | 466 | strcpy(device, m->mnt_fsname); |
469 | strcpy(directory, m->mnt_dir); | 467 | strcpy(directory, m->mnt_dir); |
470 | filesystemType = xstrdup(m->mnt_type); | 468 | filesystemType = xstrdup(m->mnt_type); |
471 | singlemount: | 469 | singlemount: |
472 | string_flags = xstrdup(string_flags); | 470 | extra_opts = string_flags; |
473 | rc = EXIT_SUCCESS; | 471 | rc = EXIT_SUCCESS; |
474 | #ifdef CONFIG_NFSMOUNT | 472 | #ifdef CONFIG_NFSMOUNT |
475 | if (strchr(device, ':') != NULL) { | 473 | if (strchr(device, ':') != NULL) { |
@@ -488,10 +486,10 @@ singlemount: | |||
488 | if (! all) | 486 | if (! all) |
489 | break; | 487 | break; |
490 | } | 488 | } |
491 | if (fstabmount) | 489 | if (f) |
492 | endmntent(f); | 490 | endmntent(f); |
493 | 491 | ||
494 | if (! all && fstabmount && m == NULL) | 492 | if (! all && f && m == NULL) |
495 | fprintf(stderr, "Can't find %s in /etc/fstab\n", device); | 493 | fprintf(stderr, "Can't find %s in /etc/fstab\n", device); |
496 | 494 | ||
497 | return rc; | 495 | return rc; |