linux - How can I compile C programs that use deprecated functions, such as gets() -



linux - How can I compile C programs that use deprecated functions, such as gets() -

for homework assignment, have seek utilize buffer overflows crash simple c program. problem compiler won't compile gets() function because deprecated , unsafe. understand this, sake of example, i'd override that. here code:

#include <stdio.h> int main(int argc, char *argv[]) { int valid = 0; // char arrays w/buffer set 8 chars char str1[8]; char str2[8]; next_tag(str1); //this want utilize gets , not fgets or other secure functions... gets(str2); if(strncmp(str1, str2, 8) == 0) { valid = 1; } // print printf("buffer 1: str1(%s), str2(%s), valid(%d)\n", str1, str2, valid); }

my gcc version is:

rabbitfighter@echo:[~/code/c/bufferoverflowexamples]: gcc -v using built-in specs. collect_gcc=gcc collect_lto_wrapper=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.1/lto-wrapper target: x86_64-unknown-linux-gnu configured with: /build/gcc/src/gcc-4.9-20140903/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-cloog-backend=isl --disable-isl-version-check --disable-cloog-version-check --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --disable-multilib --disable-werror --enable-checking=release thread model: posix gcc version 4.9.1 20140903 (prerelease) (gcc)

if can help me appreciate it. running manjaro linux (arch).

you can utilize "safer" funcion fgets , give bogus buffer size unsafe behavior out of it.

a larger buffer size real buffer allow fgets overrun bounds , potentially crash program.

just because gun has safety doesn't mean can't shoot foot off it.

c linux gcc

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -