tree-wide: use stat_verify_regular() more

This commit is contained in:
Lennart Poettering
2026-04-13 13:20:43 +02:00
parent bda7e91337
commit 8e0756c0b5
2 changed files with 8 additions and 4 deletions
+4 -2
View File
@@ -16,6 +16,7 @@
#include "path-util.h"
#include "process-util.h"
#include "set.h"
#include "stat-util.h"
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
@@ -115,8 +116,9 @@ static int add_locales_from_archive(Set *locales) {
if (fstat(fd, &st) < 0)
return -errno;
if (!S_ISREG(st.st_mode))
return -EBADMSG;
r = stat_verify_regular(&st);
if (r < 0)
return r;
if (st.st_size < (off_t) sizeof(struct locarhead))
return -EBADMSG;
+4 -2
View File
@@ -37,14 +37,16 @@ int read_fiemap(int fd, struct fiemap **ret) {
uint32_t result_extents = 0;
uint64_t fiemap_start = 0, fiemap_length;
const size_t n_extra = DIV_ROUND_UP(sizeof(struct fiemap), sizeof(struct fiemap_extent));
int r;
assert(fd >= 0);
assert(ret);
if (fstat(fd, &statinfo) < 0)
return log_debug_errno(errno, "Cannot determine file size: %m");
if (!S_ISREG(statinfo.st_mode))
return -ENOTTY;
r = stat_verify_regular(&statinfo);
if (r < 0)
return r;
fiemap_length = statinfo.st_size;
/* Zero this out in case we run on a file with no extents */