pt_util: Dynamically allocate page buffer

Since introduced in commit 53986479ee (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 <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
This commit is contained in:
Mark Vitale 2023-03-17 16:57:33 +00:00 committed by Michael Meffie
parent 03f9b08e90
commit 094066b485

View File

@ -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);
}