unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* crypt mutex
@ 2004-02-21  0:32 Kevin Ryde
  2004-02-21  3:24 ` Mikael Djurfeldt
  0 siblings, 1 reply; 15+ messages in thread
From: Kevin Ryde @ 2004-02-21  0:32 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 281 bytes --]

While nosing around the crypt function, I wondered if it ought to have
a mutex, just in case two threads run it concurrently.

        * posix.c (crypt_mutex): New variable.
        (scm_init_posix): Initialize it.
        (scm_crypt): Use it to protect static data from crypt().


[-- Attachment #2: posix.c.crypt-mutex.diff --]
[-- Type: text/plain, Size: 1210 bytes --]

--- posix.c.~1.124.~	2004-02-21 09:19:52.000000000 +1000
+++ posix.c	2004-02-21 10:30:54.000000000 +1000
@@ -1420,7 +1420,11 @@
 #undef FUNC_NAME
 #endif /* HAVE_SYNC */
 
+/* crypt() returns a pointer to a static buffer, so we use a mutex to avoid
+   another thread overwriting that buffer by another call.
+   OPTIMIZE-ME: Use glibc crypt_r() when available.  */
 #if HAVE_CRYPT
+static scm_t_mutex  crypt_mutex;
 SCM_DEFINE (scm_crypt, "crypt", 2, 0, 0, 
             (SCM key, SCM salt),
 	    "Encrypt @var{key} using @var{salt} as the salt value to the\n"
@@ -1428,12 +1432,16 @@
 #define FUNC_NAME s_scm_crypt
 {
   char * p;
+  SCM ret;
 
   SCM_VALIDATE_STRING (1, key);
   SCM_VALIDATE_STRING (2, salt);
 
+  scm_mutex_lock (&crypt_mutex);
   p = crypt (SCM_STRING_CHARS (key), SCM_STRING_CHARS (salt));
-  return scm_makfrom0str (p);
+  ret = scm_makfrom0str (p);
+  scm_mutex_unlock (&crypt_mutex);
+  return ret;
 }
 #undef FUNC_NAME
 #endif /* HAVE_CRYPT */
@@ -1826,6 +1834,10 @@
   scm_c_define ("LOCK_NB", SCM_MAKINUM (LOCK_NB));
 #endif
 
+#if HAVE_CRYPT
+  scm_mutex_init (&crypt_mutex, &scm_i_plugin_mutex);
+#endif
+
 #include "libguile/cpp_sig_symbols.c"
 #include "libguile/posix.x"
 }

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2004-07-23 23:53 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-21  0:32 crypt mutex Kevin Ryde
2004-02-21  3:24 ` Mikael Djurfeldt
2004-02-21  3:26   ` Mikael Djurfeldt
2004-02-23 19:15     ` Marius Vollmer
2004-02-21 21:50   ` Kevin Ryde
2004-02-23 19:16     ` Marius Vollmer
2004-02-23 19:12   ` Marius Vollmer
2004-02-23 19:46     ` Mikael Djurfeldt
2004-02-23 19:55       ` Mikael Djurfeldt
2004-02-24  1:11         ` Andreas Voegele
2004-02-24  1:22           ` Mikael Djurfeldt
2004-03-20 22:39         ` Marius Vollmer
2004-03-20 22:51           ` Kevin Ryde
2004-07-23 23:53             ` Kevin Ryde
2004-02-23 20:01     ` Mikael Djurfeldt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).