From: <mil...@us...> - 2008-03-04 17:29:44
|
Revision: 2831 http://selinux.svn.sourceforge.net/selinux/?rev=2831&view=rev Author: millertc Date: 2008-03-04 09:29:33 -0800 (Tue, 04 Mar 2008) Log Message: ----------- Author: Todd C. Miller <tm...@tr...> Subject: PATCH: fix uninitialized use of handle in struct policy_file Date: Tuesday, March 04, 2008 9:37 AM Add policy_file_init() function and use it to initialize struct policy_file (aka policy_file_t) before using. Fixes several instances of the "handle" element being uses unitialized. Signed-off-by: Todd C. Miller <tm...@tr...> Acked-by: Stephen Smalley <sd...@ty...> checkpolicy/checkmodule.c | 2 ++ checkpolicy/checkpolicy.c | 2 ++ checkpolicy/test/dismod.c | 1 + checkpolicy/test/dispol.c | 1 + libsepol/include/sepol/policydb/policydb.h | 2 ++ libsepol/src/genbools.c | 2 ++ libsepol/src/module.c | 3 +-- libsepol/src/policydb.c | 5 +++++ libsepol/src/policydb_convert.c | 4 ++-- libsepol/src/services.c | 15 +++++++++------ 10 files changed, 27 insertions(+), 10 deletions(-) Modified Paths: -------------- trunk/checkpolicy/checkmodule.c trunk/checkpolicy/checkpolicy.c trunk/checkpolicy/test/dismod.c trunk/checkpolicy/test/dispol.c trunk/libsepol/include/sepol/policydb/policydb.h trunk/libsepol/src/genbools.c trunk/libsepol/src/module.c trunk/libsepol/src/policydb.c trunk/libsepol/src/policydb_convert.c trunk/libsepol/src/services.c Modified: trunk/checkpolicy/checkmodule.c =================================================================== --- trunk/checkpolicy/checkmodule.c 2008-03-03 21:08:14 UTC (rev 2830) +++ trunk/checkpolicy/checkmodule.c 2008-03-04 17:29:33 UTC (rev 2831) @@ -71,6 +71,7 @@ fprintf(stderr, "Can't map '%s': %s\n", file, strerror(errno)); return -1; } + policy_file_init(&f); f.type = PF_USE_MEMORY; f.data = map; f.len = sb.st_size; @@ -124,6 +125,7 @@ p->policyvers = policyvers; p->handle_unknown = handle_unknown; + policy_file_init(&pf); pf.type = PF_USE_STDIO; pf.fp = outfp; ret = policydb_write(p, &pf); Modified: trunk/checkpolicy/checkpolicy.c =================================================================== --- trunk/checkpolicy/checkpolicy.c 2008-03-03 21:08:14 UTC (rev 2830) +++ trunk/checkpolicy/checkpolicy.c 2008-03-04 17:29:33 UTC (rev 2831) @@ -489,6 +489,7 @@ file, strerror(errno)); exit(1); } + policy_file_init(&pf); pf.type = PF_USE_MEMORY; pf.data = map; pf.len = sb.st_size; @@ -577,6 +578,7 @@ policydb.policy_type = POLICY_KERN; policydb.policyvers = policyvers; + policy_file_init(&pf); pf.type = PF_USE_STDIO; pf.fp = outfp; ret = policydb_write(&policydb, &pf); Modified: trunk/checkpolicy/test/dismod.c =================================================================== --- trunk/checkpolicy/test/dismod.c 2008-03-03 21:08:14 UTC (rev 2830) +++ trunk/checkpolicy/test/dismod.c 2008-03-04 17:29:33 UTC (rev 2831) @@ -689,6 +689,7 @@ filename, strerror(errno)); exit(1); } + policy_file_init(&f); f.type = PF_USE_STDIO; f.fp = in_fp; Modified: trunk/checkpolicy/test/dispol.c =================================================================== --- trunk/checkpolicy/test/dispol.c 2008-03-03 21:08:14 UTC (rev 2830) +++ trunk/checkpolicy/test/dispol.c 2008-03-04 17:29:33 UTC (rev 2831) @@ -373,6 +373,7 @@ /* read the binary policy */ fprintf(out_fp, "Reading policy...\n"); + policy_file_init(&pf); pf.type = PF_USE_MEMORY; pf.data = map; pf.len = sb.st_size; Modified: trunk/libsepol/include/sepol/policydb/policydb.h =================================================================== --- trunk/libsepol/include/sepol/policydb/policydb.h 2008-03-03 21:08:14 UTC (rev 2830) +++ trunk/libsepol/include/sepol/policydb/policydb.h 2008-03-04 17:29:33 UTC (rev 2831) @@ -568,6 +568,8 @@ struct policy_file pf; }; +extern void policy_file_init(policy_file_t * x); + extern int policydb_read(policydb_t * p, struct policy_file *fp, unsigned int verbose); extern int avrule_read_list(policydb_t * p, avrule_t ** avrules, Modified: trunk/libsepol/src/genbools.c =================================================================== --- trunk/libsepol/src/genbools.c 2008-03-03 21:08:14 UTC (rev 2830) +++ trunk/libsepol/src/genbools.c 2008-03-04 17:29:33 UTC (rev 2831) @@ -154,6 +154,7 @@ goto err_destroy; } + policy_file_init(&pf); pf.type = PF_USE_MEMORY; pf.data = data; pf.len = len; @@ -225,6 +226,7 @@ goto err_destroy; } + policy_file_init(&pf); pf.type = PF_USE_MEMORY; pf.data = data; pf.len = len; Modified: trunk/libsepol/src/module.c =================================================================== --- trunk/libsepol/src/module.c 2008-03-03 21:08:14 UTC (rev 2830) +++ trunk/libsepol/src/module.c 2008-03-04 17:29:33 UTC (rev 2831) @@ -851,9 +851,8 @@ if (p->policy) { /* compute policy length */ + policy_file_init(&polfile); polfile.type = PF_LEN; - polfile.data = NULL; - polfile.len = 0; polfile.handle = file->handle; if (policydb_write(&p->policy->p, &polfile)) return -1; Modified: trunk/libsepol/src/policydb.c =================================================================== --- trunk/libsepol/src/policydb.c 2008-03-03 21:08:14 UTC (rev 2830) +++ trunk/libsepol/src/policydb.c 2008-03-04 17:29:33 UTC (rev 2831) @@ -3290,3 +3290,8 @@ return 0; } + +void policy_file_init(policy_file_t *pf) +{ + memset(pf, 0, sizeof(policy_file_t)); +} Modified: trunk/libsepol/src/policydb_convert.c =================================================================== --- trunk/libsepol/src/policydb_convert.c 2008-03-03 21:08:14 UTC (rev 2830) +++ trunk/libsepol/src/policydb_convert.c 2008-03-04 17:29:33 UTC (rev 2831) @@ -13,6 +13,7 @@ policy_file_t pf; + policy_file_init(&pf); pf.type = PF_USE_MEMORY; pf.data = data; pf.len = len; @@ -39,9 +40,8 @@ struct policydb tmp_policydb; /* Compute the length for the new policy image. */ + policy_file_init(&pf); pf.type = PF_LEN; - pf.data = NULL; - pf.len = 0; pf.handle = handle; if (policydb_write(policydb, &pf)) { ERR(handle, "could not compute policy length"); Modified: trunk/libsepol/src/services.c =================================================================== --- trunk/libsepol/src/services.c 2008-03-03 21:08:14 UTC (rev 2830) +++ trunk/libsepol/src/services.c 2008-03-04 17:29:33 UTC (rev 2831) @@ -85,6 +85,8 @@ int sepol_set_policydb_from_file(FILE * fp) { struct policy_file pf; + + policy_file_init(&pf); pf.fp = fp; pf.type = PF_USE_STDIO; if (mypolicydb.policy_type) @@ -1003,13 +1005,14 @@ convert_context_args_t args; uint32_t seqno; int rc = 0; - struct policy_file file = { - .type = PF_USE_MEMORY, - .data = data, - .len = len, - .fp = NULL - }, *fp = &file; + struct policy_file file, *fp; + policy_file_init(&file); + file.type = PF_USE_MEMORY; + file.data = data; + file.len = len; + fp = &file; + if (policydb_init(&newpolicydb)) return -ENOMEM; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |