• 3 Posts
  • 215 Comments
Joined 1 year ago
cake
Cake day: September 22nd, 2025

help-circle




  • eleijeep@piefed.socialtoLinux@lemmy.ml•BSOD
    link
    fedilink
    English
    arrow-up
    4
    arrow-down
    1
    ·
    15 days ago

    Oh I see. If the URL puts the sensitive information after the anchor, like https://example.com/bsod#sensitive-info-goes-here then the browser would never send that part to the server. Everything after the anchor is just used locally by the browser to scroll the page to a specific place (or in this case for the javascript to read and process).

    You’d need to check every time you scan a QR code though that the # is in the URL and it’s not malformed. Trivially replacing the # with a ? would turn the private URL into one that sends all the data in the GET request. It’s training users to do something risky.

    Oh and it also assumes that the javascript hasn’t been tampered with to upload the data somewhere.

    I don’t like it.









  • inline is a hint to the compiler and doesn’t guarantee that your function will be inlined, even when it’s declared as such in the same compilation unit.

    You can read the GCC docs about the inline keyword: https://gcc.gnu.org/onlinedocs/gcc/Inline.html

    However it is possible to inline functions across compilation units. This is called Link-Time Optimization (LTO) and you can enable this in GCC using -flto. You must pass this flag at both compile and link time. Using LTO, you don’t need to even declare the function as inline or define it in the same compilation unit. The compiler and linker can choose the optimization based on the function size and whatever optimization heuristics they use.

    I tested this with a toy example:

    spoiler
    $ cat main.cpp 
    #include <iostream>  
    #include "lib.hpp"  
    
    int main(int argc, char* argv[])  
    {  
        set_int(13);  
        int x = get_int();  
        std::cout << x << std::endl;  
        return 0;  
    }  
    $ cat lib.hpp 
    #ifndef __LIBHPP  
    #define __LIBHPP  
    
    void set_int(int x);  
    int get_int();  
    
    #endif  
    $ cat lib.cpp 
    #include "lib.hpp"  
    
    static int val = 0;  
    
    void set_int(int x)  
    {  
        val = x;  
    }  
    
    int get_int()  
    {  
        return val;  
    }  
    $ cat Makefile 
    
    CPPFILES=main.cpp lib.cpp  
    OBJFILES=${CPPFILES:.cpp=.a}  
    
    CFLAGS=-O3 -flto  
    LDFLAGS=-O1 -flto  
    
    all: main  
    
    .PHONY: clean  
    clean:  
    	rm -f main ${OBJFILES}  
    
    main: ${OBJFILES}  
    	g++ ${LDFLAGS} -o $@ $^  
    
    %.a: %.cpp  
    	g++ ${CFLAGS} -o $@ -c $<  
    
    $ make clean && make  
    rm -f main main.a lib.a  
    g++ -O3 -flto -o main.a -c main.cpp  
    g++ -O3 -flto -o lib.a -c lib.cpp  
    g++ -O1 -flto -o main main.a lib.a  
    $ objdump -S main | grep -A 11 "<main>:"  
    0000000000000770 <main>:  
     770:	48 8d 3d a9 08 20 00 	lea    0x2008a9(%rip),%rdi        # 201020 <_ZSt4cout@@GLIBCXX_3.4>  
     777:	48 83 ec 08          	sub    $0x8,%rsp  
     77b:	be 0d 00 00 00       	mov    $0xd,%esi  
     780:	c7 05 aa 09 20 00 0d 	movl   $0xd,0x2009aa(%rip)        # 201134 <_ZL3val>  
     787:	00 00 00 
     78a:	e8 91 ff ff ff       	callq  720 <_ZNSolsEi@plt>  
     78f:	48 89 c7             	mov    %rax,%rdi  
     792:	e8 59 ff ff ff       	callq  6f0 <_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@plt>  
     797:	31 c0                	xor    %eax,%eax  
     799:	48 83 c4 08          	add    $0x8,%rsp  
     79d:	c3                   	retq  
    

    The disassembly shows that there are no calls to set_int or get_int in main.

    Compare this to the disassembly without optimization:

    spoiler
    $ make clean && make  
    rm -f main main.a lib.a  
    g++  -o main.a -c main.cpp  
    g++  -o lib.a -c lib.cpp  
    g++  -o main main.a lib.a  
    $ objdump -S main | grep -A 21 "<main>:"  
    000000000000088a <main>:  
     88a:	55                   	push   %rbp  
     88b:	48 89 e5             	mov    %rsp,%rbp  
     88e:	48 83 ec 20          	sub    $0x20,%rsp  
     892:	89 7d ec             	mov    %edi,-0x14(%rbp)  
     895:	48 89 75 e0          	mov    %rsi,-0x20(%rbp)  
     899:	bf 0d 00 00 00       	mov    $0xd,%edi  
     89e:	e8 93 00 00 00       	callq  936 <_Z7set_inti>  
     8a3:	e8 a1 00 00 00       	callq  949 <_Z7get_intv>  
     8a8:	89 45 fc             	mov    %eax,-0x4(%rbp)  
     8ab:	8b 45 fc             	mov    -0x4(%rbp),%eax  
     8ae:	89 c6                	mov    %eax,%esi  
     8b0:	48 8d 3d 69 07 20 00 	lea    0x200769(%rip),%rdi        # 201020 <_ZSt4cout@@GLIBCXX_3.4>  
     8b7:	e8 a4 fe ff ff       	callq  760 <_ZNSolsEi@plt>  
     8bc:	48 89 c2             	mov    %rax,%rdx  
     8bf:	48 8b 05 0a 07 20 00 	mov    0x20070a(%rip),%rax        # 200fd0 <_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_@GLIBCXX_3.4>  
     8c6:	48 89 c6             	mov    %rax,%rsi  
     8c9:	48 89 d7             	mov    %rdx,%rdi  
     8cc:	e8 6f fe ff ff       	callq  740 <_ZNSolsEPFRSoS_E@plt>  
     8d1:	b8 00 00 00 00       	mov    $0x0,%eax  
     8d6:	c9                   	leaveq 
     8d7:	c3                   	retq   
    




  • Some solutions:

    set -e  
    TEMPDIR=$(mktemp -d)  
    # script exits if mktemp returns error  
    

    or

    TEMPDIR=$(mktemp -d || echo "/invalid")  
    # TEMPDIR gets the value "/invalid" if mktemp fails  
    

    or

    TEMPDIR=$(mktemp -d)  
    TEMPDIR=${TEMPDIR:-"/invalid"}  
    # TEMPDIR gets the value "/invalid" if mktemp returns an empty value  
    

    or

    TEMPDIR=$(mktemp -d)  
    rm -rf ${TEMPDIR:-"/invalid"}  
    # rm is passed "/invalid" if TEMPDIR is empty  
    

    My personal preference is the last one. Any time you call rm -rf you provide a default value to variables to ensure that if they are empty they get some other value instead.




  • Really interesting work, but I’m extremely sceptical that image attestation is a good idea. Think of the privacy implications of having a unique private key tied to your device and emitted in every photo that you take. On top of that are all of the anti-consumer practises that are already enabled by hardware attestation methods that prevent us from running our own software etc.

    This is a very double-edged technology.

    It also suffers the usual problem of these kinds of systems in that it only works for people who are already honest and not producing fake images. The people who really want to make fakes will find a way around the system either by exploiting their hardware somehow, or just by taking a photograph of the fake image with a secured camera.

    The trade-off of privacy and device ownership for an illusion of trust doesn’t seem to be worth it, in my opinion.