ObjFW  Diff

Differences From Artifact [d011dc479a]:

  • File src/OFStream.m — part of check-in [535c2d5d9b] at 2011-09-19 16:22:23 on branch trunk — Make using -[tryReadLine] + OFStreamObserver safe.

    This makes it impossible for the developer to accidentally create a DoS.
    When data has been received after calling -[tryReadLine] and the string
    is still incomplete, -[streamIsReadyForReading:] will not be called
    anymore until new data has been received, thus preventing spinning in a
    loop. (user: js, size: 26698) [annotate] [blame] [check-ins using]

To Artifact [b36f920107]:


438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
				andNItems: (size_t)nItems
{
	OFDataArray *da;
	char *tmp;

	da = [OFDataArray dataArrayWithItemSize: itemSize];
	tmp = [self allocMemoryForNItems: nItems
				withSize: itemSize];

	@try {
		[self readExactlyNBytes: nItems * itemSize
			     intoBuffer: tmp];

		[da addNItems: nItems
		   fromCArray: tmp];







|







438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
				andNItems: (size_t)nItems
{
	OFDataArray *da;
	char *tmp;

	da = [OFDataArray dataArrayWithItemSize: itemSize];
	tmp = [self allocMemoryForNItems: nItems
				  ofSize: itemSize];

	@try {
		[self readExactlyNBytes: nItems * itemSize
			     intoBuffer: tmp];

		[da addNItems: nItems
		   fromCArray: tmp];
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
#ifdef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint16_t *tmp;

	tmp = [self allocMemoryForNItems: nInt16s
				withSize: sizeof(uint16_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt16s; i++)
			tmp[i] = of_bswap16(buffer[i]);








|







935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
#ifdef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint16_t *tmp;

	tmp = [self allocMemoryForNItems: nInt16s
				  ofSize: sizeof(uint16_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt16s; i++)
			tmp[i] = of_bswap16(buffer[i]);

965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
#ifdef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint32_t *tmp;

	tmp = [self allocMemoryForNItems: nInt32s
				withSize: sizeof(uint32_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt32s; i++)
			tmp[i] = of_bswap32(buffer[i]);








|







965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
#ifdef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint32_t *tmp;

	tmp = [self allocMemoryForNItems: nInt32s
				  ofSize: sizeof(uint32_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt32s; i++)
			tmp[i] = of_bswap32(buffer[i]);

995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
#ifdef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint64_t *tmp;

	tmp = [self allocMemoryForNItems: nInt64s
				withSize: sizeof(uint64_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt64s; i++)
			tmp[i] = of_bswap64(buffer[i]);








|







995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
#ifdef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint64_t *tmp;

	tmp = [self allocMemoryForNItems: nInt64s
				  ofSize: sizeof(uint64_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt64s; i++)
			tmp[i] = of_bswap64(buffer[i]);

1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
#ifdef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	float *tmp;

	tmp = [self allocMemoryForNItems: nFloats
				withSize: sizeof(float)];

	@try {
		size_t i;

		for (i = 0; i < nFloats; i++)
			tmp[i] = of_bswap_float(buffer[i]);








|







1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
#ifdef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	float *tmp;

	tmp = [self allocMemoryForNItems: nFloats
				  ofSize: sizeof(float)];

	@try {
		size_t i;

		for (i = 0; i < nFloats; i++)
			tmp[i] = of_bswap_float(buffer[i]);

1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
#ifdef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	double *tmp;

	tmp = [self allocMemoryForNItems: nDoubles
				withSize: sizeof(double)];

	@try {
		size_t i;

		for (i = 0; i < nDoubles; i++)
			tmp[i] = of_bswap_double(buffer[i]);








|







1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
#ifdef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	double *tmp;

	tmp = [self allocMemoryForNItems: nDoubles
				  ofSize: sizeof(double)];

	@try {
		size_t i;

		for (i = 0; i < nDoubles; i++)
			tmp[i] = of_bswap_double(buffer[i]);

1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
#ifndef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint16_t *tmp;

	tmp = [self allocMemoryForNItems: nInt16s
				withSize: sizeof(uint16_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt16s; i++)
			tmp[i] = of_bswap16(buffer[i]);








|







1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
#ifndef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint16_t *tmp;

	tmp = [self allocMemoryForNItems: nInt16s
				  ofSize: sizeof(uint16_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt16s; i++)
			tmp[i] = of_bswap16(buffer[i]);

1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
#ifndef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint32_t *tmp;

	tmp = [self allocMemoryForNItems: nInt32s
				withSize: sizeof(uint32_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt32s; i++)
			tmp[i] = of_bswap32(buffer[i]);








|







1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
#ifndef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint32_t *tmp;

	tmp = [self allocMemoryForNItems: nInt32s
				  ofSize: sizeof(uint32_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt32s; i++)
			tmp[i] = of_bswap32(buffer[i]);

1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
#ifndef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint64_t *tmp;

	tmp = [self allocMemoryForNItems: nInt64s
				withSize: sizeof(uint64_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt64s; i++)
			tmp[i] = of_bswap64(buffer[i]);








|







1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
#ifndef OF_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	uint64_t *tmp;

	tmp = [self allocMemoryForNItems: nInt64s
				  ofSize: sizeof(uint64_t)];

	@try {
		size_t i;

		for (i = 0; i < nInt64s; i++)
			tmp[i] = of_bswap64(buffer[i]);

1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
#ifndef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	float *tmp;

	tmp = [self allocMemoryForNItems: nFloats
				withSize: sizeof(float)];

	@try {
		size_t i;

		for (i = 0; i < nFloats; i++)
			tmp[i] = of_bswap_float(buffer[i]);








|







1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
#ifndef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	float *tmp;

	tmp = [self allocMemoryForNItems: nFloats
				  ofSize: sizeof(float)];

	@try {
		size_t i;

		for (i = 0; i < nFloats; i++)
			tmp[i] = of_bswap_float(buffer[i]);

1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
#ifndef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	double *tmp;

	tmp = [self allocMemoryForNItems: nDoubles
				withSize: sizeof(double)];

	@try {
		size_t i;

		for (i = 0; i < nDoubles; i++)
			tmp[i] = of_bswap_double(buffer[i]);








|







1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
#ifndef OF_FLOAT_BIG_ENDIAN
	[self writeNBytes: size
	       fromBuffer: buffer];
#else
	double *tmp;

	tmp = [self allocMemoryForNItems: nDoubles
				  ofSize: sizeof(double)];

	@try {
		size_t i;

		for (i = 0; i < nDoubles; i++)
			tmp[i] = of_bswap_double(buffer[i]);