devttys0 / sasquatch

510 stars 158 forks source link

‘if’ clause does not guard... [-Werror=misleading-indentation] #48

Open xlibun opened 2 years ago

xlibun commented 2 years ago

Error:

Hunk #1 succeeded at 32 with fuzz 1.
cc -g -O2  -I. -I./LZMA/lzma465/C -I./LZMA/lzmalt -I./LZMA/lzmadaptive/C/7zip/Compress/LZMA_Lib -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -DCOMP_DEFAULT=\"gzip\" -Wall -Werror  -DGZIP_SUPPORT -DLZMA_SUPPORT -DXZ_SUPPORT -DLZO_SUPPORT -DXATTR_SUPPORT -DXATTR_DEFAULT   -c -o unsquashfs.o unsquashfs.c
unsquashfs.c: In function ‘read_super’:
unsquashfs.c:1835:5: error: this ‘if’ clause does not guard... [-Werror=misleading-indentation]
 1835 |     if(swap)
      |     ^~
unsquashfs.c:1841:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
 1841 |         read_fs_bytes(fd, SQUASHFS_START, sizeof(struct squashfs_super_block),
      |         ^~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [<builtin>: unsquashfs.o] Error 1

code from 1835 to 1845:

if(swap)
        ERROR("Reading a different endian SQUASHFS filesystem on %s\n", source);

    /*
     * Try to read a Squashfs 4 superblock
     */
    read_fs_bytes(fd, SQUASHFS_START, sizeof(struct squashfs_super_block),
        &sBlk_4);
    // CJH: swap detection already done generically above
    //swap = sBlk_4.s_magic != SQUASHFS_MAGIC;
    SQUASHFS_INSWAP_SUPER_BLOCK(&sBlk_4);
h4b4n3r0 commented 2 years ago

I have the identical issue on Kali Linux.

minhng99 commented 2 years ago

there are mix of space and tab indentation in that part of the code, just change it all to 4 spaces

ghost commented 2 years ago

same issue

Fenr1r-g commented 2 years ago

"there are mix of space and tab indentation in that part of the code, just change it all to 4 spaces"

This is not true, and does nothing to actually fix the problem. The 'if' clause referenced on line 1835 is missing the { and } that includes the ERROR statement that comes afterward. Just adding them, however, doesn't fix the problem, as "unsquashfs.c" looks like it was indented by a psychopath, with random breaks in weird places that don't belong all over the place.

example on where the next error occurs if you fix the if statement (unsquashfs.c:1128:49: error: implicit declaration of function 'makedev' [-Werror=implicit-function-declaration]):

            if(mknod(pathname, chrdev ? S_IFCHR : S_IFBLK,
                    makedev((i->data >> 8) & 0xff,
                    i->data & 0xff)) == -1) {
                ERROR("create_inode: failed to create "
                    "%s device %s, because %s\n",
                    chrdev ? "character" : "block",
                    pathname, strerror(errno));
                break;
            }

Here's what that SHOULD look like (apologies for the wordwrap):

            if(mknod(pathname, chrdev ? S_IFCHR : S_IFBLK, makedev((i->data >> 8) & 0xff, i->data & 0xff)) == -1) 
            {
                ERROR("create_inode: failed to create %s device %s, because %s\n", chrdev ? "character" : "block", pathname, strerror(errno));
                break;
            }

Now, I don't deal with a lot of C code with what I do, mostly python, so someone tell me if I'm completely off base here. But onesy-twosy fixes aren't going to work here.

I also tried importing the lastest ver of squashfs (4.4) - no dice.

Fenr1r-g commented 2 years ago

The latest pull request fixes these issues: https://github.com/devttys0/sasquatch/pull/47

diablo0822 commented 2 years ago

The latest pull request fixes these issues: #47

this patch can solve this issue, but the build.sh scripts wrote a wrong path which cause the patch not work.

$ diff bd.sh build.sh
35c35
< patch -p0 < patches/patch0.txt
---
> patch -p0 < ../patches/patch0.txt
AxisRay commented 2 years ago
patching file squashfs-tools/unsquashfs.c
Hunk #1 succeeded at 32 with fuzz 1.
cc -g -O2  -I. -I./LZMA/lzma465/C -I./LZMA/lzmalt -I./LZMA/lzmadaptive/C/7zip/Compress/LZMA_Lib -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -DCOMP_DEFAULT=\"gzip\" -Wall -Werror  -DGZIP_SUPPORT -DLZMA_SUPPORT -DXZ_SUPPORT -DLZO_SUPPORT -DXATTR_SUPPORT -DXATTR_DEFAULT   -c -o unsquashfs.o unsquashfs.c
unsquashfs.c: In function ‘read_super’:
unsquashfs.c:1835:5: error: this ‘if’ clause does not guard... [-Werror=misleading-indentation]
 1835 |     if(swap)
      |     ^~
unsquashfs.c:1841:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
 1841 |         read_fs_bytes(fd, SQUASHFS_START, sizeof(struct squashfs_super_block),
      |         ^~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [<builtin>: unsquashfs.o] Error 1
slsanna commented 2 years ago

build

So, how to fix? I am dealing with this error since days, tried all solutions on internet and none of them worked. image

minhng99 commented 2 years ago

build

So, how to fix? I am dealing with this error since days, tried all solutions on internet and none of them worked. image

it's caused by inconsistent indentation (tab/space mixed), find it around that line caused error and make it consistent

prospero-x commented 2 years ago

compiling from commit 82da12 of master from this forked repo solved the issue with me on Kali Release version 2022.3.

torabi12 commented 2 years ago

I have the same error on Ubuntu 22.04.1 kép

Can you give me any hint what to do?

J0hnzon commented 2 years ago

image

frankviana commented 2 years ago

Solve:

git clone --quiet --depth 1 --branch "master" https://github.com/devttys0/sasquatch

cd sasquatch

wget https://github.com/devttys0/sasquatch/pull/47.patch && patch -p1 < 47.patch && sudo ./build.sh

iAmG-r00t commented 2 years ago

Despite fixing this error, there is an issue when extracting lzma compressed data from a firmware binary. Where most of the files are empty.

jacopotediosi commented 1 year ago

Solve:

git clone --quiet --depth 1 --branch "master" https://github.com/devttys0/sasquatch
cd sasquatch
wget https://github.com/devttys0/sasquatch/pull/47.patch && patch -p1 < 47.patch && sudo ./build.sh

Doing this, as noted also by @iAmG-r00t, causes some files to be lost while extracting some squashfs images (e.g., see https://github.com/ReFirmLabs/binwalk/issues/618), don't know why.

On Ubuntu 22.04.1LTS I suggest to compile using https://github.com/devttys0/sasquatch/pull/51 instead:

cd /tmp
git clone --quiet --depth 1 --branch "master" https://github.com/devttys0/sasquatch
cd sasquatch
wget https://github.com/devttys0/sasquatch/pull/51.patch && patch -p1 <51.patch
sudo ./build.sh
B1ank-H commented 1 year ago

compiling from commit 82da12 of master from this forked repo solved the issue with me on Kali Release version 2022.3.

Excellent! Only your method can solve this issue correctly.

peterpt commented 1 year ago

I have tried all solutions here and i still have issues compiling unsquashfs , the original git here even after the patch been revised still gives compiling issues and breaks , all others i get a lot of warnings but compile , however i believe this is not a perfect compilation and somethings may break or not work when using this tool , i used pastebin to post all the compilation , and i came here because i was trying to compile binwalk from source and i got stuck in this tool , so i decided to compile this tool manually . https://pastebin.com/p8Cnyxhx

XueningXu commented 4 months ago

On Ubuntu 22.04.1LTS I suggest to compile using #51 instead:

cd /tmp
git clone --quiet --depth 1 --branch "master" https://github.com/devttys0/sasquatch
cd sasquatch
wget https://github.com/devttys0/sasquatch/pull/51.patch && patch -p1 <51.patch
sudo ./build.sh

Thanks for your solution! It worked for me on WSL2 (Ubuntu 22.04).