Be Careful When Using scanf() in C

  Рет қаралды 127,007

NeuralNine

NeuralNine

2 жыл бұрын

Today we learn why using the scanf() function in C might cause some serious problems and how to do it properly.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: www.neuralnine.com/books/
💻 The Algorithm Bible Book: www.neuralnine.com/books/
👕 Programming Merch: www.neuralnine.com/shop
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine.com/
📷 Instagram: / neuralnine
🐦 Twitter: / neuralnine
🤵 LinkedIn: / neuralnine
📁 GitHub: github.com/NeuralNine
🎙 Discord: / discord
🎵 Outro Music From: www.bensound.com/

Пікірлер: 226
@HandledToaster2
@HandledToaster2 2 жыл бұрын
Be careful when using C.
@synthesoul
@synthesoul 2 жыл бұрын
With great power comes great responsibility
@erick_ac
@erick_ac 2 жыл бұрын
"don't do this"
@waiitwhaat
@waiitwhaat 2 жыл бұрын
C stands for Careful
@HoSza1
@HoSza1 2 жыл бұрын
@@synthesoul Tony Stark writes in C. Spiderman uses Rust.
@santitabnavascues8673
@santitabnavascues8673 2 жыл бұрын
C is Gods programming language, of course humans can't make any good use of it
@raredavid98
@raredavid98 2 жыл бұрын
I was like “oh he’s gonna use another scan function” and then you whipped out the %12s and it was magnificent
@23trekkie
@23trekkie 2 жыл бұрын
Writing a letter when program expects a number: Pascal: throws an error and ends Python: throws an error and ends Perl: throws an error and ends Golang: assigns 0 to the variable C: loops itself to infinity, forcing you to use task manager to shut the program down before it sets your computer on fire.
@jelsonrodrigues
@jelsonrodrigues 2 жыл бұрын
Yeah, but you can always get the return of scanf and test it, if it's a 0, clean the stdin and try again
@benhetland576
@benhetland576 2 жыл бұрын
@@jelsonrodrigues I would even argue that you SHOULD check the return value. If you blindly trust an integer variable that should have got assigned a value by scanf, but wasn't, then maybe garbage was left in the variable...
@edwardmacnab354
@edwardmacnab354 2 жыл бұрын
c forces you to actually think about what exactly you are doing because you have so much more control
@dhanushchakravarthi7543
@dhanushchakravarthi7543 2 жыл бұрын
Ctrl+C stops any activity in any terminal
@jd9119
@jd9119 Жыл бұрын
If you're a better programmer, you'd design the program to be able to handle a char when it's expecting a number.
@castles990
@castles990 2 жыл бұрын
Thank you for covering this topic. Many tutorials for beginners use scanf() or gets(). Which obviously can be really dangerous.
@anibal.07
@anibal.07 2 жыл бұрын
What should be used then
@Darkworldwolf
@Darkworldwolf 2 жыл бұрын
@@anibal.07 it´s not that it shouldn´t be used but the issue should be adressed
@Darkworldwolf
@Darkworldwolf 2 жыл бұрын
@minhhoanglazy it´s so dangerious that you can basically fill all your inputs with wrong information, which either makes the whole program not work at best and at worst, makes it for a hacker super easy to make it do whatever he wants
@azi3lplays696
@azi3lplays696 2 жыл бұрын
@@anibal.07 Use scanf but use it in the right way. For example: scanf("%12s", string) or scanf("%12[^ ]", string).
@baileyharrison1030
@baileyharrison1030 2 жыл бұрын
@@anibal.07 fgets(buf, sizeof(buf), stdin)
@FlyingButterHorse
@FlyingButterHorse 2 жыл бұрын
Just a reminder. As I recall, in standard C99, compilers do not allocate the extra byte for the null termination on char-arrays (strings). So char my_string[20] can be up to 19 characters long, since the last one must be a null, to indicate the end. My understanding is that this is meant to be for use-cases when you are storing small integers in an array, and want to save space. This way, it won't be adding bytes to arrays unpredictably, everything is always the size you tell it to be. I'm sure everyone here already is well aware of this, just in case some people forgot.
@benhetland576
@benhetland576 2 жыл бұрын
If you declare the array with a length, like _char s[5] = "abcdefg";_ then that will be the number of bytes allocated. If you initialize that with a string, then only that number of characters will be copied from the string even if it is longer than the buffer. In the previous example that would be "abcde" without a terminating '\0'. If the initializer string is shorter that the declared array, then _all_ remaining elements are filled with 0 (0-padded), so for example using "ab" instead in the above would initialize the array to "ab\0\0\0". If you instead declare the array without specifying a length, then the length is calculated automatically to match the initializer string including a \0 terminator, so e.g. _char p[] = "abc";_ would make the buffer 4 bytes long ("abc\0").
@lennymclennington
@lennymclennington 2 жыл бұрын
@@benhetland576 the first part of your comment "even if it is longer than the buffer" is incorrect. The C standard states: No initializer shall attempt to provide a value for an object not contained within the entity being initialized. So which part of the C standard are you getting that information from?
@44r0n-9
@44r0n-9 2 жыл бұрын
Yes, of course for a declaration like this there is no extra byte and it will be exactly the size you entered. The compiler doesn't know what you want to do with the array obviously. Could be anything.
@benhetland576
@benhetland576 2 жыл бұрын
@@lennymclennington Yes, you are right! I stand corrected, and the truncation rule only applies to the NUL terminator. My experience with that behavior goes way back to even pre-standard C, but such is -- at best -- merely an implementation-specific feature today.
@lennymclennington
@lennymclennington 2 жыл бұрын
@@benhetland576 what part of the standard adds an exception for a NUL terminator with respect to an initializer being unable to provide a value that is not contained within the object that it initializes? Or are you saying that a the behaviour you were describing only works with a NUL terminator and that in itself is an implementation detail? Sorry if I'm misinterpreting your comment.
@yonatanbeyn8557
@yonatanbeyn8557 2 жыл бұрын
Again back to C. We need more C tutorial in this great channel.
@h8handles
@h8handles 2 жыл бұрын
Explains buffer overflow without saying buffer overflow great vid
@unlxck3255
@unlxck3255 2 жыл бұрын
3:57
@potaziio7174
@potaziio7174 2 жыл бұрын
3:57
@pbenikovszky1
@pbenikovszky1 2 жыл бұрын
08:00
@MrMatheus195
@MrMatheus195 2 жыл бұрын
8:00
@matthewargyros59
@matthewargyros59 2 жыл бұрын
It's been almost 3 months since uni started and our teacher is giving us approximately 15 exercises a week and many of the stuff needed for these exercises to be "bug free" are not included in his lectures... Videos like this are a life saver cause now I can do my about 3/10 exercises assigned this week without worrying about them having this exact issue (which I did face and wanted to find a way to overcome...), Also, even though it's a 12min video the information presented is well structured enough that it feels as way less time has elapsed and I really appreciate that.
@matthewargyros59
@matthewargyros59 2 жыл бұрын
@@freedomgoddess Naip, this is email is a mistake but it's far too inconvenient to change it now :P
@jd9119
@jd9119 Жыл бұрын
I'll give you some advice when you get a lot of exercises to code in the university. Get yourself a case of cold beer and free up your nights. Your best ideas happen after the 10th beer. If you want to be good at programming, it needs to not just be what you're studying, but also your hobby. These exercises should be fun. And I'll tell you this much, as helpful as some of these videos are, you're cheating yourself of the experience of solving them yourself.
@nootsen5522
@nootsen5522 2 жыл бұрын
Thank you very much! Im a beginner in c and my teacher told us to use the scanf() function to read in some user input. I asked him how to failcheck/make sure the user puts in the right things on scanf, but he told me you just dont. Right after that we talked about buffer overflows in another class lol. Nicely explained even for ones without great knowledge
@tacokoneko
@tacokoneko 2 жыл бұрын
for some reason some university professors are just bad and teach wrong. In my experience this correlates heavily with Ph.D/Full Professor = good, Master/Bachelor/Undergrad/Assist. Prof./T.A. Lecturer = bad. When signing up for lecture periods always check the academic credentials of the lecturer, and ratemyprofessor for reference. I don't think anyone gets a Ph.D in STEM without knowing shit.
@nootsen5522
@nootsen5522 2 жыл бұрын
@@tacokoneko it's not even in Uni, it's just regular school 😅
@edwardmacnab354
@edwardmacnab354 2 жыл бұрын
@@tacokoneko a lot of full professors get contemptuous--research first ,students ? Just a pain in the ass
@neri9749
@neri9749 2 жыл бұрын
My C programming teacher (CS Engineering school) didn't know about dynamic memory allocation, we ended up teaching him how to use the linux man
@jeromesimms
@jeromesimms 2 жыл бұрын
This was really good! I would love to see more C and program security videos.
@rawdawg7995
@rawdawg7995 3 ай бұрын
dude thank you! i really like how you explained this! -i've watched 6 videos and didn't get it until yours lol thank you again !
@natalie.p6997
@natalie.p6997 2 жыл бұрын
I'm new to C/C++ and I feel lucky that I got to know this early on. Thank you so much for the heads up!
@FrancoNSosa
@FrancoNSosa Жыл бұрын
This video is great, because most of the times when we start learning C, we're just taught that a way to take user imput is by using scanf. If you're lucky enough or do your research, you'll probably discover that there are also other functions for that. And even though nowadays there's so much info on the internet, we're not taught so much about programming safely. So we keep learning, our programs become bigger and bigger, and eventually we find that our program crashes and we don't know why. And the bigger our project is, the harder it is to find every error. And this is just considering we do C projects for ourselves. Imagine if this happens in a company project or stuff. Not only you'd have a potential error, you'd have fatal security issues in your system, that someone with enough knowledge could exploit. And this doesn't only apply to C. C just doesn't provide any safety measures natively, but it can happen in other languages too! So in summary, it's always a good programming practice to introduce safety checks in your code, and if you're working in a company, this becomes a must.
@benhetland576
@benhetland576 2 жыл бұрын
Order and sanity got totally fucked up when he named the executable _main.o_ as if it were an object file... (Linux wouldn't care, but a make system will.)
@Nick-lx4fo
@Nick-lx4fo 2 жыл бұрын
That triggered me too
@KaleshwarVhKaleshwarVh
@KaleshwarVhKaleshwarVh 2 жыл бұрын
Can you please elaborate ?
@Protofall
@Protofall 2 жыл бұрын
@@KaleshwarVhKaleshwarVh He named the executable "main.o", but ".o" files are supposed to be "object" files, not binaries. Its like making a docx file, but changing the extension to "txt", sure you can use it if you open it correctly, but most people will see it and assume its a txt file.
@jekserimek
@jekserimek 2 жыл бұрын
Yes, extremely useful. But I also recommend fgets(). It can also get strings with spaces, and it also avoids the scanf problem. A thing to remember, though, is that this function also eats the line-changing character. So I usually get rid of the last character and replace it with '\0'(null character)
@FP-yg1rx
@FP-yg1rx Жыл бұрын
Thank you very much, i was seching for a easy to use way to fix this.
@hashhacker2130
@hashhacker2130 2 жыл бұрын
That's some quality information!
@ionizingradiation7970
@ionizingradiation7970 Жыл бұрын
Very informative. Appreciated!
@Mr.Equinox
@Mr.Equinox 2 жыл бұрын
Your explanation was really fantastic
@stepan_chous
@stepan_chous 2 жыл бұрын
in case some of you are interested, I have C project with function that allows you to initialise a variable of any integer type safely, which means that you can’t write letters or any other symbols as input and it tracks type overflow. I can send it to you if you want. it also contains beautiful algorithm of defining min and max value of any integer type using bits operations that i could not find on the internet
@donhunt3649
@donhunt3649 2 жыл бұрын
Sounds really useful, may I have it ?
@Meow-ie5zu
@Meow-ie5zu 2 жыл бұрын
im very interested. could you send it to me if thats no problem, thanks ^^
@pl0xy
@pl0xy 2 жыл бұрын
if you ever upload it to the internet, would you be so kind to share it? :]
@MrValsung
@MrValsung 2 жыл бұрын
same here, very interested
@nac9880
@nac9880 2 жыл бұрын
POV: He doesn't have it
@mikicerise6250
@mikicerise6250 2 жыл бұрын
It's 20. When declaring array you have to explicitly include the null byte. :) The string literal will be automatically null-terminated for you though.
@Protofall
@Protofall 2 жыл бұрын
That should be a %11s, because scanf will take the input and add a \0 at the end of it. So, with your code, if I enter "123456789012" then it will save 13 characters and potentially override part of our password string.
@edwardmacnab354
@edwardmacnab354 2 жыл бұрын
test your code
@abhijitmondal7831
@abhijitmondal7831 2 жыл бұрын
Make theses type of videos 🔥 i really enjoy this 🔥
@TheBrainReal
@TheBrainReal 2 жыл бұрын
Wow did not know about this, thanks!
@joaquingutierrez3072
@joaquingutierrez3072 2 жыл бұрын
Very interesting video. Thank you
@mamedsev5678
@mamedsev5678 2 жыл бұрын
Great contents. Subbed.
@MOHAMEDMOIDEENMOHAMED-fs5ou
@MOHAMEDMOIDEENMOHAMED-fs5ou 5 ай бұрын
Very interesting.I tested the code. Success.
@__blank__4193
@__blank__4193 2 жыл бұрын
Very nice explanation i readed the entire stackoverflow post about this topic and i didn't understood a thing but thanks to you the entire scanf vulnerability is clear to me now Btw why didn't you used scanf_s ?
@enderagent
@enderagent 2 жыл бұрын
this was a great tutorial
@dhananjaysharma4946
@dhananjaysharma4946 2 жыл бұрын
Grate video 💡
@D0Samp
@D0Samp 2 жыл бұрын
scanf is a family of library functions that aged poorly and should probably be used as little as possible in favor of (reading and) parsing a string yourself. Not only do you run into issues like Rockstar accidentally building a quadric-time parser because sscanf builds a string stream first which (depending on the C library) always counts its length, but it's also unreliable without checking the return value.
@alberdemir8877
@alberdemir8877 11 ай бұрын
This video is quite nice for me I'm interested in programming and I appreciate C language but appearantly writing C is easy but writing it correct is quite hard and writing C correct is not a popular video topic on youtube thx for the video!
@user-hj2ed5pe6j
@user-hj2ed5pe6j 2 жыл бұрын
If myinput has length of 12(including null character) so in scanf it must be %11s otherwise if input is more than 11 characters the next storagespace/variable will be empty(thus mypassword is empty string)
@LoganDark4357
@LoganDark4357 2 жыл бұрын
Actually, scanf does not write a null, so the input array would just have no null terminator. It would then read mypassword as part of the same string, you wouldn't be able to pass the check, but it's still incorrect
@benhetland576
@benhetland576 2 жыл бұрын
@@LoganDark4357 Actually %s or %11s does store a null into the receiving buffer, but %c or %11c behaves as you say. The %s variants would also stop at the first whitespace if it occurs before the length limit, so a space in the password wouldn't work correctly in this example.
@LoganDark4357
@LoganDark4357 2 жыл бұрын
@@benhetland576 If you watch the video, when he overflows the first buffer, scanf does not insert a null into the middle of the second buffer.
@benhetland576
@benhetland576 2 жыл бұрын
@@LoganDark4357 I have rewatched the video, but I could not find any case showing evidence that scanf did not add a \0 after it had filled its input into the buffer(s). Please provide a timestamp for where you saw it!
@LoganDark4357
@LoganDark4357 2 жыл бұрын
@@benhetland576 Looks like I was referring to 3:25, but upon closer inspection he didn't actually overflow it little enough for part of the original "helloguys" to show through. So I performed my own testing, and it actually seems you were correct. 0 logandark ~ cat kek.c #include int main() { char first[20]; char second[20] = "hellothisisathing"; scanf("%s", first); printf("%s ", first); printf("%s ", second); } 0 logandark ~ gcc kek.c -o kek 0 logandark ~ ./kek hello hello hellothisisathing 0 logandark ~ ./kek hellothshshdsjfjgasdkjfha hellothshshdsjfjgasdkjfha hellothisisathing 0 logandark ~ ./kek sdfjhdslfjkdhsfdlksjhfdsljkfhdkljfhdslkfjds sdfjhdslfjkdhsfdlksjhfdsljkfhdkljfhdslkfjds jfhdslkfjds
@neural_nonsense
@neural_nonsense 2 жыл бұрын
it is great thing to know. tnx
@LoganDark4357
@LoganDark4357 2 жыл бұрын
12s is incorrect! You need 11s to make room for the null terminator!
@williamdrum9899
@williamdrum9899 2 жыл бұрын
Basically if he didn't have stack smashing detection a hacker can pretty much turn that scanf() into a goto that ignores scope. If this was an 8 bit or 16 bit cpu (which didn't have protected memory) he could execute basically any code he wanted to on the machine
@user-ik5bn6ps2p
@user-ik5bn6ps2p 2 жыл бұрын
By the way, you can also use "%ms" as format string for scanf(). In this case, scanf() will allocate a buffer that is large enough to hold the entire input string, including the \0. In turn, you are obliged to free() this buffer when you finish your business with it.
@sushilkatikia1384
@sushilkatikia1384 2 жыл бұрын
If you are telling us to use free(), does it mean by using *%ms* we are dynamically allocating memory to the buffer ?
@user-ik5bn6ps2p
@user-ik5bn6ps2p 2 жыл бұрын
@@sushilkatikia1384 Indeed. We are allocating memory in the heap, not the stack. So it won't be freed automatically.
@justcurious1940
@justcurious1940 9 ай бұрын
This is interesting, but according to chatGPT it's not part of the C standard.
@KXBeats
@KXBeats 2 жыл бұрын
In c++ there is scanf_s for a safe output using an extra size Parameter. I don't know about c, but in c++, it's that.
@ClashWithHuzefa
@ClashWithHuzefa 2 жыл бұрын
good one... also can use fgets() function to be on safer aise
@thomasqsa
@thomasqsa 2 жыл бұрын
That's why you should use getline. In fact the gcc documentation recommends never using a compiler that doesn't support that function
@MarkNiemann
@MarkNiemann 2 жыл бұрын
As someone in a class going over c this is quite interesting
@igormauricio271
@igormauricio271 2 жыл бұрын
Very cool!
@b1ack_c0de
@b1ack_c0de 2 жыл бұрын
thanks a billion!
@amd9918
@amd9918 2 жыл бұрын
use scanf_s and strcmp_s to have more control with buffers xD so it doesn't go buffer overflow. strcmp_s is kinda nice. if somehow the buffer doesn't get null-terminated for some odd reason. that might be a bug in the future xD.. so it doesn't compare the whole bytes until it hits 0 somewhere else in the memory. or you can crash because you end up going into pages that have no permission to read xD
@FireSecret
@FireSecret 2 жыл бұрын
What it's the proper way to get user console input? It seems to do super strange things when you try to pass a string type variable to an int type variable (infinite loops, printing some random stuff, or even crashing).
@jelsonrodrigues
@jelsonrodrigues 2 жыл бұрын
For string input is better to just use fgets or getline functions
@vitorfontolan8517
@vitorfontolan8517 2 жыл бұрын
Coe Joelson, poderia explicar melhor ? To aprendendo C e nunca ouvi falar desses comandos kkk e nem sei se eles estão inclusos nas bibliotecas que uso tbm
@jelsonrodrigues
@jelsonrodrigues 2 жыл бұрын
​@@vitorfontolan8517 Ambas as funções são inclusas com o header stdio.h, tem a documentação certinha de cada uma na internet, ou se vc tiver utilizando linux pode utilizar o comando man no terminal para saber mais sobre cada uma. Elas são específicas para pegar strings. Você consegue delimitar o número de caracteres que serão pegos com a fgets e a getline. Com a getline se você não sabe o número de caracteres que serão lidos de antemão, ela vai alocando memória dinamicamente e para de ler quando o usuário digitar o só tem que se lembrar de usar o free depois.
@ZeroCool2211
@ZeroCool2211 2 жыл бұрын
@@vitorfontolan8517 fgets("%s",CharArray,stdin);
@kloachristoph6253
@kloachristoph6253 2 жыл бұрын
at 10:49 you write a lot of A's to the string but scanf only scans the first 12 right so your string is full with A's but isn't there a problem with the last byte that should be \x00?
@benjins
@benjins 2 жыл бұрын
Yes, the %12s indicates that it will read 12 characters from the input, but write 13 to the buffer (the 12 from the input, plus a null terminator). It fixes the specific issue seen here, but is still incorrect and can cause other buffer overflows An upcoming version of Clang has -Wfortify-source, which will warn on this code: warning: 'scanf' may overflow; destination buffer in argument 2 has size 12, but the corresponding specifier may require size 13 Alternatively, Address Sanitizer will catch this sort of thing
@jasimchouhan4784
@jasimchouhan4784 2 жыл бұрын
Wow, its amazing
@Fun_dzz
@Fun_dzz Жыл бұрын
The best 👽💜
@krunkle5136
@krunkle5136 Жыл бұрын
See C can be dangerous in uncareful hands, but also it's been around long enough that all the gotchas are well known.
@vulbyte
@vulbyte 8 ай бұрын
i love the "i prefer linux for c" massively juxtaposed by it being wsl
@nguyenkien5558
@nguyenkien5558 2 жыл бұрын
Good tutorial man! Question: how did you setup Ubuntu Vim like this in Windows?
@derpythecate6842
@derpythecate6842 2 жыл бұрын
My guess is Windows Subsystem (WSL 2.0) to run command line linux. From there the steps are all the same as terminal linux, you go to ~/.config/nvim/init.vim for neovim or ~/.vimrc for vim and edit the file. He has some additional themes on his terminal too. Eyeballing it, it seems like he is using zsh with powerlevel10k for the fancy looking terminal. Follow the steps exactly on Arch Linux's wiki, it is quite simple if you just do it step by stel.
@ahbarahad3203
@ahbarahad3203 2 жыл бұрын
WSL, install Vim on it
@IamPyu-v
@IamPyu-v 4 ай бұрын
Just use *n* functions like snscanf, snprintf, strncmp! Other functions like fgets are also safe from buffer overflows.
@aymancassim8944
@aymancassim8944 2 жыл бұрын
Heyy can you do like some C++ projects and other tips, pls :)
@NeuralNine
@NeuralNine 2 жыл бұрын
Any specific topic ideas?
@aymancassim8944
@aymancassim8944 2 жыл бұрын
@@NeuralNine Maybe one using OOP, that could be nice cause im still a beginner in C++
@radoslavl921
@radoslavl921 2 жыл бұрын
Actually the output, that you are getting, is not an object file. It's an elf executable. You shouldn't use the .o extention for it as this might confuse some people if they are trying to follow a tutorial. By default gcc outputs a file named "a.out" and it is an elf executable. You should keep using that or at least not use "main.o" as the file name as that can slow your development down as you need to select the proper file starting with "main." and doing that isn't fast as normally you can just use tab until you see that "a.out" is the file, that you will execute, but when using the name "main.o" you have to type the whole file name for it to work.
@towtruckn
@towtruckn Жыл бұрын
Thanks for the great video; I've had this problem using scanf() trying to get an integer ie. Any key eg. ESC will cause a Segmentation Fault. Can you recommend something for this. Thanks in advance.
@srin_meow
@srin_meow 2 жыл бұрын
what would've happened if the neighbouring array was also reading from stdin will buffer overflow still happen?
@ReptilianXHologram
@ReptilianXHologram 2 жыл бұрын
Alright so if I create a character array like I have posted below. How many bytes should I allocate so it is safe/secure? I'm assuming the name is already 5 bytes but I also have to include another byte for the null byte so that would be 6 bytes. So would that mean the character array and the scanf function should be both 6 bytes? char firstName[] = "Daniel";
@kevynphillipegusmao7562
@kevynphillipegusmao7562 2 жыл бұрын
Very interesting video! Just a question, is there any specific reason for not using the “&” in the scanf() function? I normally see for example scanf(“%s”, &myinput)
@impossible2hn614
@impossible2hn614 2 жыл бұрын
value of array variable is address already, so you don't need to use &.
@kevynphillipegusmao7562
@kevynphillipegusmao7562 2 жыл бұрын
@@impossible2hn614 oh that makes sense, thanks for the explanation!
@TheNemesis405
@TheNemesis405 2 жыл бұрын
Does this problem happen only when we use scanf() to input string type data?
@alien_X1
@alien_X1 2 жыл бұрын
We need tutorial for C programming
@raptors416
@raptors416 Жыл бұрын
would this matter if we are scanning a single character?
@pokepe12
@pokepe12 2 жыл бұрын
Yo what is the name of that text editor? It looks like vi but with colors to show what mode the user is on, does anyone know?
@erbenton07
@erbenton07 5 ай бұрын
I know this is a bit old but what editor is he using? nv? that's what he typed but i can't find an editor called nv. Maybe nv is an alias?
@jla0717
@jla0717 2 жыл бұрын
Alguna página donde pueda practicar o información detallada de programación en c
@biladaman4035
@biladaman4035 2 жыл бұрын
Hey amn did you make that theme yourself our you downloaded? If you make it yourself could you pass it i would love to make a vscide theme like that.
@nicolamombelli2149
@nicolamombelli2149 2 жыл бұрын
How is it called the
@serkan_bayram
@serkan_bayram 2 жыл бұрын
it doesn't give any stack smashing error and I can't write over also, I'm using dev c++ do you know why?
@Cons-Cat
@Cons-Cat 2 жыл бұрын
What compiler, operating system, and STL do you have?
@APPAROOTME
@APPAROOTME 2 жыл бұрын
hello Neureline how can we create a management stock in python
@diragon8841
@diragon8841 2 жыл бұрын
Are BufferOverflow or similiar user input vulnerabilities present in Java or Python?
@williamdrum9899
@williamdrum9899 2 жыл бұрын
No. At least they're not as easy to create. Java and Python have way more going on behind the scenes. C is basically just universal assembly, which is why it doesn't really protect you from things like this.
@danivalcamposnogueirajunio1202
@danivalcamposnogueirajunio1202 2 жыл бұрын
Why did you use python to print?
@HPMuwa
@HPMuwa 2 жыл бұрын
I thought you show us how set limit via size_t variable type.
@anuradhalakruwan1918
@anuradhalakruwan1918 2 жыл бұрын
Please create C programing language lessons tutorial..... 🌹🌹🌹🌹🌹💖💖💖💖💖
@alexanderchori8154
@alexanderchori8154 2 жыл бұрын
And what if the length isn’t known in compile time? Just use string concatenation to build the format string?
@ZeroCool2211
@ZeroCool2211 2 жыл бұрын
Use sizeof(CharrArray)
@atif1538
@atif1538 2 жыл бұрын
why does it overwrite the next array though?
@yeet159
@yeet159 2 жыл бұрын
Amazing
@night23412
@night23412 2 жыл бұрын
may I know which font you use for the terminal?
@NeuralNine
@NeuralNine 2 жыл бұрын
I think it is JetBrains Mono Nerd Font
@Brock-Landers
@Brock-Landers 2 жыл бұрын
Compiling the executable with a dot o extension... yah that's totally normal.
@heroes-of-balkan
@heroes-of-balkan 2 жыл бұрын
How we can set up scanf format to let users input strings with spaces too?
@justcurious1940
@justcurious1940 9 ай бұрын
scanf("%[^ ]") : I think this should work.
@krzysztofkwak3684
@krzysztofkwak3684 Ай бұрын
it doesn't really fix that much, for example program shouldn't take password123AAAAAAAA and print SUCCESS - which it does in this case. How do you deal with this?
@insert0name0here91
@insert0name0here91 2 ай бұрын
the safest alternative to scanf() is gets()
@Darklight171
@Darklight171 2 жыл бұрын
The '
@Darklight171
@Darklight171 2 жыл бұрын
switched to cmd, it didn't let me execute the python script, I used open() and wrote the A's and \x00 to the file, then fed the file as input, but it still gives me Fail! ....
@KiddKat
@KiddKat 2 жыл бұрын
But what would happen if the password is exactly 12 characters, let's say "password1234", and someone input it "password12345", and since "%12s" would make the program only read the first 12 characters, wouldn't that be a success?
@justcurious1940
@justcurious1940 9 ай бұрын
Yes it would be a success , but the our program won't be hacked but the problem is when u give a random input and overwrite the password buffer and still get a success.
@tt_thoma
@tt_thoma 2 жыл бұрын
Why such compression ???
@solelgammal
@solelgammal 2 жыл бұрын
what I learned: don’t code in c, code in C++
@ashleyjones193
@ashleyjones193 2 жыл бұрын
a=1 while (a
@aleksanderslepowronski7046
@aleksanderslepowronski7046 2 жыл бұрын
Error: Undefined reference to "main" Line 1. Undeclared variable "a" Line 1. Expected semicolon. Line 2. Invalid rvalue. Line 3. Expected "{". Line 3. Undefined reference to "print". Line 3. Expected semicolon. Line 4. Expected semicolon. Process returned 1 (0x01)
@williamdrum9899
@williamdrum9899 2 жыл бұрын
20 GOTO 10
@shadamethyst1258
@shadamethyst1258 2 жыл бұрын
I've been using fgets extensively
@alexlu7149
@alexlu7149 2 жыл бұрын
wooowwwww this is awesome
@user-zp7ey1sl5b
@user-zp7ey1sl5b 2 жыл бұрын
What editor are you using?
@kannanm3850
@kannanm3850 2 жыл бұрын
I guess, It's neovim
@ももい
@ももい 2 жыл бұрын
한국인 있음?? 그니까 %s로만 받고 프린트하면 스택오버플로우 되서 비밀번호 뱉으니까 %사이즈s하라는거??
@nicosilv3r
@nicosilv3r 2 жыл бұрын
4:25 19 bytes
@ayushyadav5164
@ayushyadav5164 2 жыл бұрын
Him not clearing the terminal is bothering me uh.......
@yato3335
@yato3335 2 жыл бұрын
Why not insert input like this, instead of python? echo "text" | ./main.o
@elonmaks3117
@elonmaks3117 2 жыл бұрын
It's not so easy to put NULL character in bash (which is necessary to do strcmp)
@yato3335
@yato3335 2 жыл бұрын
@@elonmaks3117 I think there's an option echo -e which allows for backslash characters.
@elonmaks3117
@elonmaks3117 2 жыл бұрын
sorry u were right, just tested and echo -e with \0 works well!
@inx1819
@inx1819 2 жыл бұрын
buffer overlows strike again
@NeuralNine
@NeuralNine 2 жыл бұрын
👀
@synthesoul
@synthesoul 2 жыл бұрын
This is why you should always practice clean coding. Especially with languages like C/C++ or low-level programming. Garbage collection is very important.
@justcurious1940
@justcurious1940 9 ай бұрын
2023 : Does not work anymore I think compilers have fixed this issue.
@dasten123
@dasten123 2 жыл бұрын
Wow... what an easy fix! Why the fuck do so many tutorials not include that
@matheusaugustodasilvasanto3171
@matheusaugustodasilvasanto3171 Жыл бұрын
I mean... it's in the name of the function... scanf, scan _formatted_. User input is the least formatted thing there is.🤨
@SulemanAsghargoion
@SulemanAsghargoion 2 жыл бұрын
There is scanf_s as well right?
@oreo6392
@oreo6392 2 жыл бұрын
If you are using MSVC, yes. But keep in mind that Microsoft's implementation of Annex K is non-standard and basically none of the other major implementations supports Annex K in any reliable form. That being said, unless you specifically need a lazy method to parse an input string, don't use scanf()/sscanf(). If all you want to do is read from stdin, just use fgets() or fread(). (I would link to sources here but google's webfilter is being a pain)
@AagLagaDenge
@AagLagaDenge Жыл бұрын
7:45
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
why do hackers love strings?
5:42
Low Level Learning
Рет қаралды 399 М.
Вечный ДВИГАТЕЛЬ!⚙️ #shorts
00:27
Гараж 54
Рет қаралды 14 МЛН
WHO LAUGHS LAST LAUGHS BEST 😎 #comedy
00:18
HaHaWhat
Рет қаралды 20 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 101 МЛН
1 or 2?🐄
00:12
Kan Andrey
Рет қаралды 55 МЛН
[c][explained] Problems with scanf
6:11
theteachr
Рет қаралды 64 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 138 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 287 М.
how can memory safe code STOP HACKERS?
7:43
Low Level Learning
Рет қаралды 112 М.
why do void* pointers even exist?
8:17
Low Level Learning
Рет қаралды 336 М.
Comparing C to machine language
10:02
Ben Eater
Рет қаралды 5 МЛН
Simulating the Evolution of Rock, Paper, Scissors
15:00
Primer
Рет қаралды 388 М.
fgets is unsafe! So what’s the alternative?
11:32
Code With Huw
Рет қаралды 2,7 М.
Stupid C Tricks: Unsafe Functions You MUST Avoid!
9:26
Dave's Garage
Рет қаралды 60 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 276 М.
Зачем ЭТО электрику? #секрет #прибор #энерголикбез
0:56
Александр Мальков
Рет қаралды 247 М.
Отдых для геймера? 😮‍💨 Hiper Engine B50
1:00
Simple maintenance. #leddisplay #ledscreen #ledwall #ledmodule #ledinstallation
0:19
LED Screen Factory-EagerLED
Рет қаралды 36 МЛН
Я УКРАЛ ТЕЛЕФОН В МИЛАНЕ
9:18
Игорь Линк
Рет қаралды 100 М.
😱Хакер взломал зашифрованный ноутбук.
0:54
Последний Оплот Безопасности
Рет қаралды 559 М.