diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-05-15 17:42:16 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-05-15 17:42:16 +0000 |
commit | c911a4389bbaa5ac85d725c8c05e452dfba8583d (patch) | |
tree | a0f435a6239c002578db8f019eb0fb427f1795b3 | |
parent | 15649c11f3568ed6f030953844f201438379e03c (diff) | |
download | busybox-w32-c911a4389bbaa5ac85d725c8c05e452dfba8583d.tar.gz busybox-w32-c911a4389bbaa5ac85d725c8c05e452dfba8583d.tar.bz2 busybox-w32-c911a4389bbaa5ac85d725c8c05e452dfba8583d.zip |
Patch from Vladimir:
1) fixed a bug that could crash df, mount, and umount applets if the root
device name was longer then the word "root" (/dev/loop1 vs /dev/root) -
2) severl functions needed static declaration in the umount applet
3) update declaration for function in last_char_is() in libbb
-rw-r--r-- | coreutils/df.c | 4 | ||||
-rw-r--r-- | df.c | 4 | ||||
-rw-r--r-- | include/libbb.h | 8 | ||||
-rw-r--r-- | libbb/chomp.c | 2 | ||||
-rw-r--r-- | libbb/concat_path_file.c | 4 | ||||
-rw-r--r-- | libbb/find_root_device.c | 26 | ||||
-rw-r--r-- | libbb/last_char_is.c | 4 | ||||
-rw-r--r-- | libbb/libbb.h | 8 | ||||
-rw-r--r-- | mount.c | 6 | ||||
-rw-r--r-- | umount.c | 33 | ||||
-rw-r--r-- | util-linux/mount.c | 6 | ||||
-rw-r--r-- | util-linux/umount.c | 33 |
12 files changed, 70 insertions, 68 deletions
diff --git a/coreutils/df.c b/coreutils/df.c index 21a1dbb31..df6874433 100644 --- a/coreutils/df.c +++ b/coreutils/df.c | |||
@@ -60,7 +60,9 @@ static int do_df(char *device, const char *mount_point) | |||
60 | if (strcmp(device, "/dev/root") == 0) { | 60 | if (strcmp(device, "/dev/root") == 0) { |
61 | /* Adjusts device to be the real root device, | 61 | /* Adjusts device to be the real root device, |
62 | * or leaves device alone if it can't find it */ | 62 | * or leaves device alone if it can't find it */ |
63 | find_real_root_device_name( device); | 63 | device = find_real_root_device_name(device); |
64 | if(device==NULL) | ||
65 | return FALSE; | ||
64 | } | 66 | } |
65 | #ifdef BB_FEATURE_HUMAN_READABLE | 67 | #ifdef BB_FEATURE_HUMAN_READABLE |
66 | switch (df_disp_hr) { | 68 | switch (df_disp_hr) { |
@@ -60,7 +60,9 @@ static int do_df(char *device, const char *mount_point) | |||
60 | if (strcmp(device, "/dev/root") == 0) { | 60 | if (strcmp(device, "/dev/root") == 0) { |
61 | /* Adjusts device to be the real root device, | 61 | /* Adjusts device to be the real root device, |
62 | * or leaves device alone if it can't find it */ | 62 | * or leaves device alone if it can't find it */ |
63 | find_real_root_device_name( device); | 63 | device = find_real_root_device_name(device); |
64 | if(device==NULL) | ||
65 | return FALSE; | ||
64 | } | 66 | } |
65 | #ifdef BB_FEATURE_HUMAN_READABLE | 67 | #ifdef BB_FEATURE_HUMAN_READABLE |
66 | switch (df_disp_hr) { | 68 | switch (df_disp_hr) { |
diff --git a/include/libbb.h b/include/libbb.h index 02cf607a7..f34bee8f7 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -123,13 +123,9 @@ extern struct mntent *find_mount_point(const char *name, const char *table); | |||
123 | extern void write_mtab(char* blockDevice, char* directory, | 123 | extern void write_mtab(char* blockDevice, char* directory, |
124 | char* filesystemType, long flags, char* string_flags); | 124 | char* filesystemType, long flags, char* string_flags); |
125 | extern void erase_mtab(const char * name); | 125 | extern void erase_mtab(const char * name); |
126 | extern void mtab_read(void); | ||
127 | extern char *mtab_first(void **iter); | ||
128 | extern char *mtab_next(void **iter); | ||
129 | extern char *mtab_getinfo(const char *match, const char which); | ||
130 | extern long atoi_w_units (const char *cp); | 126 | extern long atoi_w_units (const char *cp); |
131 | extern pid_t* find_pid_by_name( char* pidName); | 127 | extern pid_t* find_pid_by_name( char* pidName); |
132 | extern int find_real_root_device_name(char* name); | 128 | extern char *find_real_root_device_name(const char* name); |
133 | extern char *get_line_from_file(FILE *file); | 129 | extern char *get_line_from_file(FILE *file); |
134 | extern void print_file(FILE *file); | 130 | extern void print_file(FILE *file); |
135 | extern int print_file_by_name(char *filename); | 131 | extern int print_file_by_name(char *filename); |
@@ -218,7 +214,7 @@ int klogctl(int type, char * b, int len); | |||
218 | char *xgetcwd(char *cwd); | 214 | char *xgetcwd(char *cwd); |
219 | char *xreadlink(const char *path); | 215 | char *xreadlink(const char *path); |
220 | char *concat_path_file(const char *path, const char *filename); | 216 | char *concat_path_file(const char *path, const char *filename); |
221 | char *last_char_is(char *s, int c); | 217 | char *last_char_is(const char *s, int c); |
222 | 218 | ||
223 | typedef struct ar_headers_s { | 219 | typedef struct ar_headers_s { |
224 | char *name; | 220 | char *name; |
diff --git a/libbb/chomp.c b/libbb/chomp.c index e62cb4005..111d4cf77 100644 --- a/libbb/chomp.c +++ b/libbb/chomp.c | |||
@@ -32,7 +32,7 @@ | |||
32 | 32 | ||
33 | void chomp(char *s) | 33 | void chomp(char *s) |
34 | { | 34 | { |
35 | char *lc = (char *)last_char_is(s, '\n'); | 35 | char *lc = last_char_is(s, '\n'); |
36 | 36 | ||
37 | if(lc) | 37 | if(lc) |
38 | *lc = 0; | 38 | *lc = 0; |
diff --git a/libbb/concat_path_file.c b/libbb/concat_path_file.c index 6b7abf24b..12a57c837 100644 --- a/libbb/concat_path_file.c +++ b/libbb/concat_path_file.c | |||
@@ -11,9 +11,9 @@ | |||
11 | extern char *concat_path_file(const char *path, const char *filename) | 11 | extern char *concat_path_file(const char *path, const char *filename) |
12 | { | 12 | { |
13 | char *outbuf; | 13 | char *outbuf; |
14 | const char *lc; | 14 | char *lc; |
15 | 15 | ||
16 | lc = last_char_is((char*)path, '/'); | 16 | lc = last_char_is(path, '/'); |
17 | if (filename[0] == '/') | 17 | if (filename[0] == '/') |
18 | filename++; | 18 | filename++; |
19 | outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL)); | 19 | outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL)); |
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c index de765ce44..75ed1a979 100644 --- a/libbb/find_root_device.c +++ b/libbb/find_root_device.c | |||
@@ -28,26 +28,27 @@ | |||
28 | #include <stdio.h> | 28 | #include <stdio.h> |
29 | #include <string.h> | 29 | #include <string.h> |
30 | #include <dirent.h> | 30 | #include <dirent.h> |
31 | #include <stdlib.h> | ||
31 | #include "libbb.h" | 32 | #include "libbb.h" |
32 | 33 | ||
33 | 34 | ||
34 | 35 | ||
35 | extern int find_real_root_device_name(char* name) | 36 | extern char *find_real_root_device_name(const char* name) |
36 | { | 37 | { |
37 | DIR *dir; | 38 | DIR *dir; |
38 | struct dirent *entry; | 39 | struct dirent *entry; |
39 | struct stat statBuf, rootStat; | 40 | struct stat statBuf, rootStat; |
40 | char fileName[BUFSIZ]; | 41 | char *fileName; |
41 | 42 | ||
42 | if (stat("/", &rootStat) != 0) { | 43 | if (stat("/", &rootStat) != 0) { |
43 | error_msg("could not stat '/'"); | 44 | error_msg("could not stat '/'"); |
44 | return( FALSE); | 45 | return NULL; |
45 | } | 46 | } |
46 | 47 | ||
47 | dir = opendir("/dev"); | 48 | dir = opendir("/dev"); |
48 | if (!dir) { | 49 | if (!dir) { |
49 | error_msg("could not open '/dev'"); | 50 | error_msg("could not open '/dev'"); |
50 | return( FALSE); | 51 | return NULL; |
51 | } | 52 | } |
52 | 53 | ||
53 | while((entry = readdir(dir)) != NULL) { | 54 | while((entry = readdir(dir)) != NULL) { |
@@ -57,21 +58,20 @@ extern int find_real_root_device_name(char* name) | |||
57 | if (strcmp(entry->d_name, "..") == 0) | 58 | if (strcmp(entry->d_name, "..") == 0) |
58 | continue; | 59 | continue; |
59 | 60 | ||
60 | snprintf( fileName, strlen(name)+1, "/dev/%s", entry->d_name); | 61 | fileName = concat_path_file("/dev/", entry->d_name); |
61 | 62 | ||
62 | if (stat(fileName, &statBuf) != 0) | ||
63 | continue; | ||
64 | /* Some char devices have the same dev_t as block | 63 | /* Some char devices have the same dev_t as block |
65 | * devices, so make sure this is a block device */ | 64 | * devices, so make sure this is a block device */ |
66 | if (! S_ISBLK(statBuf.st_mode)) | 65 | if (stat(fileName, &statBuf) == 0 && |
67 | continue; | 66 | S_ISBLK(statBuf.st_mode)!=0 && |
68 | if (statBuf.st_rdev == rootStat.st_rdev) { | 67 | statBuf.st_rdev == rootStat.st_rdev) { |
69 | strcpy(name, fileName); | 68 | return fileName; |
70 | return ( TRUE); | ||
71 | } | 69 | } |
70 | free(fileName); | ||
72 | } | 71 | } |
72 | closedir(dir); | ||
73 | 73 | ||
74 | return( FALSE); | 74 | return NULL; |
75 | } | 75 | } |
76 | 76 | ||
77 | 77 | ||
diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c index 36b695b40..ae2d24bf7 100644 --- a/libbb/last_char_is.c +++ b/libbb/last_char_is.c | |||
@@ -25,9 +25,9 @@ | |||
25 | * underrun the buffer if the string length is 0. Also avoids a possible | 25 | * underrun the buffer if the string length is 0. Also avoids a possible |
26 | * space-hogging inline of strlen() per usage. | 26 | * space-hogging inline of strlen() per usage. |
27 | */ | 27 | */ |
28 | char * last_char_is(char *s, int c) | 28 | char * last_char_is(const char *s, int c) |
29 | { | 29 | { |
30 | char *sret = s+strlen(s)-1; | 30 | char *sret = (char *)s+strlen(s)-1; |
31 | if (sret>=s && *sret == c) { | 31 | if (sret>=s && *sret == c) { |
32 | return sret; | 32 | return sret; |
33 | } else { | 33 | } else { |
diff --git a/libbb/libbb.h b/libbb/libbb.h index 02cf607a7..f34bee8f7 100644 --- a/libbb/libbb.h +++ b/libbb/libbb.h | |||
@@ -123,13 +123,9 @@ extern struct mntent *find_mount_point(const char *name, const char *table); | |||
123 | extern void write_mtab(char* blockDevice, char* directory, | 123 | extern void write_mtab(char* blockDevice, char* directory, |
124 | char* filesystemType, long flags, char* string_flags); | 124 | char* filesystemType, long flags, char* string_flags); |
125 | extern void erase_mtab(const char * name); | 125 | extern void erase_mtab(const char * name); |
126 | extern void mtab_read(void); | ||
127 | extern char *mtab_first(void **iter); | ||
128 | extern char *mtab_next(void **iter); | ||
129 | extern char *mtab_getinfo(const char *match, const char which); | ||
130 | extern long atoi_w_units (const char *cp); | 126 | extern long atoi_w_units (const char *cp); |
131 | extern pid_t* find_pid_by_name( char* pidName); | 127 | extern pid_t* find_pid_by_name( char* pidName); |
132 | extern int find_real_root_device_name(char* name); | 128 | extern char *find_real_root_device_name(const char* name); |
133 | extern char *get_line_from_file(FILE *file); | 129 | extern char *get_line_from_file(FILE *file); |
134 | extern void print_file(FILE *file); | 130 | extern void print_file(FILE *file); |
135 | extern int print_file_by_name(char *filename); | 131 | extern int print_file_by_name(char *filename); |
@@ -218,7 +214,7 @@ int klogctl(int type, char * b, int len); | |||
218 | char *xgetcwd(char *cwd); | 214 | char *xgetcwd(char *cwd); |
219 | char *xreadlink(const char *path); | 215 | char *xreadlink(const char *path); |
220 | char *concat_path_file(const char *path, const char *filename); | 216 | char *concat_path_file(const char *path, const char *filename); |
221 | char *last_char_is(char *s, int c); | 217 | char *last_char_is(const char *s, int c); |
222 | 218 | ||
223 | typedef struct ar_headers_s { | 219 | typedef struct ar_headers_s { |
224 | char *name; | 220 | char *name; |
@@ -319,10 +319,14 @@ void show_mounts() | |||
319 | while ((m = getmntent(mountTable)) != 0) { | 319 | while ((m = getmntent(mountTable)) != 0) { |
320 | char *blockDevice = m->mnt_fsname; | 320 | char *blockDevice = m->mnt_fsname; |
321 | if (strcmp(blockDevice, "/dev/root") == 0) { | 321 | if (strcmp(blockDevice, "/dev/root") == 0) { |
322 | find_real_root_device_name( blockDevice); | 322 | blockDevice = find_real_root_device_name(blockDevice); |
323 | } | 323 | } |
324 | printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, | 324 | printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, |
325 | m->mnt_type, m->mnt_opts); | 325 | m->mnt_type, m->mnt_opts); |
326 | #ifdef BB_FEATURE_CLEAN_UP | ||
327 | if(blockDevice != m->mnt_fsname) | ||
328 | free(blockDevice); | ||
329 | #endif | ||
326 | } | 330 | } |
327 | endmntent(mountTable); | 331 | endmntent(mountTable); |
328 | } else { | 332 | } else { |
@@ -74,7 +74,7 @@ extern const char mtab_file[]; /* Defined in utility.c */ | |||
74 | * TODO: Perhaps switch to using Glibc's getmntent_r | 74 | * TODO: Perhaps switch to using Glibc's getmntent_r |
75 | * -Erik | 75 | * -Erik |
76 | */ | 76 | */ |
77 | void mtab_read(void) | 77 | static void mtab_read(void) |
78 | { | 78 | { |
79 | struct _mtab_entry_t *entry = NULL; | 79 | struct _mtab_entry_t *entry = NULL; |
80 | struct mntent *e; | 80 | struct mntent *e; |
@@ -97,7 +97,7 @@ void mtab_read(void) | |||
97 | endmntent(fp); | 97 | endmntent(fp); |
98 | } | 98 | } |
99 | 99 | ||
100 | char *mtab_getinfo(const char *match, const char which) | 100 | static char *mtab_getinfo(const char *match, const char which) |
101 | { | 101 | { |
102 | struct _mtab_entry_t *cur = mtab_cache; | 102 | struct _mtab_entry_t *cur = mtab_cache; |
103 | 103 | ||
@@ -111,8 +111,7 @@ char *mtab_getinfo(const char *match, const char which) | |||
111 | if (strcmp(cur->device, "/dev/root") == 0) { | 111 | if (strcmp(cur->device, "/dev/root") == 0) { |
112 | /* Adjusts device to be the real root device, | 112 | /* Adjusts device to be the real root device, |
113 | * or leaves device alone if it can't find it */ | 113 | * or leaves device alone if it can't find it */ |
114 | find_real_root_device_name( cur->device); | 114 | cur->device = find_real_root_device_name(cur->device); |
115 | return ( cur->device); | ||
116 | } | 115 | } |
117 | #endif | 116 | #endif |
118 | return cur->device; | 117 | return cur->device; |
@@ -123,18 +122,7 @@ char *mtab_getinfo(const char *match, const char which) | |||
123 | return NULL; | 122 | return NULL; |
124 | } | 123 | } |
125 | 124 | ||
126 | char *mtab_first(void **iter) | 125 | static char *mtab_next(void **iter) |
127 | { | ||
128 | struct _mtab_entry_t *mtab_iter; | ||
129 | |||
130 | if (!iter) | ||
131 | return NULL; | ||
132 | mtab_iter = mtab_cache; | ||
133 | *iter = (void *) mtab_iter; | ||
134 | return mtab_next(iter); | ||
135 | } | ||
136 | |||
137 | char *mtab_next(void **iter) | ||
138 | { | 126 | { |
139 | char *mp; | 127 | char *mp; |
140 | 128 | ||
@@ -145,10 +133,21 @@ char *mtab_next(void **iter) | |||
145 | return mp; | 133 | return mp; |
146 | } | 134 | } |
147 | 135 | ||
136 | static char *mtab_first(void **iter) | ||
137 | { | ||
138 | struct _mtab_entry_t *mtab_iter; | ||
139 | |||
140 | if (!iter) | ||
141 | return NULL; | ||
142 | mtab_iter = mtab_cache; | ||
143 | *iter = (void *) mtab_iter; | ||
144 | return mtab_next(iter); | ||
145 | } | ||
146 | |||
148 | /* Don't bother to clean up, since exit() does that | 147 | /* Don't bother to clean up, since exit() does that |
149 | * automagically, so we can save a few bytes */ | 148 | * automagically, so we can save a few bytes */ |
150 | #ifdef BB_FEATURE_CLEAN_UP | 149 | #ifdef BB_FEATURE_CLEAN_UP |
151 | void mtab_free(void) | 150 | static void mtab_free(void) |
152 | { | 151 | { |
153 | struct _mtab_entry_t *this, *next; | 152 | struct _mtab_entry_t *this, *next; |
154 | 153 | ||
diff --git a/util-linux/mount.c b/util-linux/mount.c index 0295fabc6..4e0e3e428 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
@@ -319,10 +319,14 @@ void show_mounts() | |||
319 | while ((m = getmntent(mountTable)) != 0) { | 319 | while ((m = getmntent(mountTable)) != 0) { |
320 | char *blockDevice = m->mnt_fsname; | 320 | char *blockDevice = m->mnt_fsname; |
321 | if (strcmp(blockDevice, "/dev/root") == 0) { | 321 | if (strcmp(blockDevice, "/dev/root") == 0) { |
322 | find_real_root_device_name( blockDevice); | 322 | blockDevice = find_real_root_device_name(blockDevice); |
323 | } | 323 | } |
324 | printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, | 324 | printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, |
325 | m->mnt_type, m->mnt_opts); | 325 | m->mnt_type, m->mnt_opts); |
326 | #ifdef BB_FEATURE_CLEAN_UP | ||
327 | if(blockDevice != m->mnt_fsname) | ||
328 | free(blockDevice); | ||
329 | #endif | ||
326 | } | 330 | } |
327 | endmntent(mountTable); | 331 | endmntent(mountTable); |
328 | } else { | 332 | } else { |
diff --git a/util-linux/umount.c b/util-linux/umount.c index 0eade5a36..8565744f2 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c | |||
@@ -74,7 +74,7 @@ extern const char mtab_file[]; /* Defined in utility.c */ | |||
74 | * TODO: Perhaps switch to using Glibc's getmntent_r | 74 | * TODO: Perhaps switch to using Glibc's getmntent_r |
75 | * -Erik | 75 | * -Erik |
76 | */ | 76 | */ |
77 | void mtab_read(void) | 77 | static void mtab_read(void) |
78 | { | 78 | { |
79 | struct _mtab_entry_t *entry = NULL; | 79 | struct _mtab_entry_t *entry = NULL; |
80 | struct mntent *e; | 80 | struct mntent *e; |
@@ -97,7 +97,7 @@ void mtab_read(void) | |||
97 | endmntent(fp); | 97 | endmntent(fp); |
98 | } | 98 | } |
99 | 99 | ||
100 | char *mtab_getinfo(const char *match, const char which) | 100 | static char *mtab_getinfo(const char *match, const char which) |
101 | { | 101 | { |
102 | struct _mtab_entry_t *cur = mtab_cache; | 102 | struct _mtab_entry_t *cur = mtab_cache; |
103 | 103 | ||
@@ -111,8 +111,7 @@ char *mtab_getinfo(const char *match, const char which) | |||
111 | if (strcmp(cur->device, "/dev/root") == 0) { | 111 | if (strcmp(cur->device, "/dev/root") == 0) { |
112 | /* Adjusts device to be the real root device, | 112 | /* Adjusts device to be the real root device, |
113 | * or leaves device alone if it can't find it */ | 113 | * or leaves device alone if it can't find it */ |
114 | find_real_root_device_name( cur->device); | 114 | cur->device = find_real_root_device_name(cur->device); |
115 | return ( cur->device); | ||
116 | } | 115 | } |
117 | #endif | 116 | #endif |
118 | return cur->device; | 117 | return cur->device; |
@@ -123,18 +122,7 @@ char *mtab_getinfo(const char *match, const char which) | |||
123 | return NULL; | 122 | return NULL; |
124 | } | 123 | } |
125 | 124 | ||
126 | char *mtab_first(void **iter) | 125 | static char *mtab_next(void **iter) |
127 | { | ||
128 | struct _mtab_entry_t *mtab_iter; | ||
129 | |||
130 | if (!iter) | ||
131 | return NULL; | ||
132 | mtab_iter = mtab_cache; | ||
133 | *iter = (void *) mtab_iter; | ||
134 | return mtab_next(iter); | ||
135 | } | ||
136 | |||
137 | char *mtab_next(void **iter) | ||
138 | { | 126 | { |
139 | char *mp; | 127 | char *mp; |
140 | 128 | ||
@@ -145,10 +133,21 @@ char *mtab_next(void **iter) | |||
145 | return mp; | 133 | return mp; |
146 | } | 134 | } |
147 | 135 | ||
136 | static char *mtab_first(void **iter) | ||
137 | { | ||
138 | struct _mtab_entry_t *mtab_iter; | ||
139 | |||
140 | if (!iter) | ||
141 | return NULL; | ||
142 | mtab_iter = mtab_cache; | ||
143 | *iter = (void *) mtab_iter; | ||
144 | return mtab_next(iter); | ||
145 | } | ||
146 | |||
148 | /* Don't bother to clean up, since exit() does that | 147 | /* Don't bother to clean up, since exit() does that |
149 | * automagically, so we can save a few bytes */ | 148 | * automagically, so we can save a few bytes */ |
150 | #ifdef BB_FEATURE_CLEAN_UP | 149 | #ifdef BB_FEATURE_CLEAN_UP |
151 | void mtab_free(void) | 150 | static void mtab_free(void) |
152 | { | 151 | { |
153 | struct _mtab_entry_t *this, *next; | 152 | struct _mtab_entry_t *this, *next; |
154 | 153 | ||