Module Name: othersrc
Committed By: agc
Date: Fri Feb 17 02:11:18 UTC 2012
Modified Files:
othersrc/crypto/external/bsd/ssss/dist/src/libssss: threshold.c
Log Message:
don't rely on an application (such as ssss(1)) being able to mmap(2) the
shares it presents via libssss - allocate space using calloc(3) if the mmap
fails.
this change allows us to use ssss(1) to combine shares from different
websites, mounted using httpdev(8).
To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 \
othersrc/crypto/external/bsd/ssss/dist/src/libssss/threshold.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: othersrc/crypto/external/bsd/ssss/dist/src/libssss/threshold.c
diff -u othersrc/crypto/external/bsd/ssss/dist/src/libssss/threshold.c:1.1.1.1 othersrc/crypto/external/bsd/ssss/dist/src/libssss/threshold.c:1.2
--- othersrc/crypto/external/bsd/ssss/dist/src/libssss/threshold.c:1.1.1.1 Mon Mar 21 05:43:35 2011
+++ othersrc/crypto/external/bsd/ssss/dist/src/libssss/threshold.c Fri Feb 17 02:11:18 2012
@@ -85,6 +85,21 @@ swapheader(thresh_head_t *head)
head->size = (*(char *)(void *)&indian) ? head->size : (uint64_t)BSWAP64(head->size);
}
+/* allocate space from heap */
+static int
+allocate(thresh_str_t *share, const void *data, size_t size)
+{
+ if ((share->io.base = calloc(1, size)) == NULL) {
+ (void) fprintf(stderr, "allocate: can't calloc %zu\n", size);
+ return 0;
+ }
+ if (data) {
+ (void) memcpy(share->io.base, data, size);
+ }
+ share->io.size = size;
+ return 1;
+}
+
/**************************************************************************/
/* check we have a sane header */
@@ -134,6 +149,8 @@ ssss_add_share(threshold_t *thresh, unsi
{
thresh_str_t *share;
struct stat st;
+ ssize_t rc;
+ ssize_t cc;
FILE *fp;
if (n != THRESH_MAX_SHARES) {
@@ -149,19 +166,23 @@ ssss_add_share(threshold_t *thresh, unsi
share->io.size = (size_t)st.st_size;
share->io.base = mmap(NULL, share->io.size, PROT_READ, MAP_PRIVATE, fileno(fp), 0);
if (share->io.base == MAP_FAILED) {
- (void) fprintf(stderr, "ida_add_share: can't mmap file '%s'\n", (const char *)data);
- (void) fclose(fp);
- return 0;
+ if (!allocate(share, NULL, (size_t)st.st_size)) {
+ return 0;
+ }
+ for (cc = 0 ; cc < st.st_size ; cc += rc) {
+ if ((rc = read(fileno(fp), &share->io.base[cc], st.st_size - cc)) < 0) {
+ break;
+ }
+ }
+ thresh->mapped[n] = ALLOCATED;
+ } else {
+ thresh->mapped[n] = MMAPPED;
}
- thresh->mapped[n] = MMAPPED;
+ (void) fclose(fp);
} else {
- if ((share->io.base = calloc(1, (size_t)size)) == NULL) {
- (void) fprintf(stderr, "ida_add_share: can't calloc %zu\n",
- (size_t)size);
+ if (!allocate(share, data, size)) {
return 0;
}
- (void) memcpy(share->io.base, data, (size_t)size);
- share->io.size = (size_t)size;
thresh->mapped[n] = ALLOCATED;
}
return 1;