From: miod Date: Wed, 16 Apr 2014 19:54:20 +0000 (+0000) Subject: - Why do we hide from the OpenSSL police, dad? X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=87d6f0d13274fa48addcbbc820d2c105a8d240b2;p=openbsd - Why do we hide from the OpenSSL police, dad? - Because they're not like us, son. They use macros to wrap stdio routines, for an undocumented (OPENSSL_USE_APPLINK) use case, which only serves to obfuscate the code. ok tedu@ --- diff --git a/lib/libcrypto/bio/b_dump.c b/lib/libcrypto/bio/b_dump.c index 090cfc2b5f4..ff75069df86 100644 --- a/lib/libcrypto/bio/b_dump.c +++ b/lib/libcrypto/bio/b_dump.c @@ -62,7 +62,7 @@ #include #include "cryptlib.h" -#include "bio_lcl.h" +#include #define TRUNCATE #define DUMP_WIDTH 16 @@ -149,7 +149,7 @@ BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), static int write_fp(const void *data, size_t len, void *fp) { - return UP_fwrite(data, len, 1, fp); + return fwrite(data, len, 1, fp); } int diff --git a/lib/libcrypto/bio/bio.h b/lib/libcrypto/bio/bio.h index 9bae034daa9..b64fd44b122 100644 --- a/lib/libcrypto/bio/bio.h +++ b/lib/libcrypto/bio/bio.h @@ -197,11 +197,6 @@ extern "C" { #define BIO_FLAGS_IO_SPECIAL 0x04 #define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) #define BIO_FLAGS_SHOULD_RETRY 0x08 -#ifndef BIO_FLAGS_UPLINK -/* "UPLINK" flag denotes file descriptors provided by application. - It defaults to 0, as most platforms don't require UPLINK interface. */ -#define BIO_FLAGS_UPLINK 0 -#endif /* Used in BIO_gethostbyname() */ #define BIO_GHBN_CTRL_HITS 1 diff --git a/lib/libcrypto/bio/bio_lcl.h b/lib/libcrypto/bio/bio_lcl.h deleted file mode 100644 index cc89c1bf2dc..00000000000 --- a/lib/libcrypto/bio/bio_lcl.h +++ /dev/null @@ -1,27 +0,0 @@ -#include - -#if BIO_FLAGS_UPLINK==0 -/* Shortcut UPLINK calls on most platforms... */ -#define UP_stdin stdin -#define UP_stdout stdout -#define UP_stderr stderr -#define UP_fprintf fprintf -#define UP_fgets fgets -#define UP_fread fread -#define UP_fwrite fwrite -#undef UP_fsetmod -#define UP_feof feof -#define UP_fclose fclose - -#define UP_fopen fopen -#define UP_fseek fseek -#define UP_ftell ftell -#define UP_fflush fflush -#define UP_ferror ferror -#define UP_fileno fileno -#define UP_open open -#define UP_read read -#define UP_write write -#define UP_lseek lseek -#define UP_close close -#endif diff --git a/lib/libcrypto/bio/bss_fd.c b/lib/libcrypto/bio/bss_fd.c index c0e7f08fbb5..988104e77cb 100644 --- a/lib/libcrypto/bio/bss_fd.c +++ b/lib/libcrypto/bio/bss_fd.c @@ -67,19 +67,7 @@ * BIO_s_fd here... */ #else -/* - * As for unconditional usage of "UPLINK" interface in this module. - * Trouble is that unlike Unix file descriptors [which are indexes - * in kernel-side per-process table], corresponding descriptors on - * platforms which require "UPLINK" interface seem to be indexes - * in a user-land, non-global table. Well, in fact they are indexes - * in stdio _iob[], and recall that _iob[] was the very reason why - * "UPLINK" interface was introduced in first place. But one way on - * another. Neither libcrypto or libssl use this BIO meaning that - * file descriptors can only be provided by application. Therefore - * "UPLINK" calls are due... - */ -#include "bio_lcl.h" +#include static int fd_write(BIO *h, const char *buf, int num); static int fd_read(BIO *h, char *buf, int size); @@ -125,7 +113,7 @@ fd_new(BIO *bi) bi->init = 0; bi->num = -1; bi->ptr = NULL; - bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */ + bi->flags=0; return (1); } @@ -136,10 +124,10 @@ fd_free(BIO *a) return (0); if (a->shutdown) { if (a->init) { - UP_close(a->num); + close(a->num); } a->init = 0; - a->flags = BIO_FLAGS_UPLINK; + a->flags = 0; } return (1); } @@ -151,7 +139,7 @@ fd_read(BIO *b, char *out, int outl) if (out != NULL) { errno = 0; - ret = UP_read(b->num, out, outl); + ret = read(b->num, out, outl); BIO_clear_retry_flags(b); if (ret <= 0) { if (BIO_fd_should_retry(ret)) @@ -166,7 +154,7 @@ fd_write(BIO *b, const char *in, int inl) { int ret; errno = 0; - ret = UP_write(b->num, in, inl); + ret = write(b->num, in, inl); BIO_clear_retry_flags(b); if (ret <= 0) { if (BIO_fd_should_retry(ret)) @@ -185,11 +173,11 @@ fd_ctrl(BIO *b, int cmd, long num, void *ptr) case BIO_CTRL_RESET: num = 0; case BIO_C_FILE_SEEK: - ret = (long)UP_lseek(b->num, num, 0); + ret = (long)lseek(b->num, num, 0); break; case BIO_C_FILE_TELL: case BIO_CTRL_INFO: - ret = (long)UP_lseek(b->num, 0, 1); + ret = (long)lseek(b->num, 0, 1); break; case BIO_C_SET_FD: fd_free(b); diff --git a/lib/libcrypto/bio/bss_file.c b/lib/libcrypto/bio/bss_file.c index 59e48e66590..c92c4753aa7 100644 --- a/lib/libcrypto/bio/bss_file.c +++ b/lib/libcrypto/bio/bss_file.c @@ -86,7 +86,7 @@ #include #include #include "cryptlib.h" -#include "bio_lcl.h" +#include #include #if !defined(OPENSSL_NO_STDIO) @@ -134,7 +134,6 @@ BIO return (NULL); } - BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ BIO_set_fp(ret, file, BIO_CLOSE); return (ret); } @@ -147,7 +146,6 @@ BIO if ((ret = BIO_new(BIO_s_file())) == NULL) return (NULL); - BIO_set_flags(ret, BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */ BIO_set_fp(ret, stream, close_flag); return (ret); } @@ -164,7 +162,7 @@ file_new(BIO *bi) bi->init = 0; bi->num = 0; bi->ptr = NULL; - bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */ + bi->flags=0; return (1); } @@ -175,12 +173,9 @@ file_free(BIO *a) return (0); if (a->shutdown) { if ((a->init) && (a->ptr != NULL)) { - if (a->flags&BIO_FLAGS_UPLINK) - UP_fclose (a->ptr); - else - fclose (a->ptr); + fclose (a->ptr); a->ptr = NULL; - a->flags = BIO_FLAGS_UPLINK; + a->flags = 0; } a->init = 0; } @@ -193,12 +188,8 @@ file_read(BIO *b, char *out, int outl) int ret = 0; if (b->init && (out != NULL)) { - if (b->flags&BIO_FLAGS_UPLINK) - ret = UP_fread(out, 1,(int)outl, b->ptr); - else - ret = fread(out, 1,(int)outl,(FILE *)b->ptr); - if (ret == 0 && (b->flags & BIO_FLAGS_UPLINK) ? - UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr)) { + ret = fread(out, 1,(int)outl,(FILE *)b->ptr); + if (ret == 0 && ferror((FILE *)b->ptr)) { SYSerr(SYS_F_FREAD, errno); BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB); ret = -1; @@ -213,10 +204,7 @@ file_write(BIO *b, const char *in, int inl) int ret = 0; if (b->init && (in != NULL)) { - if (b->flags&BIO_FLAGS_UPLINK) - ret = UP_fwrite(in,(int)inl, 1, b->ptr); - else - ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr); + ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr); if (ret) ret = inl; /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ @@ -238,41 +226,20 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr) switch (cmd) { case BIO_C_FILE_SEEK: case BIO_CTRL_RESET: - if (b->flags&BIO_FLAGS_UPLINK) - ret = (long)UP_fseek(b->ptr, num, 0); - else - ret = (long)fseek(fp, num, 0); + ret = (long)fseek(fp, num, 0); break; case BIO_CTRL_EOF: - if (b->flags&BIO_FLAGS_UPLINK) - ret = (long)UP_feof(fp); - else - ret = (long)feof(fp); + ret = (long)feof(fp); break; case BIO_C_FILE_TELL: case BIO_CTRL_INFO: - if (b->flags&BIO_FLAGS_UPLINK) - ret = UP_ftell(b->ptr); - else - ret = ftell(fp); + ret = ftell(fp); break; case BIO_C_SET_FILE_PTR: file_free(b); b->shutdown = (int)num&BIO_CLOSE; b->ptr = ptr; b->init = 1; -#if BIO_FLAGS_UPLINK!=0 -#if defined(_IOB_ENTRIES) - /* Safety net to catch purely internal BIO_set_fp calls */ - if ((size_t)ptr >= (size_t)stdin && - (size_t)ptr < (size_t)(stdin + _IOB_ENTRIES)) - BIO_clear_flags(b, BIO_FLAGS_UPLINK); -#endif -#endif -#ifdef UP_fsetmod - if (b->flags&BIO_FLAGS_UPLINK) - UP_fsetmod(b->ptr,(char)((num&BIO_FP_TEXT)?'t':'b')); -#endif break; case BIO_C_SET_FILENAME: file_free(b); @@ -302,7 +269,6 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr) } b->ptr = fp; b->init = 1; - BIO_clear_flags(b, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ break; case BIO_C_GET_FILE_PTR: /* the ptr parameter is actually a FILE ** in this case. */ @@ -318,10 +284,7 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr) b->shutdown = (int)num; break; case BIO_CTRL_FLUSH: - if (b->flags&BIO_FLAGS_UPLINK) - UP_fflush(b->ptr); - else - fflush((FILE *)b->ptr); + fflush((FILE *)b->ptr); break; case BIO_CTRL_DUP: ret = 1; @@ -344,13 +307,8 @@ file_gets(BIO *bp, char *buf, int size) int ret = 0; buf[0] = '\0'; - if (bp->flags&BIO_FLAGS_UPLINK) { - if (!UP_fgets(buf, size, bp->ptr)) - goto err; - } else { - if (!fgets(buf, size,(FILE *)bp->ptr)) - goto err; - } + if (!fgets(buf, size,(FILE *)bp->ptr)) + goto err; if (buf[0] != '\0') ret = strlen(buf); err: diff --git a/lib/libcrypto/cryptlib.h b/lib/libcrypto/cryptlib.h index d1d7cfe80a8..b3342232c76 100644 --- a/lib/libcrypto/cryptlib.h +++ b/lib/libcrypto/cryptlib.h @@ -65,11 +65,6 @@ #include "e_os.h" -#ifdef OPENSSL_USE_APPLINK -#define BIO_FLAGS_UPLINK 0x8000 -#include "ms/uplink.h" -#endif - #include #include #include diff --git a/lib/libssl/src/crypto/bio/b_dump.c b/lib/libssl/src/crypto/bio/b_dump.c index 090cfc2b5f4..ff75069df86 100644 --- a/lib/libssl/src/crypto/bio/b_dump.c +++ b/lib/libssl/src/crypto/bio/b_dump.c @@ -62,7 +62,7 @@ #include #include "cryptlib.h" -#include "bio_lcl.h" +#include #define TRUNCATE #define DUMP_WIDTH 16 @@ -149,7 +149,7 @@ BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), static int write_fp(const void *data, size_t len, void *fp) { - return UP_fwrite(data, len, 1, fp); + return fwrite(data, len, 1, fp); } int diff --git a/lib/libssl/src/crypto/bio/bio.h b/lib/libssl/src/crypto/bio/bio.h index 9bae034daa9..b64fd44b122 100644 --- a/lib/libssl/src/crypto/bio/bio.h +++ b/lib/libssl/src/crypto/bio/bio.h @@ -197,11 +197,6 @@ extern "C" { #define BIO_FLAGS_IO_SPECIAL 0x04 #define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) #define BIO_FLAGS_SHOULD_RETRY 0x08 -#ifndef BIO_FLAGS_UPLINK -/* "UPLINK" flag denotes file descriptors provided by application. - It defaults to 0, as most platforms don't require UPLINK interface. */ -#define BIO_FLAGS_UPLINK 0 -#endif /* Used in BIO_gethostbyname() */ #define BIO_GHBN_CTRL_HITS 1 diff --git a/lib/libssl/src/crypto/bio/bio_lcl.h b/lib/libssl/src/crypto/bio/bio_lcl.h deleted file mode 100644 index cc89c1bf2dc..00000000000 --- a/lib/libssl/src/crypto/bio/bio_lcl.h +++ /dev/null @@ -1,27 +0,0 @@ -#include - -#if BIO_FLAGS_UPLINK==0 -/* Shortcut UPLINK calls on most platforms... */ -#define UP_stdin stdin -#define UP_stdout stdout -#define UP_stderr stderr -#define UP_fprintf fprintf -#define UP_fgets fgets -#define UP_fread fread -#define UP_fwrite fwrite -#undef UP_fsetmod -#define UP_feof feof -#define UP_fclose fclose - -#define UP_fopen fopen -#define UP_fseek fseek -#define UP_ftell ftell -#define UP_fflush fflush -#define UP_ferror ferror -#define UP_fileno fileno -#define UP_open open -#define UP_read read -#define UP_write write -#define UP_lseek lseek -#define UP_close close -#endif diff --git a/lib/libssl/src/crypto/bio/bss_fd.c b/lib/libssl/src/crypto/bio/bss_fd.c index c0e7f08fbb5..988104e77cb 100644 --- a/lib/libssl/src/crypto/bio/bss_fd.c +++ b/lib/libssl/src/crypto/bio/bss_fd.c @@ -67,19 +67,7 @@ * BIO_s_fd here... */ #else -/* - * As for unconditional usage of "UPLINK" interface in this module. - * Trouble is that unlike Unix file descriptors [which are indexes - * in kernel-side per-process table], corresponding descriptors on - * platforms which require "UPLINK" interface seem to be indexes - * in a user-land, non-global table. Well, in fact they are indexes - * in stdio _iob[], and recall that _iob[] was the very reason why - * "UPLINK" interface was introduced in first place. But one way on - * another. Neither libcrypto or libssl use this BIO meaning that - * file descriptors can only be provided by application. Therefore - * "UPLINK" calls are due... - */ -#include "bio_lcl.h" +#include static int fd_write(BIO *h, const char *buf, int num); static int fd_read(BIO *h, char *buf, int size); @@ -125,7 +113,7 @@ fd_new(BIO *bi) bi->init = 0; bi->num = -1; bi->ptr = NULL; - bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */ + bi->flags=0; return (1); } @@ -136,10 +124,10 @@ fd_free(BIO *a) return (0); if (a->shutdown) { if (a->init) { - UP_close(a->num); + close(a->num); } a->init = 0; - a->flags = BIO_FLAGS_UPLINK; + a->flags = 0; } return (1); } @@ -151,7 +139,7 @@ fd_read(BIO *b, char *out, int outl) if (out != NULL) { errno = 0; - ret = UP_read(b->num, out, outl); + ret = read(b->num, out, outl); BIO_clear_retry_flags(b); if (ret <= 0) { if (BIO_fd_should_retry(ret)) @@ -166,7 +154,7 @@ fd_write(BIO *b, const char *in, int inl) { int ret; errno = 0; - ret = UP_write(b->num, in, inl); + ret = write(b->num, in, inl); BIO_clear_retry_flags(b); if (ret <= 0) { if (BIO_fd_should_retry(ret)) @@ -185,11 +173,11 @@ fd_ctrl(BIO *b, int cmd, long num, void *ptr) case BIO_CTRL_RESET: num = 0; case BIO_C_FILE_SEEK: - ret = (long)UP_lseek(b->num, num, 0); + ret = (long)lseek(b->num, num, 0); break; case BIO_C_FILE_TELL: case BIO_CTRL_INFO: - ret = (long)UP_lseek(b->num, 0, 1); + ret = (long)lseek(b->num, 0, 1); break; case BIO_C_SET_FD: fd_free(b); diff --git a/lib/libssl/src/crypto/bio/bss_file.c b/lib/libssl/src/crypto/bio/bss_file.c index 59e48e66590..c92c4753aa7 100644 --- a/lib/libssl/src/crypto/bio/bss_file.c +++ b/lib/libssl/src/crypto/bio/bss_file.c @@ -86,7 +86,7 @@ #include #include #include "cryptlib.h" -#include "bio_lcl.h" +#include #include #if !defined(OPENSSL_NO_STDIO) @@ -134,7 +134,6 @@ BIO return (NULL); } - BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ BIO_set_fp(ret, file, BIO_CLOSE); return (ret); } @@ -147,7 +146,6 @@ BIO if ((ret = BIO_new(BIO_s_file())) == NULL) return (NULL); - BIO_set_flags(ret, BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */ BIO_set_fp(ret, stream, close_flag); return (ret); } @@ -164,7 +162,7 @@ file_new(BIO *bi) bi->init = 0; bi->num = 0; bi->ptr = NULL; - bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */ + bi->flags=0; return (1); } @@ -175,12 +173,9 @@ file_free(BIO *a) return (0); if (a->shutdown) { if ((a->init) && (a->ptr != NULL)) { - if (a->flags&BIO_FLAGS_UPLINK) - UP_fclose (a->ptr); - else - fclose (a->ptr); + fclose (a->ptr); a->ptr = NULL; - a->flags = BIO_FLAGS_UPLINK; + a->flags = 0; } a->init = 0; } @@ -193,12 +188,8 @@ file_read(BIO *b, char *out, int outl) int ret = 0; if (b->init && (out != NULL)) { - if (b->flags&BIO_FLAGS_UPLINK) - ret = UP_fread(out, 1,(int)outl, b->ptr); - else - ret = fread(out, 1,(int)outl,(FILE *)b->ptr); - if (ret == 0 && (b->flags & BIO_FLAGS_UPLINK) ? - UP_ferror((FILE *)b->ptr) : ferror((FILE *)b->ptr)) { + ret = fread(out, 1,(int)outl,(FILE *)b->ptr); + if (ret == 0 && ferror((FILE *)b->ptr)) { SYSerr(SYS_F_FREAD, errno); BIOerr(BIO_F_FILE_READ, ERR_R_SYS_LIB); ret = -1; @@ -213,10 +204,7 @@ file_write(BIO *b, const char *in, int inl) int ret = 0; if (b->init && (in != NULL)) { - if (b->flags&BIO_FLAGS_UPLINK) - ret = UP_fwrite(in,(int)inl, 1, b->ptr); - else - ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr); + ret = fwrite(in,(int)inl, 1,(FILE *)b->ptr); if (ret) ret = inl; /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ @@ -238,41 +226,20 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr) switch (cmd) { case BIO_C_FILE_SEEK: case BIO_CTRL_RESET: - if (b->flags&BIO_FLAGS_UPLINK) - ret = (long)UP_fseek(b->ptr, num, 0); - else - ret = (long)fseek(fp, num, 0); + ret = (long)fseek(fp, num, 0); break; case BIO_CTRL_EOF: - if (b->flags&BIO_FLAGS_UPLINK) - ret = (long)UP_feof(fp); - else - ret = (long)feof(fp); + ret = (long)feof(fp); break; case BIO_C_FILE_TELL: case BIO_CTRL_INFO: - if (b->flags&BIO_FLAGS_UPLINK) - ret = UP_ftell(b->ptr); - else - ret = ftell(fp); + ret = ftell(fp); break; case BIO_C_SET_FILE_PTR: file_free(b); b->shutdown = (int)num&BIO_CLOSE; b->ptr = ptr; b->init = 1; -#if BIO_FLAGS_UPLINK!=0 -#if defined(_IOB_ENTRIES) - /* Safety net to catch purely internal BIO_set_fp calls */ - if ((size_t)ptr >= (size_t)stdin && - (size_t)ptr < (size_t)(stdin + _IOB_ENTRIES)) - BIO_clear_flags(b, BIO_FLAGS_UPLINK); -#endif -#endif -#ifdef UP_fsetmod - if (b->flags&BIO_FLAGS_UPLINK) - UP_fsetmod(b->ptr,(char)((num&BIO_FP_TEXT)?'t':'b')); -#endif break; case BIO_C_SET_FILENAME: file_free(b); @@ -302,7 +269,6 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr) } b->ptr = fp; b->init = 1; - BIO_clear_flags(b, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */ break; case BIO_C_GET_FILE_PTR: /* the ptr parameter is actually a FILE ** in this case. */ @@ -318,10 +284,7 @@ file_ctrl(BIO *b, int cmd, long num, void *ptr) b->shutdown = (int)num; break; case BIO_CTRL_FLUSH: - if (b->flags&BIO_FLAGS_UPLINK) - UP_fflush(b->ptr); - else - fflush((FILE *)b->ptr); + fflush((FILE *)b->ptr); break; case BIO_CTRL_DUP: ret = 1; @@ -344,13 +307,8 @@ file_gets(BIO *bp, char *buf, int size) int ret = 0; buf[0] = '\0'; - if (bp->flags&BIO_FLAGS_UPLINK) { - if (!UP_fgets(buf, size, bp->ptr)) - goto err; - } else { - if (!fgets(buf, size,(FILE *)bp->ptr)) - goto err; - } + if (!fgets(buf, size,(FILE *)bp->ptr)) + goto err; if (buf[0] != '\0') ret = strlen(buf); err: diff --git a/lib/libssl/src/crypto/cryptlib.h b/lib/libssl/src/crypto/cryptlib.h index d1d7cfe80a8..b3342232c76 100644 --- a/lib/libssl/src/crypto/cryptlib.h +++ b/lib/libssl/src/crypto/cryptlib.h @@ -65,11 +65,6 @@ #include "e_os.h" -#ifdef OPENSSL_USE_APPLINK -#define BIO_FLAGS_UPLINK 0x8000 -#include "ms/uplink.h" -#endif - #include #include #include