aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2001-05-15 17:42:16 +0000
committerEric Andersen <andersen@codepoet.org>2001-05-15 17:42:16 +0000
commitc911a4389bbaa5ac85d725c8c05e452dfba8583d (patch)
treea0f435a6239c002578db8f019eb0fb427f1795b3 /libbb
parent15649c11f3568ed6f030953844f201438379e03c (diff)
downloadbusybox-c911a4389bbaa5ac85d725c8c05e452dfba8583d.tar.gz
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
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 @@
void chomp(char *s)
{
- char *lc = (char *)last_char_is(s, '\n');
+ char *lc = last_char_is(s, '\n');
if(lc)
*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 @@
extern char *concat_path_file(const char *path, const char *filename)
{
char *outbuf;
- const char *lc;
+ char *lc;
- lc = last_char_is((char*)path, '/');
+ lc = last_char_is(path, '/');
if (filename[0] == '/')
filename++;
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 @@
#include <stdio.h>
#include <string.h>
#include <dirent.h>
+#include <stdlib.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;
struct dirent *entry;
struct stat statBuf, rootStat;
- char fileName[BUFSIZ];
+ char *fileName;
if (stat("/", &rootStat) != 0) {
error_msg("could not stat '/'");
- return( FALSE);
+ return NULL;
}
dir = opendir("/dev");
if (!dir) {
error_msg("could not open '/dev'");
- return( FALSE);
+ return 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)
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
* devices, so make sure this is a block device */
- if (! S_ISBLK(statBuf.st_mode))
- continue;
- if (statBuf.st_rdev == rootStat.st_rdev) {
- strcpy(name, fileName);
- return ( TRUE);
+ if (stat(fileName, &statBuf) == 0 &&
+ S_ISBLK(statBuf.st_mode)!=0 &&
+ statBuf.st_rdev == rootStat.st_rdev) {
+ return fileName;
}
+ free(fileName);
}
+ closedir(dir);
- return( FALSE);
+ return NULL;
}
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 @@
* underrun the buffer if the string length is 0. Also avoids a possible
* 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) {
return sret;
} 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);
extern void write_mtab(char* blockDevice, char* directory,
char* filesystemType, long flags, char* string_flags);
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 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 void print_file(FILE *file);
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 *xreadlink(const char *path);
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 {
char *name;