From 3674c41f665fb4d3ce290ec6e0981767ac240125 Mon Sep 17 00:00:00 2001 From: frankmorgner Date: Sun, 6 Feb 2011 20:26:37 +0000 Subject: [PATCH] added compatibility to mingw git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@408 96b47cad-a561-4643-ad3b-153ac7d7599c --- npa/configure.ac | 2 +- npa/src/npa-tool.c | 20 +++++++++++++++++++- npa/src/npa.c | 12 +++++++++--- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/npa/configure.ac b/npa/configure.ac index 00d16ed..01d354d 100644 --- a/npa/configure.ac +++ b/npa/configure.ac @@ -77,7 +77,7 @@ AC_TYPE_UINT8_T # Checks for library functions. AC_FUNC_MALLOC AC_FUNC_REALLOC -AC_CHECK_FUNCS([memmove memset strerror]) +AC_CHECK_FUNCS([getline memmove memset strerror]) cat << EOF diff --git a/npa/src/npa-tool.c b/npa/src/npa-tool.c index 555067f..fdf6db5 100644 --- a/npa/src/npa-tool.c +++ b/npa/src/npa-tool.c @@ -26,7 +26,25 @@ #include #include #include -#include +#include + +#ifndef HAVE_GETLINE +static ssize_t getline(char **lineptr, size_t *n, FILE *stream) +{ + if (!lineptr) + return -1; + + char *p = realloc(*lineptr, SC_MAX_EXT_APDU_BUFFER_SIZE*3); + if (!p) + return -1; + *lineptr = p; + + if (fgets(p, SC_MAX_EXT_APDU_BUFFER_SIZE*3, stream) == NULL) + return -1; + + return strlen(p); +} +#endif static int verbose = 0; static int doinfo = 0; diff --git a/npa/src/npa.c b/npa/src/npa.c index 1d68a23..8c356b8 100644 --- a/npa/src/npa.c +++ b/npa/src/npa.c @@ -907,7 +907,9 @@ npa_reset_retry_counter(struct sm_ctx *ctx, sc_card_t *card, free(p); return SC_ERROR_INTERNAL; } - new_len = strnlen(p, MAX_PIN_LEN+1); + new_len = strlen(p); + if (new_len > MAX_PIN_LEN) + return SC_ERROR_INVALID_PIN_LENGTH; new = p; } @@ -952,7 +954,7 @@ get_psec(sc_card_t *card, const char *pin, size_t length_pin, enum s_type pin_id sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Could not create password prompt.\n"); return NULL; } - p = malloc(MAX_MRZ_LEN); + p = malloc(MAX_MRZ_LEN+1); if (!p) { sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Not enough memory for %s.\n", npa_secret_name(pin_id)); @@ -963,7 +965,11 @@ get_psec(sc_card_t *card, const char *pin, size_t length_pin, enum s_type pin_id npa_secret_name(pin_id)); return NULL; } - length_pin = strnlen(p, MAX_MRZ_LEN); + length_pin = strlen(p); + if (length_pin > MAX_MRZ_LEN) { + sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "MRZ too long"); + return NULL; + } pin = p; }