Author Topic: C code errors  (Read 460 times)

0 Members and 2 Guests are viewing this topic.

Kiuhnm

  • Guest
C code errors
« on: October 17, 2014, 05:16:43 pm »
I'm watching
http://www.youtube.com/watch?feature=player_detailpage&v=lbjS2mXyMEQ#t=2148

Consider the following code:

Code: [Select]
#include <string.h>
#include <stdlib.h>

int main(void) {
  char s1[] = "012345678";
  char dest;
 
  dest = *(char *)malloc(strlen(s1));
}

The author of the video says that the code is vulnerable and an attacker can exploit it.
I don't see how, honestly. I think the author is wrong.
Do you agree?

Offline s3my0n

  • Knight
  • **
  • Posts: 276
  • Cookies: 58
    • View Profile
    • ::1
Re: C code errors
« Reply #1 on: October 17, 2014, 05:45:33 pm »
Not vulnerable since there is no user input.
Easter egg in all *nix systems: E(){ E|E& };E

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: C code errors
« Reply #2 on: October 18, 2014, 10:38:03 am »
I don't think you can exploit it in this state. But the code has some serious mistakes, and if it is used productively, it could lead to vulnerable code.
  • malloc(strlen(s1)) --> forgot to allocate space for the string terminator
  • return statement is missing (violates the standard)
  • char dest seems to have the wrong type
« Last Edit: October 18, 2014, 10:38:55 am by Deque »

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
Re: C code errors
« Reply #3 on: October 18, 2014, 05:32:30 pm »
I don't think you can exploit it in this state. But the code has some serious mistakes, and if it is used productively, it could lead to vulnerable code.
  • malloc(strlen(s1)) --> forgot to allocate space for the string terminator
  • return statement is missing (violates the standard)
  • char dest seems to have the wrong type

Ssssh!! Deque is giving C/C++ advice. Cellotape your damn mouth faggot. This only happens once in 40 centuries. The ancestors will flog you for this.
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]