diff options
author | Timo Teräs <timo.teras@solidboot.com> | 2023-04-10 13:41:19 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2023-04-11 20:55:13 +0300 |
commit | 9176a977d9f0970e3251493fcd71f3c1be0834ae (patch) | |
tree | 30fc7dce93bc6c2e319769b6cab905d4867dcd27 /src | |
parent | 1f6a072373f1f85dd490c9f34ea83843c746847d (diff) | |
download | apk-tools-9176a977d9f0970e3251493fcd71f3c1be0834ae.tar.gz apk-tools-9176a977d9f0970e3251493fcd71f3c1be0834ae.tar.bz2 apk-tools-9176a977d9f0970e3251493fcd71f3c1be0834ae.tar.xz apk-tools-9176a977d9f0970e3251493fcd71f3c1be0834ae.zip |
io: harden apk_fileinfo_get
Do not attempt to get xattrs from symlinks. Their extraction is not
supported either.
Do not use alloca.
Diffstat (limited to 'src')
-rw-r--r-- | src/io.c | 8 |
1 files changed, 3 insertions, 5 deletions
@@ -737,7 +737,7 @@ int apk_fileinfo_get(int atfd, const char *filename, unsigned int flags, .device = st.st_dev, }; - if (xattr_checksum != APK_CHECKSUM_NONE) { + if (xattr_checksum != APK_CHECKSUM_NONE && !S_ISLNK(fi->mode)) { ssize_t len, vlen; int fd, i, r; char val[1024], buf[1024]; @@ -775,12 +775,10 @@ int apk_fileinfo_get(int atfd, const char *filename, unsigned int flags, /* Checksum file content */ if ((flags & APK_FI_NOFOLLOW) && S_ISLNK(st.st_mode)) { - char *target = alloca(st.st_size); - if (target == NULL) - return -ENOMEM; + char target[PATH_MAX]; + if (st.st_size > sizeof target) return -ENOMEM; if (readlinkat(atfd, filename, target, st.st_size) < 0) return -errno; - EVP_Digest(target, st.st_size, fi->csum.data, NULL, apk_checksum_evp(checksum), NULL); fi->csum.type = checksum; |