unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Kevin Ryde <user42@zip.com.au>
Subject: crypt mutex
Date: Sat, 21 Feb 2004 10:32:53 +1000	[thread overview]
Message-ID: <87znbdi85m.fsf@zip.com.au> (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

             reply	other threads:[~2004-02-21  0:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-21  0:32 Kevin Ryde [this message]
2004-02-21  3:24 ` crypt mutex 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87znbdi85m.fsf@zip.com.au \
    --to=user42@zip.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).