ObjFW  Diff

Differences From Artifact [0957d5a6c1]:

To Artifact [42fad2fbd2]:

  • File src/OFSOCKS5Socket.m — part of check-in [e1e7ffa903] at 2011-09-22 23:25:42 on branch trunk — Exceptions are now autoreleased.

    This is safe as an "exception loop" can't happen, since if allocating
    an exception fails, it throws an OFAllocFailedException which is
    preallocated and can always be thrown.

    So, the worst case would be that an autorelease of an exception fails,
    triggering an OFOutOfMemoryException for which there is no memory,
    resulting in an OFAllocFailedException to be thrown. (user: js, size: 3100) [annotate] [blame] [check-ins using]


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
					   port: port] autorelease];
}

- init
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException newWithClass: c
					      selector: _cmd];
}

- initWithProxyHost: (OFString*)host
	       port: (uint16_t)port
{
	self = [super init];








|
|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
					   port: port] autorelease];
}

- init
{
	Class c = isa;
	[self release];
	@throw [OFNotImplementedException exceptionWithClass: c
						    selector: _cmd];
}

- initWithProxyHost: (OFString*)host
	       port: (uint16_t)port
{
	self = [super init];

75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
	       fromBuffer: request];

	[self readExactlyNBytes: 2
		     intoBuffer: reply];

	if (reply[0] != 5 || reply[1] != 0) {
		[self close];
		@throw [OFConnectionFailedException newWithClass: isa

							  socket: self
							    host: proxyHost
							    port: proxyPort];
	}

	oldBuffersWrites = [self buffersWrites];
	[self setBuffersWrites: YES];

	/* CONNECT request */
	[self writeNBytes: 4







|
>
|
|
|







75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
	       fromBuffer: request];

	[self readExactlyNBytes: 2
		     intoBuffer: reply];

	if (reply[0] != 5 || reply[1] != 0) {
		[self close];
		@throw [OFConnectionFailedException
		    exceptionWithClass: isa
				socket: self
				  host: proxyHost
				  port: proxyPort];
	}

	oldBuffersWrites = [self buffersWrites];
	[self setBuffersWrites: YES];

	/* CONNECT request */
	[self writeNBytes: 4
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
	[self setBuffersWrites: oldBuffersWrites];

	[self readExactlyNBytes: 4
		     intoBuffer: reply];

	if (reply[0] != 5 || reply[1] != 0 || reply[2] != 0) {
		[self close];
		@throw [OFConnectionFailedException newWithClass: isa
							  socket: self
							    host: host
							    port: port];
	}

	/* Skip the rest of the reply */
	switch (reply[3]) {
	case 1: /* IPv4 */
		[self readExactlyNBytes: 4
			     intoBuffer: reply];
		break;
	case 3: /* Domainname */
		[self readExactlyNBytes: [self readInt8]
			     intoBuffer: reply];
		break;
	case 4: /* IPv6 */
		[self readExactlyNBytes: 16
			     intoBuffer: reply];
		break;
	default:
		[self close];
		@throw [OFConnectionFailedException newWithClass: isa
							  socket: self
							    host: host
							    port: port];
	}

	[self readBigEndianInt16];
}
@end







|
|
|
|


















|
|
|
|





104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
	[self setBuffersWrites: oldBuffersWrites];

	[self readExactlyNBytes: 4
		     intoBuffer: reply];

	if (reply[0] != 5 || reply[1] != 0 || reply[2] != 0) {
		[self close];
		@throw [OFConnectionFailedException exceptionWithClass: isa
								socket: self
								  host: host
								  port: port];
	}

	/* Skip the rest of the reply */
	switch (reply[3]) {
	case 1: /* IPv4 */
		[self readExactlyNBytes: 4
			     intoBuffer: reply];
		break;
	case 3: /* Domainname */
		[self readExactlyNBytes: [self readInt8]
			     intoBuffer: reply];
		break;
	case 4: /* IPv6 */
		[self readExactlyNBytes: 16
			     intoBuffer: reply];
		break;
	default:
		[self close];
		@throw [OFConnectionFailedException exceptionWithClass: isa
								socket: self
								  host: host
								  port: port];
	}

	[self readBigEndianInt16];
}
@end