From 50a061df5105478ea5f0c0bdc3891d646c50eea3 Mon Sep 17 00:00:00 2001 From: vda Date: Tue, 10 Apr 2007 15:43:37 +0000 Subject: audit small applets and mark some of them as NOFORK. Put big scary warnings in relevant places. git-svn-id: svn://busybox.net/trunk/busybox@18382 69ca8d6d-28ef-0310-b511-8ec308f3f277 --- libbb/copyfd.c | 11 ++++------- libbb/fflush_stdout_and_exit.c | 4 ++++ libbb/make_directory.c | 5 ++--- libbb/parse_mode.c | 2 ++ libbb/remove_file.c | 2 ++ 5 files changed, 14 insertions(+), 10 deletions(-) (limited to 'libbb') diff --git a/libbb/copyfd.c b/libbb/copyfd.c index 805b80187..e0596d5f6 100644 --- a/libbb/copyfd.c +++ b/libbb/copyfd.c @@ -7,19 +7,15 @@ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ -#include -#include -#include -#include - #include "libbb.h" - #if BUFSIZ < 4096 #undef BUFSIZ #define BUFSIZ 4096 #endif +/* Used by NOFORK applets (e.g. cat) - must be very careful + * when calling xfuncs, allocating memory, with signals, termios, etc... */ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size) { @@ -27,7 +23,8 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size) off_t total = 0; RESERVE_CONFIG_BUFFER(buffer, BUFSIZ); - if (src_fd < 0) goto out; + if (src_fd < 0) + goto out; if (!size) { size = BUFSIZ; diff --git a/libbb/fflush_stdout_and_exit.c b/libbb/fflush_stdout_and_exit.c index 6f44770c6..ae68222b4 100644 --- a/libbb/fflush_stdout_and_exit.c +++ b/libbb/fflush_stdout_and_exit.c @@ -13,6 +13,10 @@ #include "libbb.h" +// TODO: make it safe to call from NOFORK applets +// Currently, it can exit(0). Even if it is made to do longjmp trick +// (see sleep_and_die internals), zero cannot be passed thru this way! + void fflush_stdout_and_exit(int retval) { if (fflush(stdout)) diff --git a/libbb/make_directory.c b/libbb/make_directory.c index fbec4e20e..d540ad133 100644 --- a/libbb/make_directory.c +++ b/libbb/make_directory.c @@ -22,11 +22,10 @@ * val. Otherwise, pass -1 to get default permissions. */ -#include -#include -#include #include "libbb.h" +/* This function is used from NOFORK applets. It must not allocate anything */ + int bb_make_directory (char *path, long mode, int flags) { mode_t mask; diff --git a/libbb/parse_mode.c b/libbb/parse_mode.c index 3ab4eb6fc..a31bd4bfd 100644 --- a/libbb/parse_mode.c +++ b/libbb/parse_mode.c @@ -11,6 +11,8 @@ #include "libbb.h" +/* This function is used from NOFORK applets. It must not allocate anything */ + #define FILEMODEBITS (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) int bb_parse_mode(const char *s, mode_t *current_mode) diff --git a/libbb/remove_file.c b/libbb/remove_file.c index 3aaaef8c7..3edc91dae 100644 --- a/libbb/remove_file.c +++ b/libbb/remove_file.c @@ -9,6 +9,8 @@ #include "libbb.h" +/* Used from NOFORK applets. Must not allocate anything */ + int remove_file(const char *path, int flags) { struct stat path_stat; -- cgit v1.2.3-55-g6feb