summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Makefile.in2
-rw-r--r--libbb/concat_subpath_file.c36
-rw-r--r--libbb/copy_file.c6
-rw-r--r--libbb/find_root_device.c7
-rw-r--r--libbb/isdirectory.c12
-rw-r--r--libbb/login.c50
-rw-r--r--libbb/pw_encrypt.c5
-rw-r--r--libbb/recursive_action.c6
-rw-r--r--libbb/remove_file.c6
-rw-r--r--libbb/run_shell.c4
-rw-r--r--libbb/setup_environment.c4
-rw-r--r--libbb/xgetcwd.c2
12 files changed, 79 insertions, 61 deletions
diff --git a/libbb/Makefile.in b/libbb/Makefile.in
index 06daf23..98b0c66 100644
--- a/libbb/Makefile.in
+++ b/libbb/Makefile.in
@@ -48,7 +48,7 @@ LIBBB_SRC:= \
fclose_nonstdin.c fflush_stdout_and_exit.c getopt_ulflags.c \
default_error_retval.c wfopen_input.c speed_table.c \
perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c \
- warn_ignoring_args.c
+ warn_ignoring_args.c concat_subpath_file.c
LIBBB_OBJS=$(patsubst %.c,$(LIBBB_DIR)%.o, $(LIBBB_SRC))
diff --git a/libbb/concat_subpath_file.c b/libbb/concat_subpath_file.c
new file mode 100644
index 0000000..6d86f5e
--- /dev/null
+++ b/libbb/concat_subpath_file.c
@@ -0,0 +1,36 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) (C) 2003 Vladimir Oleynik <dzo@simtreas.ru>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+/*
+ This function make special for recursive actions with usage
+ concat_path_file(path, filename)
+ and skiping "." and ".." directory entries
+*/
+
+#include "libbb.h"
+
+extern char *concat_subpath_file(const char *path, const char *f)
+{
+ if(f && *f == '.' && (!f[1] || (f[1] == '.' && !f[2])))
+ return NULL;
+ return concat_path_file(path, f);
+}
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index 81c5474..5808ca4 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
@@ -105,11 +105,9 @@ int copy_file(const char *source, const char *dest, int flags)
while ((d = readdir(dp)) != NULL) {
char *new_source, *new_dest;
- if (strcmp(d->d_name, ".") == 0 ||
- strcmp(d->d_name, "..") == 0)
+ new_source = concat_subpath_file(source, d->d_name);
+ if(new_source == NULL)
continue;
-
- new_source = concat_path_file(source, d->d_name);
new_dest = concat_path_file(dest, d->d_name);
if (copy_file(new_source, new_dest, flags) < 0)
status = -1;
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c
index 763ac75..b12d392 100644
--- a/libbb/find_root_device.c
+++ b/libbb/find_root_device.c
@@ -49,13 +49,10 @@ extern char *find_real_root_device_name(const char* name)
else {
while((entry = readdir(dir)) != NULL) {
- /* Must skip ".." since that is "/", and so we
- * would get a false positive on ".." */
- if (strcmp(entry->d_name, "..") == 0)
+ fileName = concat_subpath_file("/dev", entry->d_name);
+ if(fileName == NULL)
continue;
- fileName = concat_path_file("/dev", entry->d_name);
-
/* Some char devices have the same dev_t as block
* devices, so make sure this is a block device */
if (stat(fileName, &statBuf) == 0 &&
diff --git a/libbb/isdirectory.c b/libbb/isdirectory.c
index e8ef2df..e9b106a 100644
--- a/libbb/isdirectory.c
+++ b/libbb/isdirectory.c
@@ -20,8 +20,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <stdio.h>
-#include <stdlib.h>
#include <sys/stat.h>
#include "libbb.h"
@@ -32,11 +30,11 @@
int is_directory(const char *fileName, const int followLinks, struct stat *statBuf)
{
int status;
- int didMalloc = 0;
+ struct stat astatBuf;
if (statBuf == NULL) {
- statBuf = (struct stat *)xmalloc(sizeof(struct stat));
- ++didMalloc;
+ /* set from auto stack buffer */
+ statBuf = &astatBuf;
}
if (followLinks)
@@ -49,10 +47,6 @@ int is_directory(const char *fileName, const int followLinks, struct stat *statB
}
else status = TRUE;
- if (didMalloc) {
- free(statBuf);
- statBuf = NULL;
- }
return status;
}
diff --git a/libbb/login.c b/libbb/login.c
index bd8035f..67636e6 100644
--- a/libbb/login.c
+++ b/libbb/login.c
@@ -17,26 +17,28 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id: login.c,v 1.3 2003/05/13 13:28:25 bug1 Exp $
+ * Optimize and correcting OCRNL by Vladimir Oleynik <dzo@simtreas.ru>
*/
+#include <sys/param.h> /* MAXHOSTNAMELEN */
#include <stdio.h>
#include <unistd.h>
-#include "busybox.h"
+#include "libbb.h"
#include <sys/utsname.h>
#include <time.h>
#define LOGIN " login: "
-static char fmtstr_d[] = { "%A, %d %B %Y" };
-static char fmtstr_t[] = { "%H:%M:%S" };
+static const char fmtstr_d[] = "%A, %d %B %Y";
+static const char fmtstr_t[] = "%H:%M:%S";
void print_login_issue(const char *issue_file, const char *tty)
{
FILE *fd;
int c;
char buf[256];
+ const char *outbuf;
time_t t;
struct utsname uts;
@@ -47,73 +49,75 @@ void print_login_issue(const char *issue_file, const char *tty)
if ((fd = fopen(issue_file, "r"))) {
while ((c = fgetc(fd)) != EOF) {
+ outbuf = buf;
+ buf[0] = c;
+ if(c == '\n') {
+ buf[1] = '\r';
+ buf[2] = 0;
+ } else {
+ buf[1] = 0;
+ }
if (c == '\\' || c == '%') {
c = fgetc(fd);
-
switch (c) {
case 's':
- fputs(uts.sysname, stdout);
+ outbuf = uts.sysname;
break;
case 'n':
- fputs(uts.nodename, stdout);
+ outbuf = uts.nodename;
break;
case 'r':
- fputs(uts.release, stdout);
+ outbuf = uts.release;
break;
case 'v':
- fputs(uts.version, stdout);
+ outbuf = uts.version;
break;
case 'm':
- fputs(uts.machine, stdout);
+ outbuf = uts.machine;
break;
case 'D':
case 'o':
getdomainname(buf, sizeof(buf));
buf[sizeof(buf) - 1] = '\0';
- fputs(buf, stdout);
break;
case 'd':
strftime(buf, sizeof(buf), fmtstr_d, localtime(&t));
- fputs(buf, stdout);
break;
case 't':
strftime(buf, sizeof(buf), fmtstr_t, localtime(&t));
- fputs(buf, stdout);
break;
case 'h':
- gethostname(buf, sizeof(buf));
- fputs(buf, stdout);
+ gethostname(buf, sizeof(buf) - 1);
break;
case 'l':
- printf("%s", tty);
+ outbuf = tty;
break;
default:
- putchar(c);
+ buf[0] = c;
}
- } else
- putchar(c);
}
-
- puts(""); /* start a new line */
- fflush(stdout);
+ fputs(outbuf, stdout);
+ }
fclose(fd);
+
+ fflush(stdout);
}
}
void print_login_prompt(void)
{
- char buf[MAXHOSTNAMELEN];
+ char buf[MAXHOSTNAMELEN+1];
gethostname(buf, MAXHOSTNAMELEN);
fputs(buf, stdout);
diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c
index 0e4eb9f..ac79f83 100644
--- a/libbb/pw_encrypt.c
+++ b/libbb/pw_encrypt.c
@@ -39,10 +39,7 @@ extern char *pw_encrypt(const char *clear, const char *salt)
/* if crypt (a nonstandard crypt) returns a string too large,
truncate it so we don't overrun buffers and hope there is
enough security in what's left */
- if (strlen(cp) > sizeof(cipher)-1) {
- cp[sizeof(cipher)-1] = 0;
- }
- strcpy(cipher, cp);
+ safe_strncpy(cipher, cp, sizeof(cipher));
return cipher;
}
diff --git a/libbb/recursive_action.c b/libbb/recursive_action.c
index a4a4a7b..3ea107c 100644
--- a/libbb/recursive_action.c
+++ b/libbb/recursive_action.c
@@ -103,11 +103,9 @@ int recursive_action(const char *fileName,
while ((next = readdir(dir)) != NULL) {
char *nextFile;
- if ((strcmp(next->d_name, "..") == 0)
- || (strcmp(next->d_name, ".") == 0)) {
+ nextFile = concat_subpath_file(fileName, next->d_name);
+ if(nextFile == NULL)
continue;
- }
- nextFile = concat_path_file(fileName, next->d_name);
if (! recursive_action(nextFile, TRUE, followLinks, depthFirst,
fileAction, dirAction, userData)) {
status = FALSE;
diff --git a/libbb/remove_file.c b/libbb/remove_file.c
index 65708a2..8b45c58 100644
--- a/libbb/remove_file.c
+++ b/libbb/remove_file.c
@@ -79,11 +79,9 @@ extern int remove_file(const char *path, int flags)
while ((d = readdir(dp)) != NULL) {
char *new_path;
- if (strcmp(d->d_name, ".") == 0 ||
- strcmp(d->d_name, "..") == 0)
+ new_path = concat_subpath_file(path, d->d_name);
+ if(new_path == NULL)
continue;
-
- new_path = concat_path_file(path, d->d_name);
if (remove_file(new_path, flags) < 0)
status = -1;
free(new_path);
diff --git a/libbb/run_shell.c b/libbb/run_shell.c
index d154b98..49e8a76 100644
--- a/libbb/run_shell.c
+++ b/libbb/run_shell.c
@@ -52,10 +52,7 @@ void run_shell ( const char *shell, int loginshell, const char *command, const c
for ( args = additional_args; args && *args; args++ )
additional_args_cnt++;
- if ( additional_args )
args = (const char **) xmalloc (sizeof (char *) * ( 4 + additional_args_cnt ));
- else
- args = (const char **) xmalloc (sizeof (char *) * 4 );
args [0] = bb_get_last_path_component ( bb_xstrdup ( shell ));
@@ -77,4 +74,3 @@ void run_shell ( const char *shell, int loginshell, const char *command, const c
execv ( shell, (char **) args );
bb_perror_msg_and_die ( "cannot run %s", shell );
}
-
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c
index 30d317c..b18f896 100644
--- a/libbb/setup_environment.c
+++ b/libbb/setup_environment.c
@@ -45,13 +45,13 @@
static void xsetenv ( const char *key, const char *value )
{
if ( setenv ( key, value, 1 ))
- bb_error_msg_and_die ( "out of memory" );
+ bb_error_msg_and_die (bb_msg_memory_exhausted);
}
void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw )
{
if ( loginshell ) {
- char *term;
+ const char *term;
/* Change the current working directory to be the home directory
* of the user. It is a fatal error for this process to be unable
diff --git a/libbb/xgetcwd.c b/libbb/xgetcwd.c
index 85a5c41..1fcdba1 100644
--- a/libbb/xgetcwd.c
+++ b/libbb/xgetcwd.c
@@ -3,7 +3,7 @@
* Copyright (C) 1992, 1996 Free Software Foundation, Inc.
* Written by David MacKenzie <djm@gnu.ai.mit.edu>.
*
- * Special function for busybox written by Vladimir Oleynik <vodz@usa.net>
+ * Special function for busybox written by Vladimir Oleynik <dzo@simtreas.ru>
*/
#include <stdlib.h>