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
This commit is contained in:
Eric Andersen 2001-05-15 17:42:16 +00:00
parent 15649c11f3
commit c911a4389b
12 changed files with 70 additions and 68 deletions

View File

@ -60,7 +60,9 @@ static int do_df(char *device, const char *mount_point)
if (strcmp(device, "/dev/root") == 0) { if (strcmp(device, "/dev/root") == 0) {
/* Adjusts device to be the real root device, /* Adjusts device to be the real root device,
* or leaves device alone if it can't find it */ * or leaves device alone if it can't find it */
find_real_root_device_name( device); device = find_real_root_device_name(device);
if(device==NULL)
return FALSE;
} }
#ifdef BB_FEATURE_HUMAN_READABLE #ifdef BB_FEATURE_HUMAN_READABLE
switch (df_disp_hr) { switch (df_disp_hr) {

4
df.c
View File

@ -60,7 +60,9 @@ static int do_df(char *device, const char *mount_point)
if (strcmp(device, "/dev/root") == 0) { if (strcmp(device, "/dev/root") == 0) {
/* Adjusts device to be the real root device, /* Adjusts device to be the real root device,
* or leaves device alone if it can't find it */ * or leaves device alone if it can't find it */
find_real_root_device_name( device); device = find_real_root_device_name(device);
if(device==NULL)
return FALSE;
} }
#ifdef BB_FEATURE_HUMAN_READABLE #ifdef BB_FEATURE_HUMAN_READABLE
switch (df_disp_hr) { switch (df_disp_hr) {

View File

@ -123,13 +123,9 @@ extern struct mntent *find_mount_point(const char *name, const char *table);
extern void write_mtab(char* blockDevice, char* directory, extern void write_mtab(char* blockDevice, char* directory,
char* filesystemType, long flags, char* string_flags); char* filesystemType, long flags, char* string_flags);
extern void erase_mtab(const char * name); extern void erase_mtab(const char * name);
extern void mtab_read(void);
extern char *mtab_first(void **iter);
extern char *mtab_next(void **iter);
extern char *mtab_getinfo(const char *match, const char which);
extern long atoi_w_units (const char *cp); extern long atoi_w_units (const char *cp);
extern pid_t* find_pid_by_name( char* pidName); extern pid_t* find_pid_by_name( char* pidName);
extern int find_real_root_device_name(char* name); extern char *find_real_root_device_name(const char* name);
extern char *get_line_from_file(FILE *file); extern char *get_line_from_file(FILE *file);
extern void print_file(FILE *file); extern void print_file(FILE *file);
extern int print_file_by_name(char *filename); extern int print_file_by_name(char *filename);
@ -218,7 +214,7 @@ int klogctl(int type, char * b, int len);
char *xgetcwd(char *cwd); char *xgetcwd(char *cwd);
char *xreadlink(const char *path); char *xreadlink(const char *path);
char *concat_path_file(const char *path, const char *filename); char *concat_path_file(const char *path, const char *filename);
char *last_char_is(char *s, int c); char *last_char_is(const char *s, int c);
typedef struct ar_headers_s { typedef struct ar_headers_s {
char *name; char *name;

View File

@ -32,7 +32,7 @@
void chomp(char *s) void chomp(char *s)
{ {
char *lc = (char *)last_char_is(s, '\n'); char *lc = last_char_is(s, '\n');
if(lc) if(lc)
*lc = 0; *lc = 0;

View File

@ -11,9 +11,9 @@
extern char *concat_path_file(const char *path, const char *filename) extern char *concat_path_file(const char *path, const char *filename)
{ {
char *outbuf; char *outbuf;
const char *lc; char *lc;
lc = last_char_is((char*)path, '/'); lc = last_char_is(path, '/');
if (filename[0] == '/') if (filename[0] == '/')
filename++; filename++;
outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL)); outbuf = xmalloc(strlen(path)+strlen(filename)+1+(lc==NULL));

View File

@ -28,26 +28,27 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <dirent.h> #include <dirent.h>
#include <stdlib.h>
#include "libbb.h" #include "libbb.h"
extern int find_real_root_device_name(char* name) extern char *find_real_root_device_name(const char* name)
{ {
DIR *dir; DIR *dir;
struct dirent *entry; struct dirent *entry;
struct stat statBuf, rootStat; struct stat statBuf, rootStat;
char fileName[BUFSIZ]; char *fileName;
if (stat("/", &rootStat) != 0) { if (stat("/", &rootStat) != 0) {
error_msg("could not stat '/'"); error_msg("could not stat '/'");
return( FALSE); return NULL;
} }
dir = opendir("/dev"); dir = opendir("/dev");
if (!dir) { if (!dir) {
error_msg("could not open '/dev'"); error_msg("could not open '/dev'");
return( FALSE); return NULL;
} }
while((entry = readdir(dir)) != NULL) { while((entry = readdir(dir)) != NULL) {
@ -57,21 +58,20 @@ extern int find_real_root_device_name(char* name)
if (strcmp(entry->d_name, "..") == 0) if (strcmp(entry->d_name, "..") == 0)
continue; continue;
snprintf( fileName, strlen(name)+1, "/dev/%s", entry->d_name); fileName = concat_path_file("/dev/", entry->d_name);
if (stat(fileName, &statBuf) != 0)
continue;
/* Some char devices have the same dev_t as block /* Some char devices have the same dev_t as block
* devices, so make sure this is a block device */ * devices, so make sure this is a block device */
if (! S_ISBLK(statBuf.st_mode)) if (stat(fileName, &statBuf) == 0 &&
continue; S_ISBLK(statBuf.st_mode)!=0 &&
if (statBuf.st_rdev == rootStat.st_rdev) { statBuf.st_rdev == rootStat.st_rdev) {
strcpy(name, fileName); return fileName;
return ( TRUE);
} }
free(fileName);
} }
closedir(dir);
return( FALSE); return NULL;
} }

View File

@ -25,9 +25,9 @@
* underrun the buffer if the string length is 0. Also avoids a possible * underrun the buffer if the string length is 0. Also avoids a possible
* space-hogging inline of strlen() per usage. * space-hogging inline of strlen() per usage.
*/ */
char * last_char_is(char *s, int c) char * last_char_is(const char *s, int c)
{ {
char *sret = s+strlen(s)-1; char *sret = (char *)s+strlen(s)-1;
if (sret>=s && *sret == c) { if (sret>=s && *sret == c) {
return sret; return sret;
} else { } else {

View File

@ -123,13 +123,9 @@ extern struct mntent *find_mount_point(const char *name, const char *table);
extern void write_mtab(char* blockDevice, char* directory, extern void write_mtab(char* blockDevice, char* directory,
char* filesystemType, long flags, char* string_flags); char* filesystemType, long flags, char* string_flags);
extern void erase_mtab(const char * name); extern void erase_mtab(const char * name);
extern void mtab_read(void);
extern char *mtab_first(void **iter);
extern char *mtab_next(void **iter);
extern char *mtab_getinfo(const char *match, const char which);
extern long atoi_w_units (const char *cp); extern long atoi_w_units (const char *cp);
extern pid_t* find_pid_by_name( char* pidName); extern pid_t* find_pid_by_name( char* pidName);
extern int find_real_root_device_name(char* name); extern char *find_real_root_device_name(const char* name);
extern char *get_line_from_file(FILE *file); extern char *get_line_from_file(FILE *file);
extern void print_file(FILE *file); extern void print_file(FILE *file);
extern int print_file_by_name(char *filename); extern int print_file_by_name(char *filename);
@ -218,7 +214,7 @@ int klogctl(int type, char * b, int len);
char *xgetcwd(char *cwd); char *xgetcwd(char *cwd);
char *xreadlink(const char *path); char *xreadlink(const char *path);
char *concat_path_file(const char *path, const char *filename); char *concat_path_file(const char *path, const char *filename);
char *last_char_is(char *s, int c); char *last_char_is(const char *s, int c);
typedef struct ar_headers_s { typedef struct ar_headers_s {
char *name; char *name;

View File

@ -319,10 +319,14 @@ void show_mounts()
while ((m = getmntent(mountTable)) != 0) { while ((m = getmntent(mountTable)) != 0) {
char *blockDevice = m->mnt_fsname; char *blockDevice = m->mnt_fsname;
if (strcmp(blockDevice, "/dev/root") == 0) { if (strcmp(blockDevice, "/dev/root") == 0) {
find_real_root_device_name( blockDevice); blockDevice = find_real_root_device_name(blockDevice);
} }
printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir,
m->mnt_type, m->mnt_opts); m->mnt_type, m->mnt_opts);
#ifdef BB_FEATURE_CLEAN_UP
if(blockDevice != m->mnt_fsname)
free(blockDevice);
#endif
} }
endmntent(mountTable); endmntent(mountTable);
} else { } else {

View File

@ -74,7 +74,7 @@ extern const char mtab_file[]; /* Defined in utility.c */
* TODO: Perhaps switch to using Glibc's getmntent_r * TODO: Perhaps switch to using Glibc's getmntent_r
* -Erik * -Erik
*/ */
void mtab_read(void) static void mtab_read(void)
{ {
struct _mtab_entry_t *entry = NULL; struct _mtab_entry_t *entry = NULL;
struct mntent *e; struct mntent *e;
@ -97,7 +97,7 @@ void mtab_read(void)
endmntent(fp); endmntent(fp);
} }
char *mtab_getinfo(const char *match, const char which) static char *mtab_getinfo(const char *match, const char which)
{ {
struct _mtab_entry_t *cur = mtab_cache; struct _mtab_entry_t *cur = mtab_cache;
@ -111,8 +111,7 @@ char *mtab_getinfo(const char *match, const char which)
if (strcmp(cur->device, "/dev/root") == 0) { if (strcmp(cur->device, "/dev/root") == 0) {
/* Adjusts device to be the real root device, /* Adjusts device to be the real root device,
* or leaves device alone if it can't find it */ * or leaves device alone if it can't find it */
find_real_root_device_name( cur->device); cur->device = find_real_root_device_name(cur->device);
return ( cur->device);
} }
#endif #endif
return cur->device; return cur->device;
@ -123,18 +122,7 @@ char *mtab_getinfo(const char *match, const char which)
return NULL; return NULL;
} }
char *mtab_first(void **iter) static char *mtab_next(void **iter)
{
struct _mtab_entry_t *mtab_iter;
if (!iter)
return NULL;
mtab_iter = mtab_cache;
*iter = (void *) mtab_iter;
return mtab_next(iter);
}
char *mtab_next(void **iter)
{ {
char *mp; char *mp;
@ -145,10 +133,21 @@ char *mtab_next(void **iter)
return mp; return mp;
} }
static char *mtab_first(void **iter)
{
struct _mtab_entry_t *mtab_iter;
if (!iter)
return NULL;
mtab_iter = mtab_cache;
*iter = (void *) mtab_iter;
return mtab_next(iter);
}
/* Don't bother to clean up, since exit() does that /* Don't bother to clean up, since exit() does that
* automagically, so we can save a few bytes */ * automagically, so we can save a few bytes */
#ifdef BB_FEATURE_CLEAN_UP #ifdef BB_FEATURE_CLEAN_UP
void mtab_free(void) static void mtab_free(void)
{ {
struct _mtab_entry_t *this, *next; struct _mtab_entry_t *this, *next;

View File

@ -319,10 +319,14 @@ void show_mounts()
while ((m = getmntent(mountTable)) != 0) { while ((m = getmntent(mountTable)) != 0) {
char *blockDevice = m->mnt_fsname; char *blockDevice = m->mnt_fsname;
if (strcmp(blockDevice, "/dev/root") == 0) { if (strcmp(blockDevice, "/dev/root") == 0) {
find_real_root_device_name( blockDevice); blockDevice = find_real_root_device_name(blockDevice);
} }
printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir, printf("%s on %s type %s (%s)\n", blockDevice, m->mnt_dir,
m->mnt_type, m->mnt_opts); m->mnt_type, m->mnt_opts);
#ifdef BB_FEATURE_CLEAN_UP
if(blockDevice != m->mnt_fsname)
free(blockDevice);
#endif
} }
endmntent(mountTable); endmntent(mountTable);
} else { } else {

View File

@ -74,7 +74,7 @@ extern const char mtab_file[]; /* Defined in utility.c */
* TODO: Perhaps switch to using Glibc's getmntent_r * TODO: Perhaps switch to using Glibc's getmntent_r
* -Erik * -Erik
*/ */
void mtab_read(void) static void mtab_read(void)
{ {
struct _mtab_entry_t *entry = NULL; struct _mtab_entry_t *entry = NULL;
struct mntent *e; struct mntent *e;
@ -97,7 +97,7 @@ void mtab_read(void)
endmntent(fp); endmntent(fp);
} }
char *mtab_getinfo(const char *match, const char which) static char *mtab_getinfo(const char *match, const char which)
{ {
struct _mtab_entry_t *cur = mtab_cache; struct _mtab_entry_t *cur = mtab_cache;
@ -111,8 +111,7 @@ char *mtab_getinfo(const char *match, const char which)
if (strcmp(cur->device, "/dev/root") == 0) { if (strcmp(cur->device, "/dev/root") == 0) {
/* Adjusts device to be the real root device, /* Adjusts device to be the real root device,
* or leaves device alone if it can't find it */ * or leaves device alone if it can't find it */
find_real_root_device_name( cur->device); cur->device = find_real_root_device_name(cur->device);
return ( cur->device);
} }
#endif #endif
return cur->device; return cur->device;
@ -123,18 +122,7 @@ char *mtab_getinfo(const char *match, const char which)
return NULL; return NULL;
} }
char *mtab_first(void **iter) static char *mtab_next(void **iter)
{
struct _mtab_entry_t *mtab_iter;
if (!iter)
return NULL;
mtab_iter = mtab_cache;
*iter = (void *) mtab_iter;
return mtab_next(iter);
}
char *mtab_next(void **iter)
{ {
char *mp; char *mp;
@ -145,10 +133,21 @@ char *mtab_next(void **iter)
return mp; return mp;
} }
static char *mtab_first(void **iter)
{
struct _mtab_entry_t *mtab_iter;
if (!iter)
return NULL;
mtab_iter = mtab_cache;
*iter = (void *) mtab_iter;
return mtab_next(iter);
}
/* Don't bother to clean up, since exit() does that /* Don't bother to clean up, since exit() does that
* automagically, so we can save a few bytes */ * automagically, so we can save a few bytes */
#ifdef BB_FEATURE_CLEAN_UP #ifdef BB_FEATURE_CLEAN_UP
void mtab_free(void) static void mtab_free(void)
{ {
struct _mtab_entry_t *this, *next; struct _mtab_entry_t *this, *next;