- fixed invalid memory read
- added more input checking git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@304 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
@@ -32,7 +32,7 @@
|
|||||||
#include "picc_to_pcsc.h"
|
#include "picc_to_pcsc.h"
|
||||||
#include "pcscutil.h"
|
#include "pcscutil.h"
|
||||||
|
|
||||||
static FILE *picc_fd = 0; /*filehandle used for PICCDEV*/
|
static FILE *picc_fd = NULL; /*filehandle used for PICCDEV*/
|
||||||
|
|
||||||
static LPSTR readers = NULL;
|
static LPSTR readers = NULL;
|
||||||
static SCARDCONTEXT hContext = 0;
|
static SCARDCONTEXT hContext = 0;
|
||||||
@@ -49,6 +49,7 @@ void cleanup_exit(int signo){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cleanup(void) {
|
void cleanup(void) {
|
||||||
|
if (picc_fd)
|
||||||
fclose(picc_fd);
|
fclose(picc_fd);
|
||||||
pcsc_disconnect(hContext, hCard, readers);
|
pcsc_disconnect(hContext, hCard, readers);
|
||||||
}
|
}
|
||||||
@@ -60,8 +61,8 @@ size_t picc_decode_apdu(char *inbuf, size_t inlen, unsigned char **outbuf)
|
|||||||
char *end, *p;
|
char *end, *p;
|
||||||
unsigned long int b;
|
unsigned long int b;
|
||||||
|
|
||||||
if (inbuf == NULL || inlen == 0 || inbuf[0] == '\0') {
|
if (!outbuf || inbuf == NULL || inlen == 0 || inbuf[0] == '\0') {
|
||||||
//Ignore empty lines and 'RESET' lines
|
/* Ignore invalid parameters, empty and 'RESET' lines */
|
||||||
goto noapdu;
|
goto noapdu;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,10 +103,10 @@ size_t picc_encode_rapdu(unsigned char *inbuf, size_t inlen, char **outbuf)
|
|||||||
unsigned char *next;
|
unsigned char *next;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
|
||||||
if (!inbuf || inlen > 0xffff)
|
if (!inbuf || inlen > 0xffff || !outbuf)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
length = inlen*3+5;
|
length = 5+inlen*3+1;
|
||||||
p = realloc(*outbuf, length);
|
p = realloc(*outbuf, length);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
fprintf(stderr, "Error allocating memory for encoded R-APDU\n");
|
fprintf(stderr, "Error allocating memory for encoded R-APDU\n");
|
||||||
@@ -239,8 +240,6 @@ int main (int argc, char **argv)
|
|||||||
|
|
||||||
err:
|
err:
|
||||||
cleanup();
|
cleanup();
|
||||||
stringify_error(r);
|
|
||||||
pcsc_disconnect(hContext, hCard, readers);
|
|
||||||
|
|
||||||
exit(r == SCARD_S_SUCCESS ? 0 : 1);
|
exit(r == SCARD_S_SUCCESS ? 0 : 1);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user