:: Re: [DNG] Nasty Linux systemd secur…
Pàgina inicial
Delete this message
Reply to this message
Autor: Steve Litt
Data:  
A: dng
Assumpte: Re: [DNG] Nasty Linux systemd security bug revealed
Josef Grosch via Dng said on Tue, 27 Jul 2021 07:31:12 -0700


>7) Pay attention to the scope of variables and functions.


LOL. When I was a lot younger and stupider, my C code enabling 40 data
entry people to input data crashed once or twice a day, costing about
1/2 hour of work for each (20 hours of work gone per crash). My
co-worker and I finally found the problem, which follows:

======================================================
#include <stdio.h>
#include <string.h>

char * double_string(const char * string_in)
{
    char buffer[2000];  /* way big enough */
    strcpy(buffer, string_in);
    strcpy(buffer + strlen(string_in), string_in);
    return buffer;
}


int main(int argc, char * argv[])
{
    char * newstring = double_string("the quick, sly fox");
    do_lots_of_other_stuff();
    printf("%s\n", newstring); // Why wrong output?
    return 0;
}
======================================================


I never did THAT again!

SteveT

Steve Litt
Spring 2021 featured book: Troubleshooting Techniques of the Successful
Technologist http://www.troubleshooters.com/techniques