Skip to content

Commit

Permalink
Rename crypt_r to fix ASan false positive
Browse files Browse the repository at this point in the history
The ASan interceptor for CRYPT(3) ::crypt_r thinks we're doing something
naughty, but we have our own implementation. So to keep ASan from
intercepting this function, let's rename it.
  • Loading branch information
seven1m committed Dec 24, 2024
1 parent adb262b commit 857d5f3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/natalie/crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ char *crypt(const char *key, const char *setting);
void setkey(const char *key);
void encrypt(char *block, int flag);

char *crypt_r(const char *key, const char *setting, struct crypt_data *data);
char *crypt_r2(const char *key, const char *setting, struct crypt_data *data);
void setkey_r(const char *key, struct crypt_data *data);
void encrypt_r(char *block, int flag, struct crypt_data *data);

Expand Down
4 changes: 2 additions & 2 deletions src/crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ static struct crypt_data default_crypt_data;
*/
char *
crypt(const char *key, const char *setting) {
return crypt_r(key, setting, &default_crypt_data);
return crypt_r2(key, setting, &default_crypt_data);
}
#endif

Expand All @@ -1192,7 +1192,7 @@ crypt(const char *key, const char *setting) {
* encryption produced by the "key" and "setting".
*/
char *
crypt_r(const char *key, const char *setting, struct crypt_data *data) {
crypt_r2(const char *key, const char *setting, struct crypt_data *data) {
register char *encp;
register long i;
register int t;
Expand Down
2 changes: 1 addition & 1 deletion test/asan_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Dir[
'spec/language/*_spec.rb',
'test/natalie/**/*_test.rb',
'spec/core/string/crypt_spec.rb',
].to_a
else
# runs nightly -- all tests
Expand Down Expand Up @@ -53,7 +54,6 @@
'spec/core/process/uid_spec.rb', # not sure why this breaks
'spec/core/process/euid_spec.rb', # not sure why this breaks
'spec/core/process/egid_spec.rb', # not sure why this breaks
'spec/core/string/crypt_spec.rb', # heap buffer overflow in Natalie::StringObject::crypt
].freeze

describe 'ASAN tests' do
Expand Down

0 comments on commit 857d5f3

Please sign in to comment.