aboutsummaryrefslogtreecommitdiff
path: root/src/or/rendclient.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-09-17 09:52:43 -0400
committerNick Mathewson <nickm@torproject.org>2012-09-17 10:28:14 -0400
commit96d2a21683cdfe25b549e13fa450d4b12fb945b2 (patch)
tree64fe4f8b4d134fb9c607754463946dc74606ad4d /src/or/rendclient.c
parent2939cc3ba3afe5ef2c6a273eef18577274e6867b (diff)
downloadtor-96d2a21683cdfe25b549e13fa450d4b12fb945b2.tar.gz
tor-96d2a21683cdfe25b549e13fa450d4b12fb945b2.zip
Avoid sign-extending when computing rend auth type.
Right-shifting negative values has implementation-defined behavior. On all the platforms we work on right now, the behavior is to sign-extend the input. That isn't what we wanted in auth_type_val = (descriptor_cookie_tmp[16] >> 4) + 1; Fix for 6861; bugfix on 0.2.1.5-alpha; reported pseudonymously. The broken behavior didn't actually hurt anything, I think, since the only way to get sign-extension to happen would be to have the top bit of descriptor_cookie_tmp[16] set, which would make the value of descriptor_cookie_tmp[16] >> 4 somewhere between 0b11111111 and 0b11111000 (that is, between -1 and -8). So auth_type_val would be between -7 and 0. And the immediate next line does: if (auth_type_val < 1 || auth_type_val > 2) { So the incorrectly computed auth_type_val would be rejected as invalid, just as a correctly computed auth_type_val would be. Still, this stuff shouldn't sit around the codebase.
Diffstat (limited to 'src/or/rendclient.c')
-rw-r--r--src/or/rendclient.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/or/rendclient.c b/src/or/rendclient.c
index 73e1c41d7b..2104a5b3d4 100644
--- a/src/or/rendclient.c
+++ b/src/or/rendclient.c
@@ -1250,7 +1250,7 @@ rend_parse_service_authorization(const or_options_t *options,
descriptor_cookie);
goto err;
}
- auth_type_val = (descriptor_cookie_tmp[16] >> 4) + 1;
+ auth_type_val = (((uint8_t)descriptor_cookie_tmp[16]) >> 4) + 1;
if (auth_type_val < 1 || auth_type_val > 2) {
log_warn(LD_CONFIG, "Authorization cookie has unknown authorization "
"type encoded.");