Re: core dump using Pro*C on CONNECT
Date: Sun, 27 Jul 2003 05:45:55 GMT
Message-ID: <3F2367AA.2030607_at_earthlink.net>
Frank Diedrich wrote:
> "thumor" <member34030_at_dbforums.com> schrieb im Newsbeitrag
> news:3148847.1059070191_at_dbforums.com...
>
>>Line of code in my Pro*C file: >> >><--BEGIN--> >> [Quoted] [Quoted] >> strcpy(Username, user_id); >> strcpy(Userpass, user_pw); >> strcpy(DBname, db_name);
Copy the string in user_id up to and including the terminal NUL '\0' into the variable Username. Repeat for the other two lines. No error checking on length; let's hope no-one was being malicious.
[Quoted] >> strcat(Username, '\0'); >> strcat(Userpass, '\0'); >> strcat(DBname, '\0');
Given the comment above, the attempt to append an extra NUL is pointless.
Worse, strcat() takes a char pointer (const char *, or pointer to constant character data) as the second argument. Writing '\0' for the null pointer is obscure, but valid. OTOH, it also leads to core dumps.
I recommend a visit to comp.lang.c or thereabouts.
>> >>EXEC SQL CONNECT :Username IDENTIFIED BY :Userpass AT DB_NAME >>USING :DBname; >> >> >> if (sqlca.sqlcode != 0) >> { >> sprintf(Log_Msg, "Error %d (%s) Connecting Database >> ",sqlca.sqlcode,sqlca.sqlerrm); >> Log_Message(Waste_Log, "pods_init", FATAL, Log_Msg); >> } >> else >> { >> sprintf(Log_Msg, "Connection to Database Successful"); >> Log_Message(Waste_Log, "pods_init", INFORM, Log_Msg); >> }; >><--- End --> >> >>I am running on HP-UX 10.2, ORACLE = 8.0.5 >> >>I get core dumped on me after the CONNECT statement.
After? Are you sure? How d'y'know?
I'd expect it to be beforehand, as indicated...
>>What seems to be the problem? >>Please help. >> >>-- >>Posted via http://dbforums.com
>
>
> Hello,
>
> i had the same problems in coding with C. Try to use char in C and then
> use the variable type declaration to declare the variable as string.
> With this method, you don't need to get the length of the char-array all
> the time (like with VARCHAR). See documentation for correct use.
>
> Greetings,
>
> Frank
>
>
>
>
-- Jonathan Leffler #include <disclaimer.h> Email: jleffler_at_earthlink.net, jleffler_at_us.ibm.com Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/Received on Sun Jul 27 2003 - 07:45:55 CEST