• 0 Posts
  • 14 Comments
Joined 12 days ago
cake
Cake day: March 13th, 2025

help-circle







  • mina86@lemmy.wtftoLinux@lemmy.mlLinux Terminal: CTRL+D is like pressing ENTER
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    1
    ·
    edit-2
    2 days ago

    Which is why I haven’t wrote ‘EOF character’, ‘EOT’ or ‘EOT character’. Neither have I claimed that \x4 character is interpreted by the shell as end of file.

    Edit: Actually, I did say ‘EOF character’ originally (though I still haven’t claimed that it sends EOF character to the program). I’ve updated the comment to clear things up more.



  • Sure, though I advise against it. The following C program can do that:

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    int main(int argc, char **argv) {
    	if (argc < 2) {
    		fprintf(stderr, "usage: %s <command> <args>...", argv[0]);
    		return EXIT_FAILURE;
    	}
    
    	printf("Executing");
    	for (int i = 1; i < argc; ++i) {
    		printf(" %s", argv[i]);
    	}
    	puts("\nPress ^C to abort.");
    	sleep(5);
    
    	if (setuid(0)) {
    		perror("setuid");
    		return EXIT_FAILURE;
    	}
    
    	execvp(argv[1], argv + 1);
    	perror(argv[1]);
    	return EXIT_FAILURE;
    }
    

    As seen in:

    $ gcc -O2 -o delay-su delay-su.c
    $ sudo chown root:sudo delay-su
    $ sudo chmod 4750 delay-su
    $ ./delay-su id
    $ id -u
    1000
    $ ./delay-su id -u
    Executing id -u
    ^C to abort
    0
    

    This will allow anyone in group sudo to execute any command as root. You may change the group to something else to control who exactly can run the program (you cannot change the user of the program).

    If there’s some specific command you want to run, it’s better to hard-code it or configure sudo to allow execution of that command without password.


  • mina86@lemmy.wtftoLinux@lemmy.mlLinux Terminal: CTRL+D is like pressing ENTER
    link
    fedilink
    English
    arrow-up
    23
    arrow-down
    1
    ·
    edit-2
    2 days ago

    It’s not. You keep insisting that ^D doesn’t send EOF and yet:

    $ stty -a | grep eof
    intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>;
    $ man stty |grep -A1 eof |head -n2
           eof CHAR
                  CHAR will send an end of file (terminate the input)
    

    ^D (which is an ASCII EOT character) signals EOF. The thing is that in C every line of a text file must be terminated by a new-line. And so, when you end a file with ^D without a return, you get funky results.




  • mina86@lemmy.wtftoRust Programming@lemmy.mlWhich is faster?
    link
    fedilink
    English
    arrow-up
    1
    ·
    11 days ago

    This is too simplistic example to give any meaningful answer. What’s Type? What’s value? If it’s i32 and 42 than they both compile to the exact same thing. But if Type is Drop than the second will call the destructor on each iteration. (I’ve also written previously about similar example with BorrowedBuf1).