Skip to content
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

Mies suomesta fixes segfaults and logic errors #515

Closed
wants to merge 10 commits into from

Conversation

MiesSuomesta
Copy link

While debugging found some issues: Segfaults and made some securing actions.

@MiesSuomesta MiesSuomesta changed the title Mies suomesta patch 1 Mies suomesta fixes segfaults and logic errors Dec 19, 2019
Copy link
Member

@hawicz hawicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vast majority of this pull request is not something that I would merge, and I see only three potentially useful changes:

  • Additional of a test (thank you!)
  • In sprintbuf(), the use of the PRINTBUF_DEFAULT_SIZE define and sizeof() instead of hard-coded constants, though that needs to fix the off-by-one bug and drop use of "long".
  • Perhaps, the fix to the order of the arguments to calloc() in json_object_new()

@@ -467,6 +477,19 @@ struct lh_table* json_object_get_object(const struct json_object *jso)
}
}

static char *stringdup(const char *s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with strdup() ?

@@ -220,14 +220,16 @@ static void json_object_generic_delete(struct json_object* jso)
lh_table_delete(json_object_table, jso);
#endif /* REFCOUNT_DEBUG */
printbuf_free(jso->_pb);
jso->_pb = NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting local variables and memory about to be freed to NULL is useless, please don't do this.

r = "null";
}
else if ((jso->_pb) || (jso->_pb = printbuf_new()))
/* Failure case set first */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the point of this change. As far as I can tell, the overall logic is the same, but you've introduced an additional level of indentation, making the code slightly more complicated. Under what condition does the original code fail?

"\\u00%c%c",
json_hex_chars[c >> 4],
json_hex_chars[c & 0xf]);
"\\u00%c%c",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any functional change here.

existing_entry = (opts & JSON_C_OBJECT_ADD_KEY_IS_NEW) ? NULL :
lh_table_lookup_entry_w_hash(jso->o.c_object,
(const void *)key, hash);
existing_entry = (opts & JSON_C_OBJECT_ADD_KEY_IS_NEW) ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any functional change here.

@@ -142,14 +177,29 @@ int sprintbuf(struct printbuf *p, const char *msg, ...)

void printbuf_reset(struct printbuf *p)
{
p->buf[0] = '\0';
p->bpos = 0;
if (p != NULL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not valid to call this with a NULL. At most, this could be an assert(), but crashing is perfectly reasonable too.

}

void printbuf_free(struct printbuf *p)
{
if(p) {
free(p->buf);

if (p->buf != NULL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointless check, p->buf may never be NULL.

if (p->buf != NULL)
free(p->buf);

p->buf = NULL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with your changes in json_object_generic_delete, setting these to NULL is pointless.

printf("%s: end test\n", __func__);
}

#if 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the code isn't used, remove it.


int main(int argc, char **argv)
{
int before_resize = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This before_resize values doesn't seem to make any sense. Why would the behavior of test_sprintbuf() depend on code that is entirely local to test_printbuf_memappend()? Please remove this.

@MiesSuomesta
Copy link
Author

MiesSuomesta commented Dec 19, 2019 via email

@MiesSuomesta
Copy link
Author

Seems that this was some other problem with the system, rebooted PC and recompiled 0.13.99 master.. no hick ups at all.

@MiesSuomesta MiesSuomesta deleted the MiesSuomesta-patch-1 branch December 19, 2019 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants