From 094066b485d424e8eac17ea8a104ed0959b74896 Mon Sep 17 00:00:00 2001 From: Mark Vitale Date: Fri, 17 Mar 2023 16:57:33 +0000 Subject: [PATCH] pt_util: Dynamically allocate page buffer Since introduced in commit 53986479ee1e (ptutil-initial-20001219), pt_util has used a statically allocated buffer to read pages from the database. In several places the buffer is cast to a struct ubik_header. Memory allocated dynamically via malloc()/calloc() is guaranteed to be properly aligned for objects of any type at run time, however buffers that are not allocated dynamically have no such guarantee. So, instead of using a statically allocated buffer, dynamically allocate it with calloc() to ensure it is aligned for struct ubik_header objects. This fixes a SIGBUS error whenever the buffer happens to be built with a non-word alignment. This failure was observed while running the tests/ptserver/pt_util-t unit test on Solaris SPARC 64-bit. Note: By inspection, the same potential problem exists in src/kauth/ka_util.c. However, kaserver is deprecated and ka_util has never been built by default. Change-Id: I00372ed6adede32448b5e0df1c1d74689286a218 Reviewed-on: https://gerrit.openafs.org/15352 Tested-by: BuildBot Reviewed-by: Cheyenne Wills Reviewed-by: Mark Vitale Reviewed-by: Michael Meffie --- src/ptserver/pt_util.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ptserver/pt_util.c b/src/ptserver/pt_util.c index 00b7deae6a..095a25a819 100644 --- a/src/ptserver/pt_util.c +++ b/src/ptserver/pt_util.c @@ -84,7 +84,7 @@ struct usr_list { }; static struct usr_list *usr_head = 0; -char buffer[1024]; +char *buffer = NULL; int dbase_fd; FILE *dfp; @@ -178,6 +178,8 @@ CommandProc(struct cmd_syndesc *a_as, void *arock) dfile = tparm[8].items->data; } + buffer = calloc(1, UBIK_PAGESIZE); + if (pfile == NULL) { snprintf(pbuffer, sizeof(pbuffer), "%s.DB0", pbase); pfile = pbuffer; @@ -238,7 +240,7 @@ CommandProc(struct cmd_syndesc *a_as, void *arock) struct usr_list *u; int seenGroup = 0, id = 0, flags = 0; - while (fgets(buffer, sizeof(buffer), dfp)) { + while (fgets(buffer, UBIK_PAGESIZE, dfp)) { int oid, cid, quota, uid; char name[PR_MAXNAMELEN], mem[PR_MAXNAMELEN]; @@ -387,6 +389,7 @@ CommandProc(struct cmd_syndesc *a_as, void *arock) uv.epoch, uv.counter, uh->version.epoch, uh->version.counter); } close(dbase_fd); + free(buffer); exit(0); }