Commit 05a15df9 authored by Marc-André Lureau's avatar Marc-André Lureau

build-sys: use WARN_CFLAGS/WARN_LDFLAGS and fix errors

Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
parent cdc61d0c
......@@ -37,6 +37,7 @@ libcacard_la_LDFLAGS = \
-export-symbols $(srcdir)/src/libcacard.syms \
-no-undefined \
-version-info 0:0:0 \
$(WARN_LDFLAGS)
$(NULL)
pkgconfigdir = $(libdir)/pkgconfig
......@@ -46,7 +47,7 @@ bin_PROGRAMS = vscclient
vscclient_SOURCES = src/vscclient.c
vscclient_LDADD = libcacard.la $(CACARD_LIBS)
AM_CPPFLAGS = $(CACARD_CFLAGS)
AM_CPPFLAGS = $(CACARD_CFLAGS) $(WARN_CFLAGS)
EXTRA_DIST = \
README.md \
docs/libcacard.txt \
......
......@@ -187,6 +187,8 @@ vcard_response_delete(VCardResponse *response)
break;
case VCARD_STATIC:
break;
default:
g_warn_if_reached();
}
}
......@@ -750,6 +752,8 @@ vcard_process_apdu(VCard *card, VCardAPDU *apdu, VCardResponse **response)
/* if we are type direct, then the applet should handle everything */
assert(!"VCARD_DIRECT: applet failure");
break;
default:
g_warn_if_reached();
}
*response =
vcard_make_response(VCARD7816_STATUS_ERROR_COMMAND_NOT_SUPPORTED);
......
......@@ -195,9 +195,9 @@ vcard_get_atr(VCard *vcard, unsigned char *atr, int *atr_len)
}
void
vcard_set_atr_func(VCard *card, VCardGetAtr vcard_get_atr)
vcard_set_atr_func(VCard *card, VCardGetAtr get_atr)
{
card->vcard_get_atr = vcard_get_atr;
card->vcard_get_atr = get_atr;
}
......
......@@ -203,6 +203,8 @@ vcard_emul_map_error(int error)
return VCARD7816_STATUS_ERROR_DATA_INVALID;
case SEC_ERROR_NO_MEMORY:
return VCARD7816_STATUS_EXC_ERROR_MEMORY_FAILURE;
default:
g_warn_if_reached();
}
return VCARD7816_STATUS_EXC_ERROR_CHANGE;
}
......@@ -221,6 +223,7 @@ vcard_emul_rsa_op(VCard *card, VCardKey *key,
int pad_len;
vcard_7816_status_t ret = VCARD7816_STATUS_SUCCESS;
assert(buffer_size >= 0);
if ((!nss_emul_init) || (key == NULL)) {
/* couldn't get the key, indicate that we aren't logged in */
return VCARD7816_STATUS_ERROR_CONDITION_NOT_SATISFIED;
......@@ -236,7 +239,7 @@ vcard_emul_rsa_op(VCard *card, VCardKey *key,
* this is only true of the rsa signature
*/
signature_len = PK11_SignatureLen(priv_key);
if (buffer_size != signature_len) {
if ((unsigned)buffer_size != signature_len) {
return VCARD7816_STATUS_ERROR_DATA_INVALID;
}
/* be able to handle larger keys if necessariy */
......@@ -256,7 +259,7 @@ vcard_emul_rsa_op(VCard *card, VCardKey *key,
rv = PK11_PrivDecryptRaw(priv_key, bp, &signature_len, signature_len,
buffer, buffer_size);
if (rv == SECSuccess) {
assert(buffer_size == signature_len);
assert((unsigned)buffer_size == signature_len);
memcpy(buffer, bp, signature_len);
key->failedX509 = VCardEmulFalse;
goto cleanup;
......@@ -306,7 +309,7 @@ vcard_emul_rsa_op(VCard *card, VCardKey *key,
ret = vcard_emul_map_error(PORT_GetError());
goto cleanup;
}
assert(buffer_size == signature.len);
assert((unsigned)buffer_size == signature.len);
memcpy(buffer, bp, signature.len);
/*
* we got here because either the X509 attempt failed, or the
......
......@@ -12,6 +12,7 @@
#include "vcardt.h"
#include "vcard_emul_type.h"
#include "cac.h"
#include "glib-compat.h"
VCardStatus vcard_init(VReader *vreader, VCard *vcard,
VCardEmulType type, const char *params,
......@@ -25,7 +26,9 @@ VCardStatus vcard_init(VReader *vreader, VCard *vcard,
return cac_card_init(vreader, vcard, params,
cert, cert_len, key, cert_count);
/* add new ones here */
case VCARD_EMUL_PASSTHRU:
default:
g_warn_if_reached();
break;
}
return VCARD_FAIL;
......
......@@ -89,8 +89,9 @@ apdu_ins_to_string(int ins)
return "sign decrypt";
case CAC_GET_CERTIFICATE:
return "get certificate";
default:
g_return_val_if_reached("unknown");
}
return "unknown";
}
/* manage locking */
......@@ -262,6 +263,7 @@ vreader_xfr_bytes(VReader *reader,
VCardStatus card_status;
unsigned short status;
VCard *card = vreader_get_card(reader);
int size;
if (card == NULL) {
return VREADER_NO_CARD;
......@@ -283,7 +285,7 @@ vreader_xfr_bytes(VReader *reader,
}
}
assert(card_status == VCARD_DONE && response);
int size = MIN(*receive_buf_len, response->b_total_len);
size = MIN(*receive_buf_len, response->b_total_len);
memcpy(receive_buf, response->b_data, size);
*receive_buf_len = size;
vcard_response_delete(response);
......
......@@ -71,8 +71,15 @@ typedef enum VSCErrorCode {
#define VSCARD_UNDEFINED_READER_ID 0xffffffff
#define VSCARD_MINIMAL_READER_ID 0
#define VSCARD_MAGIC (*(uint32_t *)"VSCD")
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
#define VSCARD_MAGIC_CONST(f) \
((uint32_t)(((f)[0])|((f)[1]<<8)|((f)[2]<<16)|((f)[3]<<24)))
#else
#define VSCARD_MAGIC_CONST(f) \
((uint32_t)(((f)[3])|((f)[2]<<8)|((f)[1]<<16)|((f)[0]<<24)))
#endif
#define VSCARD_MAGIC VSCARD_MAGIC_CONST("VSCD")
/*
* Header
* Each message starts with the header.
......
......@@ -36,7 +36,7 @@ static int verbose;
static void
print_byte_array(
uint8_t *arrBytes,
unsigned int nSize
int nSize
) {
int i;
for (i = 0; i < nSize; i++) {
......@@ -224,6 +224,7 @@ event_thread(gpointer arg)
}
send_msg(VSC_CardRemove, reader_id, NULL, 0);
break;
case VEVENT_LAST:
default:
break;
}
......@@ -299,8 +300,9 @@ do_socket_read(GIOChannel *source,
VReaderStatus reader_status;
VReader *reader = NULL;
static VSCMsgHeader mhHeader;
VSCMsgError *error_msg;
VSCMsgError error_msg;
GError *err = NULL;
VSCMsgInit init;
static gchar *buf;
static gsize br, to_read;
......@@ -382,8 +384,8 @@ do_socket_read(GIOChannel *source,
send_msg(VSC_FlushComplete, mhHeader.reader_id, NULL, 0);
break;
case VSC_Error:
error_msg = (VSCMsgError *) pbSendBuffer;
if (error_msg->code == VSC_SUCCESS) {
memcpy(&error_msg, pbSendBuffer, sizeof(VSCMsgError));
if (error_msg.code == VSC_SUCCESS) {
g_mutex_lock(&pending_reader_lock);
if (pending_reader) {
vreader_set_id(pending_reader, mhHeader.reader_id);
......@@ -395,7 +397,7 @@ do_socket_read(GIOChannel *source,
break;
}
printf("warning: qemu refused to add reader\n");
if (error_msg->code == VSC_CANNOT_ADD_MORE_READERS) {
if (error_msg.code == VSC_CANNOT_ADD_MORE_READERS) {
/* clear pending reader, qemu can't handle any more */
g_mutex_lock(&pending_reader_lock);
if (pending_reader) {
......@@ -407,7 +409,8 @@ do_socket_read(GIOChannel *source,
}
break;
case VSC_Init:
if (on_host_init(&mhHeader, (VSCMsgInit *)pbSendBuffer) < 0) {
memcpy(&init, pbSendBuffer, sizeof(VSCMsgInit));
if (on_host_init(&mhHeader, &init) < 0) {
return FALSE;
}
break;
......@@ -485,18 +488,18 @@ do_command(GIOChannel *source,
printf("Active Readers:\n");
for (reader_entry = vreader_list_get_first(list); reader_entry;
reader_entry = vreader_list_get_next(reader_entry)) {
VReader *reader = vreader_list_get_reader(reader_entry);
vreader_id_t reader_id;
reader_id = vreader_get_id(reader);
if (reader_id == -1) {
VReader *r = vreader_list_get_reader(reader_entry);
vreader_id_t id;
id = vreader_get_id(r);
if (id == (vreader_id_t)-1) {
continue;
}
/* be nice and signal card removal first (qemu probably should
* do this itself) */
if (vreader_card_is_present(reader) == VREADER_OK) {
send_msg(VSC_CardRemove, reader_id, NULL, 0);
if (vreader_card_is_present(r) == VREADER_OK) {
send_msg(VSC_CardRemove, id, NULL, 0);
}
send_msg(VSC_ReaderRemove, reader_id, NULL, 0);
send_msg(VSC_ReaderRemove, id, NULL, 0);
}
exit(0);
} else if (strncmp(string, "insert", 6) == 0) {
......@@ -549,31 +552,31 @@ do_command(GIOChannel *source,
printf("Active Readers:\n");
for (reader_entry = vreader_list_get_first(list); reader_entry;
reader_entry = vreader_list_get_next(reader_entry)) {
VReader *reader = vreader_list_get_reader(reader_entry);
vreader_id_t reader_id;
reader_id = vreader_get_id(reader);
if (reader_id == -1) {
VReader *r = vreader_list_get_reader(reader_entry);
vreader_id_t id;
id = vreader_get_id(r);
if (id == (vreader_id_t)-1) {
continue;
}
printf("%3u %s %s\n", reader_id,
vreader_card_is_present(reader) == VREADER_OK ?
printf("%3u %s %s\n", id,
vreader_card_is_present(r) == VREADER_OK ?
"CARD_PRESENT" : " ",
vreader_get_name(reader));
vreader_get_name(r));
}
printf("Inactive Readers:\n");
for (reader_entry = vreader_list_get_first(list); reader_entry;
reader_entry = vreader_list_get_next(reader_entry)) {
VReader *reader = vreader_list_get_reader(reader_entry);
vreader_id_t reader_id;
reader_id = vreader_get_id(reader);
if (reader_id != -1) {
VReader *r = vreader_list_get_reader(reader_entry);
vreader_id_t id;
id = vreader_get_id(reader);
if (id != (vreader_id_t)-1) {
continue;
}
printf("INA %s %s\n",
vreader_card_is_present(reader) == VREADER_OK ?
vreader_card_is_present(r) == VREADER_OK ?
"CARD_PRESENT" : " ",
vreader_get_name(reader));
vreader_get_name(r));
}
vreader_list_delete(list);
} else if (*string != 0) {
......@@ -656,7 +659,7 @@ main(
GIOChannel *channel_stdin;
char *qemu_host;
char *qemu_port;
VSCMsgInit init;
VCardEmulOptions *command_line_options = NULL;
char *cert_names[MAX_CERTS];
......@@ -698,6 +701,8 @@ main(
case 'd':
verbose = get_id_from_string(optarg, 1);
break;
default:
g_warn_if_reached();
}
}
......@@ -766,7 +771,7 @@ main(
g_io_channel_set_buffered(channel_socket, FALSE);
/* Send init message, Host responds (and then we send reader attachments) */
VSCMsgInit init = {
init = (VSCMsgInit) {
.version = htonl(VSCARD_VERSION),
.magic = VSCARD_MAGIC,
.capabilities = {0}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment