Ticket #24500: 0001-Make-errno-error-log-more-useful-for-getrandom.patch

File 0001-Make-errno-error-log-more-useful-for-getrandom.patch, 1.9 KB (added by ffmancera, 2 years ago)
  • new file changes/ticket24500

    From 09492be5ee50774db433622af3e163390b4e827a Mon Sep 17 00:00:00 2001
    From: Fernando Fernandez Mancera <ffernandezmancera@gmail.com>
    Date: Tue, 5 Dec 2017 00:17:09 +0100
    Subject: [PATCH] Make errno error log more useful for getrandom()
    
    Making errno error log more useful for getrandom() call. Adding if statement to
    make difference between ENOSYS and other errors.
    
    Fixes #24500
    
    Signed-off-by: Fernando Fernandez Mancera <ffernandezmancera@gmail.com>
    ---
     changes/ticket24500 |  3 +++
     src/common/crypto.c | 13 +++++++++++--
     2 files changed, 14 insertions(+), 2 deletions(-)
     create mode 100644 changes/ticket24500
    
    diff --git a/changes/ticket24500 b/changes/ticket24500
    new file mode 100644
    index 000000000..0f1778d46
    - +  
     1  o Code simplification and refactoring:
     2    - Making more useful log messages for errno errors on getrandom() call.
     3      Closes ticket 24500.
  • src/common/crypto.c

    diff --git a/src/common/crypto.c b/src/common/crypto.c
    index 80137b0d8..7f034ee94 100644
    a b crypto_strongest_rand_syscall(uint8_t *out, size_t out_len) 
    28752875      tor_assert(errno != EAGAIN);
    28762876      tor_assert(errno != EINTR);
    28772877
    2878       /* Probably ENOSYS. */
    2879       log_warn(LD_CRYPTO, "Can't get entropy from getrandom().");
     2878      /* Useful log message for errno. */
     2879      if (errno == ENOSYS) {
     2880        log_warn(LD_CRYPTO, "This warning is caused by ENOSYS error."
     2881                 " You are running a version of Tor built to support"
     2882                 " getrandom(), but the kernel is too old and doesn't"
     2883                 " implement this function.");
     2884      } else {
     2885        log_warn(LD_CRYPTO, "Can't get entropy from getrandom(). %s error.",
     2886                 strerror(errno));
     2887      }
     2888
    28802889      getrandom_works = 0; /* Don't bother trying again. */
    28812890      return -1;
    28822891      /* LCOV_EXCL_STOP */