Richard W.M. Jones
2018-Jan-29 15:47 UTC
[Libguestfs] [PATCH] customize: Correctly handle crypt(3) returning NULL.
In particular glibc's crypt will return NULL / errno == ENOSYS and other implementations might do that in future too. --- customize/crypt-c.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/customize/crypt-c.c b/customize/crypt-c.c index d5425cfaa..e358018cd 100644 --- a/customize/crypt-c.c +++ b/customize/crypt-c.c @@ -21,6 +21,7 @@ #include <stdio.h> #include <stdlib.h> #include <unistd.h> +#include <errno.h> #if HAVE_CRYPT_H #include <crypt.h> @@ -29,6 +30,7 @@ #include <caml/alloc.h> #include <caml/memory.h> #include <caml/mlvalues.h> +#include <caml/unixsupport.h> #pragma GCC diagnostic ignored "-Wmissing-prototypes" @@ -44,6 +46,8 @@ virt_customize_crypt (value keyv, value saltv) * is not thread safe. */ r = crypt (String_val (keyv), String_val (saltv)); + if (r == NULL) + unix_error (errno, (char *) "crypt", Nothing); rv = caml_copy_string (r); CAMLreturn (rv); -- 2.13.2
Pino Toscano
2018-Jan-30 12:39 UTC
Re: [Libguestfs] [PATCH] customize: Correctly handle crypt(3) returning NULL.
On Monday, 29 January 2018 16:47:03 CET Richard W.M. Jones wrote:> In particular glibc's crypt will return NULL / errno == ENOSYS and > other implementations might do that in future too. > --- > customize/crypt-c.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/customize/crypt-c.c b/customize/crypt-c.c > index d5425cfaa..e358018cd 100644 > --- a/customize/crypt-c.c > +++ b/customize/crypt-c.c > @@ -21,6 +21,7 @@ > #include <stdio.h> > #include <stdlib.h> > #include <unistd.h> > +#include <errno.h> > > #if HAVE_CRYPT_H > #include <crypt.h> > @@ -29,6 +30,7 @@ > #include <caml/alloc.h> > #include <caml/memory.h> > #include <caml/mlvalues.h> > +#include <caml/unixsupport.h> > > #pragma GCC diagnostic ignored "-Wmissing-prototypes" > > @@ -44,6 +46,8 @@ virt_customize_crypt (value keyv, value saltv) > * is not thread safe. > */ > r = crypt (String_val (keyv), String_val (saltv)); > + if (r == NULL) > + unix_error (errno, (char *) "crypt", Nothing); > rv = caml_copy_string (r);LGTM. -- Pino Toscano
Reasonably Related Threads
- [PATCH] customize: Use libxcrypt if available to provide crypt(3).
- [Bug 2112] New: Android doesn't provide an implementation of crypt().
- [PATCH] customize: Move virt-customize-related code to a separate
- Bug reports - auth is broken in Dovecot 2.3.3
- openssh for UWIN