Re: Linux programme - different results each run



Eric Enright <eric.enright@xxxxxxxxx> writes:

>> int isNum(char data)
>> {
>>
>> switch(data)
>> {
>> case '0': return 0;
>> case '1': return 0;
....
> There is a function called isdigit() in ctype.h that
> does just this, you should use it instead.

In addition, isSomething() should return non-zero when something
is true, and zero (false) otherwise.

As written, the code will require anyone with any "C" experience
to go through extra "this code works backwards" mental gymnastics.

>> char *path = (char *)malloc(50);
>
> What happens if malloc() fails? Plus, you shouldn't
> be casting malloc().
>
>> strcat(path,"/proc/");

One more bug: what happens if storage returned by malloc() did
not begin with a NUL byte?

I believe that bug is at the root of OPs irreproducible results.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
.



Relevant Pages

  • Re: ZLib double free bug: Windows NT potentially unaffected
    ... I've been researching this bug since I heard that ssh passes packets to zlib ... Double free vulnerabilities are primarily an issue for malloc implementations ... how exploitation of this error works entitled: ... Also as noted above some malloc libraries have explicit protection mechanisms ...
    (Bugtraq)
  • Re: ANN: ZPack File Format, spec and tools
    ... those "oddball crap" machines such as wireless routers and stuff. ... memory management. ... and behaves like a memory corruption bug. ... bizarre malloc behavior is nothing new in my experience... ...
    (comp.compression)
  • Re: C++ exception handling question [solved]
    ... That is, even if there is no memory left, it might tell the ... man malloc calls the default behavior ... of the kernel a really bad bug, ... happens, for example, with some memory allocation algorithms. ...
    (Debian-User)
  • Re: malloc options
    ... I did find a number of errors in my own code where I was not allocating enough space for some things. ... Even if you tweak enough options the new malloc() ... There's definitely a bug somewhere and you ultimately need it resolved. ... J Each byte of new memory allocated by malloc, realloc() ...
    (freebsd-questions)
  • Re: malloc options
    ... probably because your program contains bugs in how it manages memory that happened to be working by accident with the old memory allocator. ... e.g. because you were making use of memory after it had been freed, but before the allocator returned it to some other malloc() call. ... Your description looks like a use-after-free bug. ...
    (freebsd-questions)