commit: 3d9401137c5034e53f9bd31b1e5dbf9365c6c260
parent 413335f482a5d6d79e33ffa321c71d8fe883d200
Author: Michael Forney <mforney@mforney.org>
Date: Fri, 31 Jan 2020 23:49:33 -0800
squashfs-tools: Fix a few portability issues
Diffstat:
5 files changed, 313 insertions(+), 1 deletion(-)
diff --git a/.gitmodules b/.gitmodules
@@ -247,6 +247,7 @@
[submodule "pkg/squashfs-tools/src"]
path = pkg/squashfs-tools/src
url = https://github.com/plougher/squashfs-tools.git
+ ignore = all
[submodule "pkg/sshfs/src"]
path = pkg/sshfs/src
url = https://github.com/libfuse/sshfs
diff --git a/pkg/squashfs-tools/patch/0001-Avoid-pointer-arithmetic-with-void.patch b/pkg/squashfs-tools/patch/0001-Avoid-pointer-arithmetic-with-void.patch
@@ -0,0 +1,109 @@
+From 7668bc8b07dec7eeb8f2682e50ae5c740c25c704 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Thu, 30 Jan 2020 11:38:23 -0800
+Subject: [PATCH] Avoid pointer arithmetic with `void *`
+
+`void *` is a pointer to an incomplete type, so cannot be used in
+pointer arithmetic.
+---
+ squashfs-tools/action.c | 2 +-
+ squashfs-tools/mksquashfs.c | 10 +++++-----
+ squashfs-tools/unsquashfs.c | 6 +++---
+ 3 files changed, 9 insertions(+), 9 deletions(-)
+
+diff --git a/squashfs-tools/action.c b/squashfs-tools/action.c
+index 4b06ccb..b107470 100644
+--- a/squashfs-tools/action.c
++++ b/squashfs-tools/action.c
+@@ -950,7 +950,7 @@ void *get_frag_action(void *fragment)
+ if (fragment == &def_fragment)
+ action = &fragment_spec[0] - 1;
+ else
+- action = fragment - offsetof(struct action, data);
++ action = (struct action *)((char *)fragment - offsetof(struct action, data));
+
+ if (++action == spec_list_end)
+ return NULL;
+diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
+index a45b77f..d9e7b01 100644
+--- a/squashfs-tools/mksquashfs.c
++++ b/squashfs-tools/mksquashfs.c
+@@ -516,7 +516,7 @@ int read_bytes(int fd, void *buff, int bytes)
+ int res, count;
+
+ for(count = 0; count < bytes; count += res) {
+- res = read(fd, buff + count, bytes - count);
++ res = read(fd, (char *)buff + count, bytes - count);
+ if(res < 1) {
+ if(res == 0)
+ goto bytes_read;
+@@ -563,7 +563,7 @@ int write_bytes(int fd, void *buff, int bytes)
+ int res, count;
+
+ for(count = 0; count < bytes; count += res) {
+- res = write(fd, buff + count, bytes - count);
++ res = write(fd, (char *)buff + count, bytes - count);
+ if(res == -1) {
+ if(errno != EINTR) {
+ ERROR("Write failed because %s\n",
+@@ -889,7 +889,7 @@ int create_inode(squashfs_inode *i_no, struct dir_info *dir_info,
+ struct stat *buf = &dir_ent->inode->buf;
+ union squashfs_inode_header inode_header;
+ struct squashfs_base_inode_header *base = &inode_header.base;
+- void *inode;
++ char *inode;
+ char *filename = pathname(dir_ent);
+ int nlink = dir_ent->inode->nlink;
+ int xattr = read_xattrs(dir_ent);
+@@ -982,7 +982,7 @@ int create_inode(squashfs_inode *i_no, struct dir_info *dir_info,
+ }
+ else if(type == SQUASHFS_LDIR_TYPE) {
+ int i;
+- unsigned char *p;
++ char *p;
+ struct squashfs_ldir_inode_header *dir = &inode_header.ldir;
+ struct cached_dir_index *index = dir_in->index;
+ unsigned int i_count = dir_in->i_count;
+@@ -1680,7 +1680,7 @@ long long generic_write_table(int length, void *buffer, int length2,
+ for(i = 0; i < meta_blocks; i++) {
+ int avail_bytes = length > SQUASHFS_METADATA_SIZE ?
+ SQUASHFS_METADATA_SIZE : length;
+- c_byte = mangle(cbuffer + BLOCK_OFFSET, buffer + i *
++ c_byte = mangle(cbuffer + BLOCK_OFFSET, (char *)buffer + i *
+ SQUASHFS_METADATA_SIZE , avail_bytes,
+ SQUASHFS_METADATA_SIZE, uncompressed, 0);
+ SQUASHFS_SWAP_SHORTS(&c_byte, cbuffer, 1);
+diff --git a/squashfs-tools/unsquashfs.c b/squashfs-tools/unsquashfs.c
+index 727f1d5..5e8b2cb 100644
+--- a/squashfs-tools/unsquashfs.c
++++ b/squashfs-tools/unsquashfs.c
+@@ -640,7 +640,7 @@ int read_fs_bytes(int fd, long long byte, int bytes, void *buff)
+ }
+
+ for(count = 0; count < bytes; count += res) {
+- res = read(fd, buff + count, bytes - count);
++ res = read(fd, (char *)buff + count, bytes - count);
+ if(res < 1) {
+ if(res == 0) {
+ ERROR("Read on filesystem failed because "
+@@ -748,7 +748,7 @@ void *read_inode_table(long long start, long long end)
+ int res;
+ long long size = 0;
+ long long bytes = 0;
+- void *inode_table = NULL;
++ char *inode_table = NULL;
+
+ TRACE("read_inode_table: start %lld, end %lld\n", start, end);
+
+@@ -1226,7 +1226,7 @@ void *read_directory_table(long long start, long long end)
+ int res;
+ long long bytes = 0;
+ long long size = 0;
+- void *directory_table = malloc(1);
++ char *directory_table = malloc(1);
+
+ TRACE("read_directory_table: start %lld, end %lld\n", start, end);
+
+--
+2.25.0
+
diff --git a/pkg/squashfs-tools/patch/0002-Don-t-omit-second-operand-to-conditional-operator.patch b/pkg/squashfs-tools/patch/0002-Don-t-omit-second-operand-to-conditional-operator.patch
@@ -0,0 +1,53 @@
+From 4f371cd8042d8b574a49d07c5bca1417e08d366c Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Thu, 30 Jan 2020 11:40:49 -0800
+Subject: [PATCH] Don't omit second operand to conditional operator
+
+This is a GNU C extension, and not valid in ISO C.
+---
+ squashfs-tools/action.c | 5 ++++-
+ squashfs-tools/mksquashfs.c | 4 ++--
+ 2 files changed, 6 insertions(+), 3 deletions(-)
+
+diff --git a/squashfs-tools/action.c b/squashfs-tools/action.c
+index b107470..38438dc 100644
+--- a/squashfs-tools/action.c
++++ b/squashfs-tools/action.c
+@@ -632,8 +632,11 @@ char *_expr_log(char *string, int cmnd)
+ break;
+ }
+
++ size = strlen(string);
++
+ /* if string is empty append '\0' */
+- size = strlen(string) ? : 1;
++ if (size == 0)
++ size = 1;
+
+ if(alloc_size - cur_size < size) {
+ /* buffer too small, expand */
+diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c
+index d9e7b01..a5d0e69 100644
+--- a/squashfs-tools/mksquashfs.c
++++ b/squashfs-tools/mksquashfs.c
+@@ -773,7 +773,7 @@ char *_pathname(struct dir_ent *dir_ent, char *pathname, int *size)
+ for(;;) {
+ int res = snprintf(pathname, *size, "%s/%s",
+ dir_ent->our_dir->pathname,
+- dir_ent->source_name ? : dir_ent->name);
++ dir_ent->source_name ? dir_ent->source_name : dir_ent->name);
+
+ if(res < 0)
+ BAD_ERROR("snprintf failed in pathname\n");
+@@ -3154,7 +3154,7 @@ static inline struct inode_info *lookup_inode(struct stat *buf)
+ static inline void alloc_inode_no(struct inode_info *inode, unsigned int use_this)
+ {
+ if (inode->inode_number == 0) {
+- inode->inode_number = use_this ? : inode_no ++;
++ inode->inode_number = use_this ? use_this : inode_no ++;
+ if((inode->buf.st_mode & S_IFMT) == S_IFREG)
+ progress_bar_size((inode->buf.st_size + block_size - 1)
+ >> block_log);
+--
+2.25.0
+
diff --git a/pkg/squashfs-tools/patch/0003-Convert-TOK_TO_STR-to-an-inline-function.patch b/pkg/squashfs-tools/patch/0003-Convert-TOK_TO_STR-to-an-inline-function.patch
@@ -0,0 +1,149 @@
+From 5bab68afaeaab209cde2ddb8767f0aa3f5b30e9f Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Fri, 31 Jan 2020 17:59:06 -0800
+Subject: [PATCH] Convert TOK_TO_STR to an inline function
+
+This avoids the use of statement expressions, which are a GNU C
+extension.
+---
+ squashfs-tools/action.c | 33 ++++++++++++++++++++++++---------
+ squashfs-tools/action.h | 16 ----------------
+ 2 files changed, 24 insertions(+), 25 deletions(-)
+
+diff --git a/squashfs-tools/action.c b/squashfs-tools/action.c
+index 38438dc..18505dc 100644
+--- a/squashfs-tools/action.c
++++ b/squashfs-tools/action.c
+@@ -91,6 +91,21 @@ extern char *subpathname(struct dir_ent *);
+
+ extern int read_file(char *filename, char *type, int (parse_line)(char *));
+
++static inline char *tok_to_str(int op, char *s)
++{
++ switch(op) {
++ case TOK_EOF:
++ s = "EOF";
++ break;
++ case TOK_STRING:
++ break;
++ default:
++ s = token_table[op].string;
++ break;
++ }
++ return s;
++}
++
+ /*
+ * Lexical analyser
+ */
+@@ -321,7 +336,7 @@ static struct expr *parse_test(char *name)
+ while(1) {
+ if (token != TOK_STRING) {
+ SYNTAX_ERROR("Unexpected token \"%s\", expected "
+- "argument\n", TOK_TO_STR(token, string));
++ "argument\n", tok_to_str(token, string));
+ goto failed;
+ }
+
+@@ -338,7 +353,7 @@ static struct expr *parse_test(char *name)
+
+ if (token != TOK_COMMA) {
+ SYNTAX_ERROR("Unexpected token \"%s\", expected "
+- "\",\" or \")\"\n", TOK_TO_STR(token, string));
++ "\",\" or \")\"\n", tok_to_str(token, string));
+ goto failed;
+ }
+ token = get_token(&string);
+@@ -388,7 +403,7 @@ static struct expr *get_atom()
+ default:
+ SYNTAX_ERROR("Unexpected token \"%s\", expected test "
+ "operation, \"!\", or \"(\"\n",
+- TOK_TO_STR(token, string));
++ tok_to_str(token, string));
+ return NULL;
+ }
+ }
+@@ -425,7 +440,7 @@ static struct expr *parse_expr(int subexp)
+ if (op != TOK_AND && op != TOK_OR) {
+ free_parse_tree(expr);
+ SYNTAX_ERROR("Unexpected token \"%s\", expected "
+- "\"&&\" or \"||\"\n", TOK_TO_STR(op, string));
++ "\"&&\" or \"||\"\n", tok_to_str(op, string));
+ return NULL;
+ }
+
+@@ -454,7 +469,7 @@ int parse_action(char *s, int verbose)
+
+ if (token != TOK_STRING) {
+ SYNTAX_ERROR("Unexpected token \"%s\", expected name\n",
+- TOK_TO_STR(token, string));
++ tok_to_str(token, string));
+ return 0;
+ }
+
+@@ -476,7 +491,7 @@ int parse_action(char *s, int verbose)
+
+ if (token != TOK_OPEN_BRACKET) {
+ SYNTAX_ERROR("Unexpected token \"%s\", expected \"(\"\n",
+- TOK_TO_STR(token, string));
++ tok_to_str(token, string));
+ goto failed;
+ }
+
+@@ -492,7 +507,7 @@ int parse_action(char *s, int verbose)
+ while (1) {
+ if (token != TOK_STRING) {
+ SYNTAX_ERROR("Unexpected token \"%s\", expected "
+- "argument\n", TOK_TO_STR(token, string));
++ "argument\n", tok_to_str(token, string));
+ goto failed;
+ }
+
+@@ -509,7 +524,7 @@ int parse_action(char *s, int verbose)
+
+ if (token != TOK_COMMA) {
+ SYNTAX_ERROR("Unexpected token \"%s\", expected "
+- "\",\" or \")\"\n", TOK_TO_STR(token, string));
++ "\",\" or \")\"\n", tok_to_str(token, string));
+ goto failed;
+ }
+ token = get_token(&string);
+@@ -537,7 +552,7 @@ skip_args:
+
+ if (token != TOK_AT) {
+ SYNTAX_ERROR("Unexpected token \"%s\", expected \"@\"\n",
+- TOK_TO_STR(token, string));
++ tok_to_str(token, string));
+ goto failed;
+ }
+
+diff --git a/squashfs-tools/action.h b/squashfs-tools/action.h
+index 0a8de7c..156162d 100644
+--- a/squashfs-tools/action.h
++++ b/squashfs-tools/action.h
+@@ -38,22 +38,6 @@
+ #define TOK_STRING 8
+ #define TOK_EOF 9
+
+-#define TOK_TO_STR(OP, S) ({ \
+- char *s; \
+- switch(OP) { \
+- case TOK_EOF: \
+- s = "EOF"; \
+- break; \
+- case TOK_STRING: \
+- s = S; \
+- break; \
+- default: \
+- s = token_table[OP].string; \
+- break; \
+- } \
+- s; \
+-})
+-
+
+ struct token_entry {
+ char *string;
+--
+2.25.0
+
diff --git a/pkg/squashfs-tools/ver b/pkg/squashfs-tools/ver
@@ -1 +1 @@
-4.4 r0
+4.4 r1