summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/dump.c4
-rw-r--r--libbb/update_passwd.c2
-rw-r--r--libbb/xfuncs_printf.c10
3 files changed, 12 insertions, 4 deletions
diff --git a/libbb/dump.c b/libbb/dump.c
index a739ff6..4db3f06 100644
--- a/libbb/dump.c
+++ b/libbb/dump.c
@@ -323,9 +323,7 @@ static void do_skip(priv_dumper_t *dumper, const char *fname, int statok)
struct stat sbuf;
if (statok) {
- if (fstat(STDIN_FILENO, &sbuf)) {
- bb_simple_perror_msg_and_die(fname);
- }
+ xfstat(STDIN_FILENO, &sbuf, fname);
if (!(S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode) || S_ISFIFO(sbuf.st_mode))
&& dumper->pub.dump_skip >= sbuf.st_size
) {
diff --git a/libbb/update_passwd.c b/libbb/update_passwd.c
index e050dfc..a2be0f1 100644
--- a/libbb/update_passwd.c
+++ b/libbb/update_passwd.c
@@ -133,7 +133,7 @@ int FAST_FUNC update_passwd(const char *filename,
goto close_old_fp;
created:
- if (!fstat(old_fd, &sb)) {
+ if (fstat(old_fd, &sb) == 0) {
fchmod(new_fd, sb.st_mode & 0777); /* ignore errors */
fchown(new_fd, sb.st_uid, sb.st_gid);
}
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index b99f906..c6db38d 100644
--- a/libbb/xfuncs_printf.c
+++ b/libbb/xfuncs_printf.c
@@ -436,6 +436,16 @@ void FAST_FUNC xstat(const char *name, struct stat *stat_buf)
bb_perror_msg_and_die("can't stat '%s'", name);
}
+void FAST_FUNC xfstat(int fd, struct stat *stat_buf, const char *errmsg)
+{
+ /* errmsg is usually a file name, but not always:
+ * xfstat may be called in a spot where file name is no longer
+ * available, and caller may give e.g. "can't stat input file" string.
+ */
+ if (fstat(fd, stat_buf))
+ bb_simple_perror_msg_and_die(errmsg);
+}
+
// selinux_or_die() - die if SELinux is disabled.
void FAST_FUNC selinux_or_die(void)
{