aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--archival/ar.c3
-rw-r--r--archival/tar.c3
-rw-r--r--include/libbb.h1
-rw-r--r--libbb/dump.c4
-rw-r--r--libbb/update_passwd.c2
-rw-r--r--libbb/xfuncs_printf.c10
-rw-r--r--miscutils/ubi_attach_detach.c4
-rw-r--r--shell/ash.c8
-rw-r--r--util-linux/mkfs_ext2.c2
-rw-r--r--util-linux/mkfs_minix.c3
-rw-r--r--util-linux/mkfs_reiser.c4
-rw-r--r--util-linux/mkfs_vfat.c3
-rw-r--r--util-linux/mkswap.c3
13 files changed, 29 insertions, 21 deletions
diff --git a/archival/ar.c b/archival/ar.c
index bce62f76d..05556c6cb 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -123,8 +123,7 @@ static int write_ar_archive(archive_handle_t *handle)
123 struct stat st; 123 struct stat st;
124 archive_handle_t *out_handle; 124 archive_handle_t *out_handle;
125 125
126 if (fstat(handle->src_fd, &st) == -1) 126 xfstat(handle->src_fd, &st, handle->ar__name);
127 bb_simple_perror_msg_and_die(handle->ar__name);
128 127
129 /* if archive exists, create a new handle for output. 128 /* if archive exists, create a new handle for output.
130 * we create it in place of the old one. 129 * we create it in place of the old one.
diff --git a/archival/tar.c b/archival/tar.c
index b5cbf4197..2176ad2ac 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -572,8 +572,7 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
572 572
573 /* Store the stat info for the tarball's file, so 573 /* Store the stat info for the tarball's file, so
574 * can avoid including the tarball into itself.... */ 574 * can avoid including the tarball into itself.... */
575 if (fstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf) < 0) 575 xfstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf, "can't stat tar file");
576 bb_perror_msg_and_die("can't stat tar file");
577 576
578#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2 577#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
579 if (gzip) 578 if (gzip)
diff --git a/include/libbb.h b/include/libbb.h
index 43e525cb9..6fb0438f5 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -411,6 +411,7 @@ void bb_unsetenv(const char *key) FAST_FUNC;
411void bb_unsetenv_and_free(char *key) FAST_FUNC; 411void bb_unsetenv_and_free(char *key) FAST_FUNC;
412void xunlink(const char *pathname) FAST_FUNC; 412void xunlink(const char *pathname) FAST_FUNC;
413void xstat(const char *pathname, struct stat *buf) FAST_FUNC; 413void xstat(const char *pathname, struct stat *buf) FAST_FUNC;
414void xfstat(int fd, struct stat *buf, const char *errmsg) FAST_FUNC;
414int xopen(const char *pathname, int flags) FAST_FUNC; 415int xopen(const char *pathname, int flags) FAST_FUNC;
415int xopen_nonblocking(const char *pathname) FAST_FUNC; 416int xopen_nonblocking(const char *pathname) FAST_FUNC;
416int xopen3(const char *pathname, int flags, int mode) FAST_FUNC; 417int xopen3(const char *pathname, int flags, int mode) FAST_FUNC;
diff --git a/libbb/dump.c b/libbb/dump.c
index a739ff61e..4db3f06f0 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)
323 struct stat sbuf; 323 struct stat sbuf;
324 324
325 if (statok) { 325 if (statok) {
326 if (fstat(STDIN_FILENO, &sbuf)) { 326 xfstat(STDIN_FILENO, &sbuf, fname);
327 bb_simple_perror_msg_and_die(fname);
328 }
329 if (!(S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode) || S_ISFIFO(sbuf.st_mode)) 327 if (!(S_ISCHR(sbuf.st_mode) || S_ISBLK(sbuf.st_mode) || S_ISFIFO(sbuf.st_mode))
330 && dumper->pub.dump_skip >= sbuf.st_size 328 && dumper->pub.dump_skip >= sbuf.st_size
331 ) { 329 ) {
diff --git a/libbb/update_passwd.c b/libbb/update_passwd.c
index e050dfc0e..a2be0f155 100644
--- a/libbb/update_passwd.c
+++ b/libbb/update_passwd.c
@@ -133,7 +133,7 @@ int FAST_FUNC update_passwd(const char *filename,
133 goto close_old_fp; 133 goto close_old_fp;
134 134
135 created: 135 created:
136 if (!fstat(old_fd, &sb)) { 136 if (fstat(old_fd, &sb) == 0) {
137 fchmod(new_fd, sb.st_mode & 0777); /* ignore errors */ 137 fchmod(new_fd, sb.st_mode & 0777); /* ignore errors */
138 fchown(new_fd, sb.st_uid, sb.st_gid); 138 fchown(new_fd, sb.st_uid, sb.st_gid);
139 } 139 }
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c
index b99f906df..c6db38d33 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)
436 bb_perror_msg_and_die("can't stat '%s'", name); 436 bb_perror_msg_and_die("can't stat '%s'", name);
437} 437}
438 438
439void FAST_FUNC xfstat(int fd, struct stat *stat_buf, const char *errmsg)
440{
441 /* errmsg is usually a file name, but not always:
442 * xfstat may be called in a spot where file name is no longer
443 * available, and caller may give e.g. "can't stat input file" string.
444 */
445 if (fstat(fd, stat_buf))
446 bb_simple_perror_msg_and_die(errmsg);
447}
448
439// selinux_or_die() - die if SELinux is disabled. 449// selinux_or_die() - die if SELinux is disabled.
440void FAST_FUNC selinux_or_die(void) 450void FAST_FUNC selinux_or_die(void)
441{ 451{
diff --git a/miscutils/ubi_attach_detach.c b/miscutils/ubi_attach_detach.c
index 15377aa37..18ffd4df2 100644
--- a/miscutils/ubi_attach_detach.c
+++ b/miscutils/ubi_attach_detach.c
@@ -63,9 +63,9 @@ int ubi_attach_detach_main(int argc UNUSED_PARAM, char **argv)
63 ubi_ctrl = argv[optind]; 63 ubi_ctrl = argv[optind];
64 64
65 fd = xopen(ubi_ctrl, O_RDWR); 65 fd = xopen(ubi_ctrl, O_RDWR);
66 //fstat(fd, &st); 66 //xfstat(fd, &st, ubi_ctrl);
67 //if (!S_ISCHR(st.st_mode)) 67 //if (!S_ISCHR(st.st_mode))
68 // bb_error_msg_and_die("'%s' is not a char device", ubi_ctrl); 68 // bb_error_msg_and_die("%s: not a char device", ubi_ctrl);
69 69
70 if (do_attach) { 70 if (do_attach) {
71 if (!(opts & OPTION_M)) 71 if (!(opts & OPTION_M))
diff --git a/shell/ash.c b/shell/ash.c
index 921367be5..28a8bb60c 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -4989,9 +4989,13 @@ noclobberopen(const char *fname)
4989 * revealed that it was a regular file, and the file has not been 4989 * revealed that it was a regular file, and the file has not been
4990 * replaced, return the file descriptor. 4990 * replaced, return the file descriptor.
4991 */ 4991 */
4992 if (fstat(fd, &finfo2) == 0 && !S_ISREG(finfo2.st_mode) 4992 if (fstat(fd, &finfo2) == 0
4993 && finfo.st_dev == finfo2.st_dev && finfo.st_ino == finfo2.st_ino) 4993 && !S_ISREG(finfo2.st_mode)
4994 && finfo.st_dev == finfo2.st_dev
4995 && finfo.st_ino == finfo2.st_ino
4996 ) {
4994 return fd; 4997 return fd;
4998 }
4995 4999
4996 /* The file has been replaced. badness. */ 5000 /* The file has been replaced. badness. */
4997 close(fd); 5001 close(fd);
diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c
index 1c2b3b2e2..6dccd3a5d 100644
--- a/util-linux/mkfs_ext2.c
+++ b/util-linux/mkfs_ext2.c
@@ -221,7 +221,7 @@ int mkfs_ext2_main(int argc UNUSED_PARAM, char **argv)
221 221
222 // open the device, check the device is a block device 222 // open the device, check the device is a block device
223 xmove_fd(xopen(argv[0], O_WRONLY), fd); 223 xmove_fd(xopen(argv[0], O_WRONLY), fd);
224 fstat(fd, &st); 224 xfstat(fd, &st, argv[0]);
225 if (!S_ISBLK(st.st_mode) && !(option_mask32 & OPT_F)) 225 if (!S_ISBLK(st.st_mode) && !(option_mask32 & OPT_F))
226 bb_error_msg_and_die("%s: not a block device", argv[0]); 226 bb_error_msg_and_die("%s: not a block device", argv[0]);
227 227
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c
index 9e826aef3..95499ba17 100644
--- a/util-linux/mkfs_minix.c
+++ b/util-linux/mkfs_minix.c
@@ -686,8 +686,7 @@ int mkfs_minix_main(int argc UNUSED_PARAM, char **argv)
686 bb_error_msg_and_die("can't format mounted filesystem"); 686 bb_error_msg_and_die("can't format mounted filesystem");
687 687
688 xmove_fd(xopen(G.device_name, O_RDWR), dev_fd); 688 xmove_fd(xopen(G.device_name, O_RDWR), dev_fd);
689 if (fstat(dev_fd, &statbuf) < 0) 689 xfstat(dev_fd, &statbuf, G.device_name);
690 bb_error_msg_and_die("can't stat '%s'", G.device_name);
691 if (!S_ISBLK(statbuf.st_mode)) 690 if (!S_ISBLK(statbuf.st_mode))
692 opt &= ~1; // clear -c (check) 691 opt &= ~1; // clear -c (check)
693 692
diff --git a/util-linux/mkfs_reiser.c b/util-linux/mkfs_reiser.c
index 6e172d6d3..00ce8f1d1 100644
--- a/util-linux/mkfs_reiser.c
+++ b/util-linux/mkfs_reiser.c
@@ -168,9 +168,9 @@ int mkfs_reiser_main(int argc UNUSED_PARAM, char **argv)
168 168
169 // check the device is a block device 169 // check the device is a block device
170 fd = xopen(argv[0], O_WRONLY | O_EXCL); 170 fd = xopen(argv[0], O_WRONLY | O_EXCL);
171 fstat(fd, &st); 171 xfstat(fd, &st, argv[0]);
172 if (!S_ISBLK(st.st_mode) && !(option_mask32 & OPT_f)) 172 if (!S_ISBLK(st.st_mode) && !(option_mask32 & OPT_f))
173 bb_error_msg_and_die("not a block device"); 173 bb_error_msg_and_die("%s: not a block device", argv[0]);
174 174
175 // check if it is mounted 175 // check if it is mounted
176 // N.B. what if we format a file? find_mount_point will return false negative since 176 // N.B. what if we format a file? find_mount_point will return false negative since
diff --git a/util-linux/mkfs_vfat.c b/util-linux/mkfs_vfat.c
index 211e67e97..45760f7c5 100644
--- a/util-linux/mkfs_vfat.c
+++ b/util-linux/mkfs_vfat.c
@@ -245,8 +245,7 @@ int mkfs_vfat_main(int argc UNUSED_PARAM, char **argv)
245 volume_id = time(NULL); 245 volume_id = time(NULL);
246 246
247 dev = xopen(device_name, O_RDWR); 247 dev = xopen(device_name, O_RDWR);
248 if (fstat(dev, &st) < 0) 248 xfstat(dev, &st, device_name);
249 bb_simple_perror_msg_and_die(device_name);
250 249
251 // 250 //
252 // Get image size and sector size 251 // Get image size and sector size
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c
index 61a786e92..53537fcd9 100644
--- a/util-linux/mkswap.c
+++ b/util-linux/mkswap.c
@@ -15,8 +15,7 @@ static void mkswap_selinux_setcontext(int fd, const char *path)
15 if (!is_selinux_enabled()) 15 if (!is_selinux_enabled())
16 return; 16 return;
17 17
18 if (fstat(fd, &stbuf) < 0) 18 xfstat(fd, &stbuf, argv[0]);
19 bb_perror_msg_and_die("fstat failed");
20 if (S_ISREG(stbuf.st_mode)) { 19 if (S_ISREG(stbuf.st_mode)) {
21 security_context_t newcon; 20 security_context_t newcon;
22 security_context_t oldcon = NULL; 21 security_context_t oldcon = NULL;