Improve the example getpass() implementation to show an error return
authorNick Mathewson <nickm@torproject.org>
Thu, 24 May 2018 19:23:15 +0000 (15:23 -0400)
committerRichard Levitte <levitte@openssl.org>
Sat, 26 May 2018 06:36:42 +0000 (08:36 +0200)
Also, modernize the code, so that it isn't trying to store a size_t
into an int, and then check the int's sign. :/

Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/6271)

doc/man3/PEM_read_bio_PrivateKey.pod

index 4fb4d1159aec9163b98052e8e63de4958edfff20..744a46f81ed9362d992b1bbd60c6c5c4d9132b87 100644 (file)
@@ -346,17 +346,16 @@ Skeleton pass phrase callback:
 
  int pass_cb(char *buf, int size, int rwflag, void *u)
  {
 
  int pass_cb(char *buf, int size, int rwflag, void *u)
  {
-     int len;
-     char *tmp;
 
      /* We'd probably do something else if 'rwflag' is 1 */
      printf("Enter pass phrase for \"%s\"\n", (char *)u);
 
      /* get pass phrase, length 'len' into 'tmp' */
 
      /* We'd probably do something else if 'rwflag' is 1 */
      printf("Enter pass phrase for \"%s\"\n", (char *)u);
 
      /* get pass phrase, length 'len' into 'tmp' */
-     tmp = "hello";
-     len = strlen(tmp);
-     if (len <= 0)
-         return 0;
+     char *tmp = "hello";
+     if (tmp == NULL) /* An error occurred */
+         return -1;
+
+     size_t len = strlen(tmp);
 
      if (len > size)
          len = size;
 
      if (len > size)
          len = size;