aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-05-15 17:42:16 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2001-05-15 17:42:16 +0000
commit4556650b13ac68ca7a536ac1664cc66cbb3e3b23 (patch)
treea0f435a6239c002578db8f019eb0fb427f1795b3 /libbb
parent6ebe0d2d046886fcfc2a9bdd6294fe9c38932811 (diff)
downloadbusybox-w32-4556650b13ac68ca7a536ac1664cc66cbb3e3b23.tar.gz
busybox-w32-4556650b13ac68ca7a536ac1664cc66cbb3e3b23.tar.bz2
busybox-w32-4556650b13ac68ca7a536ac1664cc66cbb3e3b23.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 git-svn-id: svn://busybox.net/trunk/busybox@2647 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r--libbb/chomp.c2
-rw-r--r--libbb/concat_path_file.c4
-rw-r--r--libbb/find_root_device.c26
-rw-r--r--libbb/last_char_is.c4
-rw-r--r--libbb/libbb.h8
5 files changed, 20 insertions, 24 deletions
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
33void chomp(char *s) 33void 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 @@
11extern char *concat_path_file(const char *path, const char *filename) 11extern 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
35extern int find_real_root_device_name(char* name) 36extern 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 */
28char * last_char_is(char *s, int c) 28char * 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);
123extern void write_mtab(char* blockDevice, char* directory, 123extern void write_mtab(char* blockDevice, char* directory,
124 char* filesystemType, long flags, char* string_flags); 124 char* filesystemType, long flags, char* string_flags);
125extern void erase_mtab(const char * name); 125extern void erase_mtab(const char * name);
126extern void mtab_read(void);
127extern char *mtab_first(void **iter);
128extern char *mtab_next(void **iter);
129extern char *mtab_getinfo(const char *match, const char which);
130extern long atoi_w_units (const char *cp); 126extern long atoi_w_units (const char *cp);
131extern pid_t* find_pid_by_name( char* pidName); 127extern pid_t* find_pid_by_name( char* pidName);
132extern int find_real_root_device_name(char* name); 128extern char *find_real_root_device_name(const char* name);
133extern char *get_line_from_file(FILE *file); 129extern char *get_line_from_file(FILE *file);
134extern void print_file(FILE *file); 130extern void print_file(FILE *file);
135extern int print_file_by_name(char *filename); 131extern int print_file_by_name(char *filename);
@@ -218,7 +214,7 @@ int klogctl(int type, char * b, int len);
218char *xgetcwd(char *cwd); 214char *xgetcwd(char *cwd);
219char *xreadlink(const char *path); 215char *xreadlink(const char *path);
220char *concat_path_file(const char *path, const char *filename); 216char *concat_path_file(const char *path, const char *filename);
221char *last_char_is(char *s, int c); 217char *last_char_is(const char *s, int c);
222 218
223typedef struct ar_headers_s { 219typedef struct ar_headers_s {
224 char *name; 220 char *name;