Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Fixes #413: API for getting bucket and file by name #414

Merged
merged 5 commits into from
Jan 23, 2018

Conversation

kaloyan-raev
Copy link
Contributor

No description provided.

@kaloyan-raev
Copy link
Contributor Author

@aleitner @braydonf please review when you have time.

src/utils.c Outdated

// count the number of replacements needed
ins = subject;
for (count = 0; tmp = strstr(ins, search); ++count) {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this break when tmp == NULL?

Copy link
Contributor

Choose a reason for hiding this comment

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

utils.c:104:25: warning: using the result of an assignment as a condition
      without parentheses [-Wparentheses]
    for (count = 0; tmp = strstr(ins, search); ++count) {
                    ~~~~^~~~~~~~~~~~~~~~~~~~~
utils.c:104:25: note: place parentheses around the assignment to silence this
      warning
    for (count = 0; tmp = strstr(ins, search); ++count) {
                        ^
                    (                        )
utils.c:104:25: note: use '==' to turn this assignment into an equality
      comparison
    for (count = 0; tmp = strstr(ins, search); ++count) {
                        ^
                        ==
1 warning generated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It breaks on tmp == NULL. I can rework this line to avoid the compiler warning.

@aleitner
Copy link
Contributor

update to handle variable freeing and returns with goto like other places in library. https://github.com/Storj/libstorj/blob/master/src/crypto.c#L134

@kaloyan-raev
Copy link
Contributor Author

Do you mean in the get_bucket_id_request_worker()? I copied this logic from the existing create_bucket_request_worker() and followed the same style: https://github.com/Storj/libstorj/blob/master/src/storj.c#L32-L35

src/storj.c Outdated
return;
}

free(bucket_key_as_str);
Copy link
Contributor

Choose a reason for hiding this comment

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

this variable never gets freed when returning on line 259. handle frees and return using goto at end of function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I see it now. However, the same issues exists on many other places in the code.
I would suggest to move the code for generating the bucket key in a separate function that handles the memory correctly and replace it all over. Rather than polluting the code with gotos. Sounds good?

Copy link
Contributor

Choose a reason for hiding this comment

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

we've been using gotos across the entire library. You could just put variables you need access to outside on the heap and the rest on the stack. I don't exactly understand what you are saying. maybe show me an example of what you mean

Copy link
Contributor Author

@kaloyan-raev
Copy link
Contributor Author

@aleitner The latest commit 72c443e to this PR extracts all the duplicated code to separate function for encrypting and decrypting bucket/file names. These new functions free and clear the memory as you suggested. This way the problem is fixed in all places.

@aleitner
Copy link
Contributor

Looks awesome to me. Tests passed on my local machine. No compiler warnings

src/storj.c Outdated
return;
}

free(escaped_encrypted_file_name);
Copy link
Contributor

Choose a reason for hiding this comment

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

This may not get freed, could use goto with cleanup label

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed 5c40693 that does this.

@@ -80,6 +80,54 @@ char *str_concat_many(int count, ...)
return combined;
}

char *str_replace(char *search, char *replace, char *subject) {
Copy link
Contributor

Choose a reason for hiding this comment

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

a few unit tests around this could be useful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just added a unit test - see the latest commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool

@braydonf
Copy link
Contributor

So far looks good to me. Ran valgrind on it and didn't see any issues that are not already on the master branch.

@braydonf braydonf merged commit 23d5c55 into storj-archived:master Jan 23, 2018
@kaloyan-raev kaloyan-raev deleted the get-file-id branch January 25, 2018 15:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants