-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed SIGSEGV, fixed heap buffer overflow, heap use after free #6925
Conversation
libr/util/r_asn1.c
Outdated
@@ -386,16 +392,14 @@ ut32 r_asn1_count_objects (const ut8 *buffer, ut32 length) { | |||
while (next >= buffer && next < end) { | |||
object = asn1_parse_header (next, end - next); | |||
if (!object || next == object->sector) { | |||
// if (object->tag != TAG_NULL) | |||
if (object) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is not need to check if (object) free, free already takes care of that
libr/util/r_asn1.c
Outdated
inner = r_asn1_create_object (next, end - next); | ||
if (!inner || next == inner->sector) { | ||
//if(inner->tag != TAG_NULL) | ||
if (inner) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
Create a PR in r2r uploading all those files |
i'll merge after having those changes fixed. thanks |
what changes? |
libr/util/r_asn1.c
Outdated
@@ -311,14 +325,11 @@ RASN1Object *asn1_parse_header (const ut8 *buffer, ut32 length) { | |||
if (!object) { | |||
return NULL; | |||
} | |||
memset (object, 0, sizeof(RASN1Object)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing soace before (
libr/util/r_asn1.c
Outdated
@@ -63,8 +76,9 @@ RASN1String *r_asn1_stringify_string (const ut8 *buffer, ut32 length) { | |||
return NULL; | |||
} | |||
memcpy (str, buffer, length); | |||
sanitize(str, length + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anither missing soace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean space
libr/util/r_x509.c
Outdated
@@ -165,8 +172,7 @@ bool r_x509_parse_extensions (RX509Extensions *ext, RASN1Object * object) { | |||
for (i = 0; i < object->list.length; ++i) { | |||
ext->extensions[i] = (RX509Extension*) malloc (sizeof (RX509Extension)); | |||
if (!r_x509_parse_extension (ext->extensions[i], object->list.objects[i])) { | |||
free (ext->extensions[i]); | |||
ext->extensions[i] = NULL; | |||
R_FREE(ext->extensions[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space
libr/util/r_asn1.c
Outdated
} | ||
char* e = s; | ||
while (s <= (e + len)) { | ||
if(*s < 0x20 || *s > 0x7E) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theres a function in rutil that does this already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually no. i've checked, and no code does ASCII only.
if yes, i'll be happy to remove it.
@@ -311,14 +325,11 @@ RASN1Object *asn1_parse_header (const ut8 *buffer, ut32 length) { | |||
if (!object) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use R_NEW0 instead of malloc and remove the memset
libr/util/r_pkcs7.c
Outdated
length = 2048 + (container->signedData.certificates.length * 1024); | ||
if(!length) return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space and missing braces
libr/util/r_pkcs7.c
Outdated
length = 2048 + (container->signedData.certificates.length * 1024); | ||
if(!length) return NULL; | ||
buffer = (char*) malloc (length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use calloc and remove the memset
libr/util/r_x509.c
Outdated
@@ -6,6 +6,9 @@ | |||
|
|||
#include "r_x509_internal.h" | |||
|
|||
#define MOVE_PTR(dst, src) ((dst) = (src)); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong spacing and indentation
this is if (IS_PRINTABLE(*s))
… On 07 Mar 2017, at 20:39, Giovanni ***@***.***> wrote:
@wargio commented on this pull request.
In libr/util/r_asn1.c <#6925 (comment)>:
> @@ -10,6 +10,19 @@
const char* _hex = "0123456789abcdef";
+static char* sanitize(char *s, ut32 len) {
+ if (!s) {
+ return NULL;
+ }
+ char* e = s;
+ while (s <= (e + len)) {
+ if(*s < 0x20 || *s > 0x7E)
actually no. i've checked, and no code does ASCII only.
if yes, i'll be happy to remove it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#6925 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AA3-llY9nklwNBB2A97EtxRu02fKOwGOks5rjbJ7gaJpZM4MToc7>.
|
Do not merge still it crash
|
This fix the crash, update it please. remove the gotcha message with eprintf and fix it correctly please
|
FINALLY fixed. @alvarofe can you check the crash again? thanks! |
i hope to have fixed all frees now :| |
btw, passing the pointers as references seems like an anti-pattern compared to the rest of the code in r2. i would prefer not to change that. |
is responsability of the caller to nullify the pointer if that's going to be used later to avoid an UAF |
i can merge that because i think that fixing those segfaults is important, but i would prefer not to have ** pointers and the extra dereference needed for every access |
Ok, I'll change it later |
ok merged for now, please send another PR rollbacking the ** |
Fixed bugs (#6908 #6909 #6911)
Here is the list of the binaries tested: