summaryrefslogtreecommitdiffstats
path: root/src/opk
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2023-05-11 05:08:31 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2023-05-11 05:08:31 (EDT)
commite607c970a422a91420d50201a5ac41a131b4de46 (patch)
tree84465ecc4a7542c4cdfda5b7f9e11c32e0aca590 /src/opk
parent3bcb98c1002bcb1661165679e2df945d690667c3 (diff)
opk/write: Error-check lstat() and rename var
Diffstat (limited to 'src/opk')
-rw-r--r--src/opk/write.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/opk/write.c b/src/opk/write.c
index 44629db..7940222 100644
--- a/src/opk/write.c
+++ b/src/opk/write.c
@@ -92,7 +92,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
int i;
struct opkg_opk_dirent child;
size_t j;
- struct stat stat;
+ struct stat st;
uid_t uid;
char *uname;
gid_t gid;
@@ -135,16 +135,21 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
child_path[j] = names[i]->d_name[j];
}
child_path[j] = '\0';
- lstat(opk->path, &stat);
+ if (lstat(opk->path, &st) != 0) {
+ fprintf(stderr, _("Error: Failed to stat \"%s\"\n"),
+ opk->path);
+ ret = OPKG_OPK_ERROR;
+ goto out1;
+ }
/* TODO: Ownership override */
- uid = stat.st_uid;
+ uid = st.st_uid;
uname = getpwuid(uid)->pw_name;
- gid = stat.st_gid;
+ gid = st.st_gid;
gname = getgrgid(gid)->gr_name;
- if (S_ISDIR(stat.st_mode)) {
+ if (S_ISDIR(st.st_mode)) {
if (opkg_opk_ustar_write_header(opk->inner_ustar,
&child,
- stat.st_mode & 0777,
+ st.st_mode & 0777,
uid, uname, gid, gname, 0,
opk->mtime, 'd', NULL) !=
OPKG_OPK_OK) {
@@ -158,7 +163,7 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
ret = OPKG_OPK_ERROR;
goto out1;
}
- } else if (S_ISLNK(stat.st_mode)) {
+ } else if (S_ISLNK(st.st_mode)) {
link_len = readlink(opk->path, link,
OPKG_OPK_USTAR_LINKNAME_SIZE);
if (link_len < 0) {
@@ -180,18 +185,18 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
ret = OPKG_OPK_ERROR;
goto out1;
}
- } else if (S_ISCHR(stat.st_mode)) {
+ } else if (S_ISCHR(st.st_mode)) {
/* TODO */
- } else if (S_ISBLK(stat.st_mode)) {
+ } else if (S_ISBLK(st.st_mode)) {
/* TODO */
- } else if (S_ISFIFO(stat.st_mode)) {
+ } else if (S_ISFIFO(st.st_mode)) {
/* TODO */
- } else if (S_ISREG(stat.st_mode)) {
+ } else if (S_ISREG(st.st_mode)) {
if (opkg_opk_ustar_write_header(opk->inner_ustar,
&child,
- stat.st_mode & 0777,
+ st.st_mode & 0777,
uid, uname, gid, gname,
- stat.st_size,
+ st.st_size,
opk->mtime, '-', NULL) !=
OPKG_OPK_OK) {
fputs(_("Error: Failed to write header\n"),
@@ -226,10 +231,10 @@ _opkg_opk_opk_write_dir_read(struct opkg_opk_opk *opk,
ret = OPKG_OPK_ERROR;
goto out1;
}
- if ((uintmax_t) tot_read != (uintmax_t) stat.st_size) {
+ if ((uintmax_t) tot_read != (uintmax_t) st.st_size) {
fprintf(stderr, _("Error: Expected %jd bytes "
"but read %zu\n"),
- (intmax_t) stat.st_size,
+ (intmax_t) st.st_size,
num_read);
ret = OPKG_OPK_ERROR;
goto out1;