From: Joseph C. <jos...@in...> - 2010-07-21 07:31:15
|
changeset ccc9e78f30fa in /var/www/tboot.hg details: tboot.hg?cmd=changeset;node=ccc9e78f30fa description: Added additional compiler warnings and cleaned up code to build cleanly Added: -Wall -Wformat-security -Werror -Wstrict-prototypes -Wextra -Winit-self -Wswitch-default -Wunused-parameter -Wwrite-strings -Wlogical-op -Wno-missing-field-initializers -D_FORTIFY_SOURCE=2 Signed-off-by: Joseph Cihula <jos...@in...> diffstat: Config.mk | 12 ++++-- include/tb_policy.h | 6 +- lcptools/crtpconf.c | 6 +- lcptools/crtpol.c | 36 +++++++++--------- lcptools/crtpolelt.c | 2 +- lcptools/crtpollist.c | 4 +- lcptools/defindex.c | 12 +++--- lcptools/getcap.c | 23 +++++------ lcptools/hash.c | 4 +- lcptools/lcputils.c | 5 +- lcptools/lcputils.h | 2 +- lcptools/lcputils2.c | 2 +- lcptools/mlehash.c | 2 +- lcptools/pol.c | 3 +- lcptools/pollist.c | 2 +- lcptools/readpol.c | 60 +++++++++++++++++++---------- lcptools/relindex.c | 2 +- lcptools/writepol.c | 40 ++++++++++++------- tb_polgen/hash.c | 4 +- tb_polgen/param.c | 6 +- tboot/common/acpi.c | 3 +- tboot/common/cmdline.c | 4 +- tboot/common/e820.c | 33 +++++++--------- tboot/common/loader.c | 10 ++-- tboot/common/paging.c | 7 ++- tboot/common/pci_cfgreg.c | 8 ++++ tboot/common/policy.c | 6 +- tboot/common/vmac.c | 6 +++ tboot/common/vsprintf.c | 8 ++-- tboot/include/loader.h | 4 +- tboot/txt/heap.c | 2 +- tboot/txt/mtrrs.c | 3 +- tboot/txt/txt.c | 2 +- tboot/txt/verify.c | 1 + utils/txt-stat.c | 6 ++- 35 files changed, 192 insertions(+), 144 deletions(-) diffs (truncated from 1104 to 300 lines): diff -r 3aa464aa2b6d -r ccc9e78f30fa Config.mk --- a/Config.mk Tue Jul 20 21:14:47 2010 -0700 +++ b/Config.mk Tue Jul 20 23:51:25 2010 -0700 @@ -34,9 +34,14 @@ /dev/null 2>&1`"; then echo "$(2)"; else echo "$(3)"; fi ;) +CFLAGS_WARN = -Wall -Wformat-security -Werror -Wstrict-prototypes \ + -Wextra -Winit-self -Wswitch-default -Wunused-parameter \ + -Wwrite-strings -Wlogical-op \ + -Wno-missing-field-initializers \ + -D_FORTIFY_SOURCE=2 + HOSTCC = gcc -HOSTCFLAGS = -Wall -Wformat-security -Werror -Wstrict-prototypes -HOSTCFLAGS += -O2 -std=gnu99 -fno-strict-aliasing +HOSTCFLAGS = $(CFLAGS_WARN) -O2 -std=gnu99 -fno-strict-aliasing HOSTCFLAGS_x86_32 = -m32 HOSTCFLAGS_x86_64 = -m64 @@ -67,8 +72,7 @@ # TARGET_ARCH ?= $(shell uname -m | sed -e s/i.86/x86_32/ -e s/i86pc/x86_32/) -CFLAGS += -Wall -Wformat-security -Werror -Wstrict-prototypes -CFLAGS += -fno-strict-aliasing -std=gnu99 +CFLAGS += $(CFLAGS_WARN) -fno-strict-aliasing -std=gnu99 # due to bug in gcc v4.2,3,? CFLAGS += $(call cc-option,$(CC),-Wno-array-bounds,) diff -r 3aa464aa2b6d -r ccc9e78f30fa include/tb_policy.h --- a/include/tb_policy.h Tue Jul 20 21:14:47 2010 -0700 +++ b/include/tb_policy.h Tue Jul 20 23:51:25 2010 -0700 @@ -2,7 +2,7 @@ * tb_policy.h: data structures, definitions, and helper fns for tboot * verified launch policies * - * Copyright (c) 2006-2008, Intel Corporation + * Copyright (c) 2006-2010, Intel Corporation * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -106,7 +106,7 @@ * helper fns */ #ifndef PRINT -#define PRINT(...) /**/ +#define PRINT(...) {} #endif static inline const char *hash_type_to_string(uint8_t hash_type) @@ -250,7 +250,7 @@ static inline bool verify_policy(const tb_policy_t *policy, size_t size, bool print) { - if ( print) PRINT("policy:\n"); + if ( print ) PRINT("policy:\n"); if ( policy == NULL ) { if ( print ) PRINT("policy pointer is NULL\n"); diff -r 3aa464aa2b6d -r ccc9e78f30fa lcptools/crtpconf.c --- a/lcptools/crtpconf.c Tue Jul 20 21:14:47 2010 -0700 +++ b/lcptools/crtpconf.c Tue Jul 20 23:51:25 2010 -0700 @@ -1,5 +1,5 @@ /* - * Copyright 2001 - 2007 Intel Corporation. All Rights Reserved. + * Copyright 2001 - 2010 Intel Corporation. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -163,12 +163,12 @@ ret_value = LCP_E_INVALID_PARAMETER; goto _error_end; } - for (i = 0; i < idx_num; i++) { + for ( i = 0; i < idx_num; i++ ) { if ( strtonum((char *)pcr_num[i], &temp) < 0 ) { ret_value = LCP_E_INVALID_PARAMETER; goto _error_end; } - if ( temp < 0 || temp > 23 ) { + if ( temp > 23 ) { ret_value = LCP_E_INVALID_PARAMETER; goto _error_end; } diff -r 3aa464aa2b6d -r ccc9e78f30fa lcptools/crtpol.c --- a/lcptools/crtpol.c Tue Jul 20 21:14:47 2010 -0700 +++ b/lcptools/crtpol.c Tue Jul 20 23:51:25 2010 -0700 @@ -74,23 +74,23 @@ {0, 0, 0, 0}, }; -static const char * usage_string = "lcp_crtpol -t policy_type [-a hashalg] "\ - "[-v version] [-sr SINIT revocation_counter] [-s srtm_file] "\ +static const char *usage_string = "lcp_crtpol -t policy_type [-a hashalg] " + "[-v version] [-sr SINIT revocation_counter] [-s srtm_file] " "[-m mle_file] [-o policyfile] [-b policydata_file] [-h]\n"; -static const char * option_strings[] ={ - "-t Policy type: uint8/string.\n"\ - "\tPolicy type is:\n"\ - "\tLCP_POLTYPE_HASHONLY: 0 or \"hashonly\" \n"\ - "\tLCP_POLTYPE_UNSIGNED: 1 or \"unsigned\" \n"\ - "\tLCP_POLTYPE_SIGNED: 2 or \"signed\" \n"\ - "\tLCP_POLTYPE_ANY: 3 or \"any\" \n"\ +static const char *option_strings[] = { + "-t Policy type: uint8/string.\n" + "\tPolicy type is:\n" + "\tLCP_POLTYPE_HASHONLY: 0 or \"hashonly\" \n" + "\tLCP_POLTYPE_UNSIGNED: 1 or \"unsigned\" \n" + "\tLCP_POLTYPE_SIGNED: 2 or \"signed\" \n" + "\tLCP_POLTYPE_ANY: 3 or \"any\" \n" "\tLCP_POLTYPE_FORCEOWNERPOLICY: 4 or \"forceowner\" \n", - "-a algorithm: uint8/string. algorithm used in the policy.\n"\ - "\tAlgorithm choice:\n"\ - "\t\tLCP_POLHALG_SHA1: 0 or \"sha1\" \n"\ + "-a algorithm: uint8/string. algorithm used in the policy.\n" + "\tAlgorithm choice:\n" + "\t\tLCP_POLHALG_SHA1: 0 or \"sha1\" \n" "\tCurrently we only support SHA-1 algorithm.\n", - "-v version: uint8. version number.\n"\ + "-v version: uint8. version number.\n" "\tCurrently 0 or 1 is allowed.\n", "-s PConf file name: String. File name of PConf data.\n", "-m MLE hash file name: String. File containing the MLE hashes.\n", @@ -98,8 +98,8 @@ "-b LCPPOLICYDATA file name: String. File to save Policy data.\n", "-sr SINIT Revocation count number: uint8.\n", "-pcf Policy Control Field: uint32.\n", - "-h help. Will print out this help message.\n" - ,0 + "-h help. Will print out this help message.\n", + NULL }; static param_option_t poltype_option_table[] = { @@ -131,11 +131,11 @@ /* * if not, then the users should input the 0~4 number, */ - if ( temp == -1 ) + if ( temp == (unsigned int)-1 ) if ( strtonum(optarg, &temp) ) return LCP_E_INVALID_PARAMETER; - if ( temp < 0 || temp > 4 ) { + if ( temp > 4 ) { log_error("policy type out of range.\n"); return LCP_E_INVALID_PARAMETER; } @@ -185,7 +185,7 @@ case 'n': if ( strtonum(optarg, &temp) ) return LCP_E_INVALID_PARAMETER; - if ( temp > 0xff || temp < 0 ) + if ( temp > 0xff ) return LCP_E_INVALID_PARAMETER; sinit_revoc = temp; break; diff -r 3aa464aa2b6d -r ccc9e78f30fa lcptools/crtpolelt.c --- a/lcptools/crtpolelt.c Tue Jul 20 21:14:47 2010 -0700 +++ b/lcptools/crtpolelt.c Tue Jul 20 23:51:25 2010 -0700 @@ -91,7 +91,7 @@ static void add_plugins(void) { /* we will add each plugin's opts to end, so find initial last one */ - int nr_opts = 0; + unsigned int nr_opts = 0; struct option *opt = long_opts; while ( opt->name != NULL ) { opt++; diff -r 3aa464aa2b6d -r ccc9e78f30fa lcptools/crtpollist.c --- a/lcptools/crtpollist.c Tue Jul 20 21:14:47 2010 -0700 +++ b/lcptools/crtpollist.c Tue Jul 20 23:51:25 2010 -0700 @@ -138,7 +138,7 @@ return NULL; } - int keysize = RSA_size(pubkey); + unsigned int keysize = RSA_size(pubkey); if ( keysize == 0 ) { ERROR("Error: public key size is 0\n"); RSA_free(pubkey); @@ -154,7 +154,7 @@ memset(sig, 0, sizeof(*sig) + 2*keysize); sig->pubkey_size = keysize; - if ( BN_num_bytes(pubkey->n) != keysize ) { + if ( (unsigned int)BN_num_bytes(pubkey->n) != keysize ) { ERROR("Error: modulus size not match key size\n"); free(sig); RSA_free(pubkey); diff -r 3aa464aa2b6d -r ccc9e78f30fa lcptools/defindex.c --- a/lcptools/defindex.c Tue Jul 20 21:14:47 2010 -0700 +++ b/lcptools/defindex.c Tue Jul 20 23:51:25 2010 -0700 @@ -70,10 +70,10 @@ {"rl", 1, 0, 'r'}, {0, 0, 0, 0}}; -static char *usage_string = "tpmnv_defindex -i index [-s size] "\ - "[-pv permission_value] "\ - "[-p passwd] [-av authentication_value] "\ - "[-wl write_locality] [-rl read_locality] [-h]"; +static const char *usage_string = "tpmnv_defindex -i index [-s size] " + "[-pv permission_value] " + "[-p passwd] [-av authentication_value] " + "[-wl write_locality] [-rl read_locality] [-h]"; static const char * option_strings[] = { "-i index value: uint32/string.\n"\ @@ -94,7 +94,7 @@ "\tFor example, locality value is 0x18 if locality 3 or 4. \n", "-wl write locality value: uint8. The same as read locality value.\n", "-h help. Will print out this help message.\n", - 0 + NULL }; static param_option_t index_option_table[] = { @@ -125,7 +125,7 @@ * if not, then the users should input the non-0 number, * 0 is not allowed for index */ - if ( index_value == -1 ) + if ( index_value == (uint32_t)-1 ) if ( strtonum(optarg, &index_value) || (index_value == 0) ) return LCP_E_INVALID_PARAMETER; diff -r 3aa464aa2b6d -r ccc9e78f30fa lcptools/getcap.c --- a/lcptools/getcap.c Tue Jul 20 21:14:47 2010 -0700 +++ b/lcptools/getcap.c Tue Jul 20 23:51:25 2010 -0700 @@ -61,7 +61,7 @@ static uint32_t passwd_length = 0; static const char *short_option = "hi:f:"; -static char *usage_string = "tpmnv_getcap [-i index] [-f password] [-h]"; +static const char *usage_string = "tpmnv_getcap [-i index] [-f password] [-h]"; static const char * option_strings[] ={ "-i index value: uint32/string. To get the public data of this index.\n"\ @@ -70,7 +70,7 @@ "\tINDEX_AUX:0x50000002 or \"aux\"\n", "-f password: string displays TPM_PERMANENT_FLAGS.\n", "-h help. Will print out this help message.\n", - 0 + NULL }; static param_option_t index_option_table[] = { @@ -97,7 +97,7 @@ * if not, then the users should input the non-0 number, * 0 is not allowed for index */ - if ( index_value == -1 ) + if ( index_value == (uint32_t)-1 ) if ( strtonum(optarg, &index_value) || (index_value == 0) ) return LCP_E_INVALID_PARAMETER; break; @@ -271,7 +271,7 @@ lcp_result_t ret_value = LCP_E_COMD_INTERNAL_ERR; ret_value = lcp_get_tpmcap(TSS_TPMCAP_NV_INDEX, 4, - (unsigned char *)&index_value, + (unsigned char *)&index, &datasize, buffer); if ( ret_value != LCP_SUCCESS ) @@ -287,9 +287,8 @@ * If the index retrieved correctly, * print the public data to the screen. */ - if ( index_retrieve == index_value ) { - log_info("\nThe public data value of index 0x%08x is: \n", - index_value); + if ( index_retrieve == index ) { + log_info("\nThe public data value of index 0x%08x is: \n", index); /* print the public data to the screen */ print_nv_caps_msg(datasize, buffer, ""); @@ -297,8 +296,8 @@ lcp_unloaddata_uint16(&pcrread_sizeofselect, &pbuffer, 1); pbuffer += pcrread_sizeofselect; log_info("\n\tRead locality: "); - print_locality(*pbuffer); - log_info(".\n"); + print_locality(*pbuffer); + log_info(".\n"); /* move the pbuffer to the start of pcrInfoWrite */ pbuffer += pcrread_sizeofselect @@ -309,8 +308,8 @@ lcp_unloaddata_uint16(&pcrwrite_sizeofselect, &pbuffer, 1); pbuffer += pcrwrite_sizeofselect; log_info("\n\tWrite locality: "); - print_locality(*pbuffer); - log_info(".\n"); + print_locality(*pbuffer); + log_info(".\n"); /* move the pointer and get permission value */ |