Fix memory overwrite in proto decding; fix test for windows

pull/6774/head
Alistair Veitch 9 years ago
parent 2ea5e3d396
commit 8c7618e88d
  1. 6
      src/core/ext/census/resource.c
  2. 4
      test/core/census/resource_test.c

@ -156,9 +156,11 @@ static bool validate_units_helper(pb_istream_t *stream, int *count,
gpr_free(*bup);
}
*bup = new_bup;
if (!pb_decode_varint(stream, (uint64_t *)(*bup + *count - 1))) {
uint64_t value;
if (!pb_decode_varint(stream, &value)) {
return false;
}
*(*bup + *count - 1) = (google_census_Resource_BasicUnit)value;
}
return true;
}
@ -290,7 +292,7 @@ int32_t define_resource(const resource *base) {
resources[id]->name = gpr_malloc(len);
memcpy(resources[id]->name, base->name, len);
if (base->description) {
len = strlen(base->description);
len = strlen(base->description) + 1;
resources[id]->description = gpr_malloc(len);
memcpy(resources[id]->description, base->description, len);
}

@ -66,10 +66,10 @@ static void test_empty_definition() {
static int32_t define_resource_from_file(const char *file) {
#define BUF_SIZE 512
uint8_t buffer[BUF_SIZE];
FILE *input = fopen(file, "r");
FILE *input = fopen(file, "rb");
GPR_ASSERT(input != NULL);
size_t nbytes = fread(buffer, 1, BUF_SIZE, input);
GPR_ASSERT(nbytes != 0 && nbytes < BUF_SIZE);
GPR_ASSERT(nbytes != 0 && nbytes < BUF_SIZE && feof(input) && !ferror(input));
int32_t rid = census_define_resource(buffer, nbytes);
GPR_ASSERT(fclose(input) == 0);
return rid;

Loading…
Cancel
Save