Merge pull request #4370 from felixjendrusch/objc-output-stream-write-check

Objective-C: Check return value on write of raw pointer
pull/4366/merge
Thomas Van Lenten 7 years ago committed by GitHub
commit aae10ed36d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      objectivec/GPBCodedOutputStream.m
  2. 10
      objectivec/Tests/GPBCodedOuputStreamTests.m

@ -942,7 +942,10 @@ static void GPBWriteRawLittleEndian64(GPBOutputBufferState *state,
state_.position = length;
} else {
// Write is very big. Let's do it all at once.
[state_.output write:((uint8_t *)value) + offset maxLength:length];
NSInteger written = [state_.output write:((uint8_t *)value) + offset maxLength:length];
if (written != (NSInteger)length) {
[NSException raise:GPBCodedOutputStreamException_WriteFailed format:@""];
}
}
}
}

@ -423,4 +423,14 @@
}
}
- (void)testThatItThrowsWhenWriteRawPtrFails {
NSOutputStream *output = [NSOutputStream outputStreamToMemory];
GPBCodedOutputStream *codedOutput =
[GPBCodedOutputStream streamWithOutputStream:output bufferSize:0]; // Skip buffering.
[output close]; // Close the output stream to force failure on write.
const char *cString = "raw";
XCTAssertThrowsSpecificNamed([codedOutput writeRawPtr:cString offset:0 length:strlen(cString)],
NSException, GPBCodedOutputStreamException_WriteFailed);
}
@end

Loading…
Cancel
Save