From: Michael L. <mi...@lu...> - 2009-02-11 17:28:38
|
On Wed, Feb 11, 2009 at 8:14 AM, Earnie Boyd <ea...@us...>wrote: > > Quoting Michael Luich <mi...@lu...>: > > > I'm having a problem that I think is due to space in pathnames, > > So I compile a lib which uses Openssl, > > My app gives the lib a file path like C:\Users\OEM User\AppData\Roaming\ > > and the lib promptly crash's taking the app with it. > > Quoting the string doesn't help, makes it worse. > > Is there a good way to handle spaces in pathnames? > > > > any suggestions? > > > > Can you give a sample of the code that includes the path? > How did you quote the name? > > Earnie > > > ------------------------------------------------------------------------------ > Create and Deploy Rich Internet Apps outside the browser with > Adobe(R)AIR(TM) > software. With Adobe AIR, Ajax developers can use existing skills and code > to > build responsive, highly engaging applications that combine the power of > local > resources and data with the reach of the web. Download the Adobe AIR SDK > and > Ajax docs to start building applications today- > http://p.sf.net/sfu/adobe-com > _______________________________________________ > MinGW-users mailing list > Min...@li... > > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users > > _______________________________________________ > This list observes the Etiquette found at > http://www.mingw.org/Mailing_Lists. > We ask that you be polite and do the same. > > Most annoying abuses are: > 1) Top posting > 2) HTML/MIME encoded mail > 3) Improper quoting > 4) Improper trimming > Now that I test it it of course is failing to fail in my test program. I'm writing a plugin for pidgin that's doing encryption. The path is generated out of the location of the pidgin configuration dir. Below is the relevant code snippets: get_cert_path takes the name of the cert ex: mi...@lu... and wether it's a public or private cert. This translates into something like: c:\Users\mluich\AppData\.purple\ mi...@lu... my library uses this path to download the cert from a central server, and store it on the File system. This is reopens the file and hands it off to openssl as a file handle I tried changing sprintf (cert_path, "%s%s%s", user_dir, cert_dir, cert_name); to sprintf (cert_path, "\"%s%s%s\"", user_dir, cert_dir, cert_name); and that just caused the crash everytime. I have a vista machine on which this code works, but when used on a vist machine where the path is c:\Users\Oem User\AppData\.purple\mi...@lu...causes the plugin to crash. Admittedly the obvious thing is the space in the pathname. I just put together some test code for GetShortPathName, and can't get it to fail! sigh ...... the problem system is not mine and as such I have limited testing / debug but from the results i'm seeing on my vista system I may need to do much more debuging. Mike Luich **** in plugin: ***** #ifdef WIN32 #define PUB_DIR "\\srenc\\pub\\" #define PRIV_DIR "\\srenc\\priv\\" #define ICON_DIR "\\srenc\\icon\\" #else #define PUB_DIR "/srenc/pub/" #define PRIV_DIR "/srenc/priv/" #define ICON_DIR "/srenc/icon/" #endif static void sending_im_msg_cb (PurpleAccount * account, char *recipient, char **buffer, void *data) { FILE *fp; char *cert_path; char *html_enc_msg, *ptr; const char *user_dir = purple_user_dir (); char acct_name[128]; sprintf (acct_name, "%s", purple_account_get_protocol_id (account)); purple_debug_info (PLUGIN_ID_SHORT, "ENTER: %s in %s, line %d. %s with %s\n", __FUNCTION__, __FILE__, __LINE__, recipient, acct_name); char *normalized_name = normalize_name (recipient, acct_name); cert_path = get_cert_path (normalized_name, PRIVATE); if (0 == strcasecmp ("prpl-jabber", acct_name) | 0 == strcasecmp ("prpl-yahoo", acct_name) | 0 == strcasecmp ("prpl-aim", acct_name) | 0 == strcasecmp ("prpl-msn", acct_name)) { purple_debug_info (PLUGIN_ID_SHORT, "We support %s\n", acct_name); sprintf (cert_path, "%s%s%s", user_dir, PUB_DIR, normalized_name); purple_debug_misc (PLUGIN_ID_SHORT, "sending-im-msg (%s, %s, %s)\n", purple_account_get_username (account), normalized_name, *buffer); /* since were sending encrypt if they have a cert */ //open the recipient cert if (NULL == (fp = fopen (cert_path, "r"))) { purple_debug_error (PLUGIN_ID_SHORT, " unable to open %s \n", cert_path); } else { purple_debug_info (PLUGIN_ID_SHORT, "opened %s\n", cert_path); char enc_msg[20480]; sprintf (enc_msg, "%s", sr_encrypt (*buffer, fp)); purple_debug_info (PLUGIN_ID_SHORT, "encrypted: %s\n", enc_msg); html_enc_msg = calloc (1, strlen (enc_msg) + 99); html_enc_msg = purple_strdup_withhtml (enc_msg); *buffer = html_enc_msg; } purple_debug_info (PLUGIN_ID_SHORT, "EXIT: %s in %s, line %d.\n", __FUNCTION__, __FILE__, __LINE__); } } /*! \brief get_cert_path * Get the full path to the cert. * * - @varname cert_name name of cert ex:us...@do...d * - @varname CertType PUBLIC or PRIVATE * */ char * get_cert_path (char *cert_name, CertType cert_type) { purple_debug_info (PLUGIN_ID_SHORT, "ENTER: %s in %s, line %d.\n", __FUNCTION__, __FILE__, __LINE__); const char *user_dir = purple_user_dir (); char *cert_dir; char *cert_path; if (cert_type == PUBLIC) { cert_dir = PUB_DIR; } else { cert_dir = PRIV_DIR; } cert_path = calloc (1, strlen (user_dir) + strlen (cert_dir) + strlen (cert_name) + 4); sprintf (cert_path, "%s%s%s", user_dir, cert_dir, cert_name); purple_debug_info (PLUGIN_ID_SHORT, "Returning: %s %s in %s, line %d.\n", cert_path, __FUNCTION__, __FILE__, __LINE__); return cert_path; } ***** in library: ***** /*! \brief sr_encrypt * encrypt the given string with the given cert * return the encrypted data as char * * * - @clear_msg char * to buffer holding the string * - @pub_cert FILE * to the public cert * */ char *sr_encrypt(char *clear_msg, FILE *pub_cert) { if (SRDEBUG > 0){ fprintf (stderr, "ENTER: %s in %s, line %d.\n", __FUNCTION__, __FILE__, __LINE__); } const EVP_CIPHER *cipher= EVP_des_ede3_cbc(); STACK_OF(X509) *certs= sk_X509_new_null(); X509 *tmp; BIO *in, *out; PKCS7 *pkcs7; char *enc_msg, *enc_buffer; int bio_size; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); RAND_load_file("/dev/urandom", 1024); if (SRDEBUG > 0){ fprintf (stderr, "START: %s in %s, line %d.\n", __FUNCTION__, __FILE__, __LINE__); } in = BIO_new_mem_buf(clear_msg, -1); out = BIO_new(BIO_s_mem()); if (!(tmp = PEM_read_X509(pub_cert, NULL, NULL, NULL))) { fprintf (stderr, "Error Opening Public Key"); } sk_X509_push(certs,tmp); fclose (pub_cert); if (!(pkcs7 = PKCS7_encrypt(certs, in, cipher, PKCS7_BINARY))) { fprintf (stderr,"Error making PKC#7object : %s in %s, line %d.\n", __FUNCTION__, __FILE__, __LINE__); } if (SMIME_write_PKCS7(out, pkcs7, in, 0) !=1) { fprintf (stderr,"Error writing SMIME : %s in %s, line %d.\n", __FUNCTION__, __FILE__, __LINE__); } if (SRDEBUG > 0){ fprintf (stderr,"Encrypt on success : %s in %s, line %d.\n", __FUNCTION__, __FILE__, __LINE__); } bio_size=BIO_ctrl_pending(out); if (SRDEBUG > 0){ fprintf (stderr,"size of bio: %s in %s, line %d.\n %d\n", __FUNCTION__, __FILE__, __LINE__, bio_size); } enc_msg=calloc(1, bio_size + 1); enc_buffer=calloc(1, bio_size + 1); BIO_set_mem_eof_return(out,0); while ( !BIO_eof(out)) { BIO_gets(out,enc_buffer, bio_size); sprintf(enc_msg,"%s%s",enc_msg ,enc_buffer); } free(enc_buffer); if (SRDEBUG > 0){ fprintf (stderr,"Data out of bio: %s in %s, line %d.\n %s\n", __FUNCTION__, __FILE__, __LINE__, enc_msg); } return enc_msg; } |