Only a buffer-overflow is this evil... (Solved)

Started by
10 comments, last by Toolmaker 19 years, 3 months ago
Quote:Original post by Nemesis2k2
Have you checked to see if fopen is actually succeding in opening the file?


Nice call.

I disected the 'f' and found it was broken up into several components. I did some comparisons with other programs I had written to determine if a specific value changed when it loaded sucessfully/differently. It wasn't apparanent.

Than I replace chrUserFile with "1.reg" and ran the program again, and it loaded the data correctly.

I'm not sure why that fixed it, but at least I have a basis to work with now.

Thanks!
rating++;

Edit: Found it! strcpy(*,*), two pointers, so saying strcpy(array, "1.reg") is invalid! I used sprintf(array,"%d.reg",1) and it fixed it.
Advertisement
Well, I suggest that you don't use plain password as you do now, and that you change your name/password strings to std::string, since these are less prone to errors.

So, for your password, I suggest you use MD5 hashes. I used the RSA Data Center C files for this, which you can get here:
http://www.toolmaker.nl/downloads/md5.zip

Add those files to your project, and then add this function somewhere in your "general purpose functions" files:
string MD5(const string& PlainText){    MD5_CTX       Context;    unsigned char Digest[16];    char          HashValue[33];    HashValue[32] = 0;    MD5Init(&Context);    MD5Update(&Context, (unsigned char *)PlainText.c_str(), (unsigned int)PlainText.length());    MD5Final((unsigned char *) Digest, &Context);    // Copy the digest into the string    int Pos = 0;    for (int i = 0; i < 16; ++i)    {        sprintf(&HashValue[Pos], "%02x", Digest);        Pos += 2;    }    return (HashValue);}


If you don't want to use std::string, it's easy to convert to char*.

Toolmaker

This topic is closed to new replies.

Advertisement