Je suis sur le chapitre concernant les chaînes de caractères du cours sur le C.
J'essaye de tester les différentes fonctions de la bibliothèque string.h, mais seulement de nombreuses erreurs du type
C4996 : "Erreur C4996 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details."
m'empêche d'utiliser les fonctions comme strcpy ou strcat. J'ai utilisé les variantes strcpy_s et strcat_s (comme je le fait habituellement avec le scanf_s) mais ça ne marche toujours pas.
En effet, je ne connais pas les sanitizers pour visual studio mais je t'invite fortement à en activer car ton premier code fait un buffer overflow totalement gratuit.
D'une manière générale il est vrai que l'on utilise assez peu les fonctions strcpy et strcat à moins que l'on sait à l'avance combien d'espace ça va prendre.
Voilà ton premier code avec un sanitizer activé lors de l'exécution (-fsanitize=address,undefined)
=================================================================
==8267==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffeeccac986 at pc 0x000102fa6984 bp 0x7ffeeccac950 sp 0x7ffeeccac0f0
WRITE of size 6 at 0x7ffeeccac986 thread T0
#0 0x102fa6983 in wrap_strcat+0x423 (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x43983)
#1 0x102f56ca0 in main+0x140 (a.out:x86_64+0x100003ca0)
#2 0x7fff20348620 in start+0x0 (libdyld.dylib:x86_64+0x15620)
Address 0x7ffeeccac986 is located in stack of thread T0 at offset 38 in frame
#0 0x102f56b6f in main+0xf (a.out:x86_64+0x100003b6f)
This frame has 2 object(s):
[32, 38) 'salut' <== Memory access at offset 38 overflows this variable
[64, 70) 'prenom'
HINT: this may be a false positive if your program uses some custom stack unwind mechanism, swapcontext or vfork
(longjmp and C++ exceptions *are* supported)
SUMMARY: AddressSanitizer: stack-buffer-overflow (libclang_rt.asan_osx_dynamic.dylib:x86_64h+0x43983) in wrap_strcat+0x423
Shadow bytes around the buggy address:
0x1fffdd9958e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1fffdd9958f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1fffdd995900: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1fffdd995910: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1fffdd995920: 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1
=>0x1fffdd995930:[06]f2 f2 f2 06 f3 f3 f3 00 00 00 00 00 00 00 00
0x1fffdd995940: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1fffdd995950: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1fffdd995960: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1fffdd995970: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x1fffdd995980: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==8267==ABORTING
zsh: abort ./a.out
- Edité par markand 28 janvier 2021 à 9:15:09
git is great because Linus did it, mercurial is better because he didn't.
Problème avec la bibliothèque string.h
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Recueil de code C et C++ http://fvirtman.free.fr/recueil/index.html
git is great because Linus did it, mercurial is better because he didn't.