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

maint(gpg2john.c): add missing prototypes #5603

Open
wants to merge 1 commit into
base: bleeding-jumbo
Choose a base branch
from

Conversation

claudioandre-br
Copy link
Member

The clang compiler was complaining with the error message: "Passing arguments to a function without a prototype is deprecated in all versions of C".


It looks correct to me, so I'm sending it.

@claudioandre-br
Copy link
Member Author

bots are happy!

@magnumripper
Copy link
Member

That's great! I'll have to let @solardiz approve it though, because I really don't understand any of it 😆

Copy link
Member

@solardiz solardiz left a comment

Choose a reason for hiding this comment

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

I made review comments about implementation detail of your approach, but I also question the whole approach.

It'd be simpler to cast the two different-prototype function addresses to (funcptr) in the initializer and then cast them to the right function pointer type in the two calls. A drawback is we wouldn't let the compiler check that we use the right type for those functions there - we'd take responsibility that we do.

src/gpg2john.c Outdated
@@ -1295,7 +1295,7 @@ TAG[] = {
#define TAG_NUM (sizeof(TAG) * sizeof(string))

private void
(*tag_func[])() = {
(*tag_func[])(int) = {
Copy link
Member

Choose a reason for hiding this comment

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

Could use the funcptr type here.

src/gpg2john.c Outdated
@@ -1629,7 +1697,7 @@ parse_packet(char *hash)
if (tag < TAG_NUM && tag_func[tag] != NULL) {
if (gpg_dbg)
fprintf(stderr, "Packet type %d, len %d at offset %d (Processing) (pkt-type %s) (Partial %s)\n", tag, len, offset, pkt_type(tag), partial?"yes":"no");
(*tag_func[tag])(len, 1, partial, hash); // first packet (possibly only one if partial is false).
(*tag_func1[tag])(len, 1, partial, hash); // first packet (possibly only one if partial is false).
Copy link
Member

Choose a reason for hiding this comment

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

We're now calling through a tag_func1 element, but the NULL check above remained of tag_func - that's probably wrong now.

src/gpg2john.c Outdated
@@ -1651,7 +1719,7 @@ parse_packet(char *hash)
if (tag < TAG_NUM && tag_func[tag] != NULL) {
if (gpg_dbg)
fprintf(stderr, "Packet type %d, len %d at offset %d (Processing) (pkt-type %s) (Partial %s)\n", tag, len, offset, pkt_type(tag), partial?"yes":"no");
(*tag_func[tag])(len, 0, partial, hash); // subsquent packets.
(*tag_func1[tag])(len, 0, partial, hash); // subsquent packets.
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

@claudioandre-br
Copy link
Member Author

tag_func is always called using the 4 parameters. Therefore, only the new tag_func1 is needed (it seems).

@magnumripper
Copy link
Member

It would be nice IMHO if you reference #5268 if you force-push again. Better traceability when trying to understand historical changes two years from now.

@claudioandre-br claudioandre-br force-pushed the fix/clang branch 2 times, most recently from 4289de9 to 0b01ba0 Compare December 3, 2024 09:52
@claudioandre-br
Copy link
Member Author

tag_func is always called using the 4 parameters. Therefore, only the new tag_func1 is needed (it seems).

No. Let's rephrase it: it calls some functions that expect only one parameter, but it passes 4 parameters.

@claudioandre-br
Copy link
Member Author

claudioandre-br commented Dec 3, 2024

Testing now (from john-samples):

Committed code:

john-the-ripper.gpg2john GPG/test.utf8.asc > 1.hash
john-the-ripper.gpg2john GPG/gpg-70_flavors/*.sec >> 1.hash
cat 1.hash | LANG=C sort > old.hash

PR:

../run/gpg2john GPG/test.utf8.asc > 2.hash
../run/gpg2john GPG/gpg-70_flavors/*.sec >> 2.hash
cat 2.hash | LANG=C sort > pr.hash
diff old.hash pr.hash

@claudioandre-br
Copy link
Member Author

Both versions are producing the same result (see the tests above).

if (tag_func[tag] != NULL)
(*tag_func[tag])(len);
else
(*tag_func4[tag])(len, 1, partial, hash); // first packet (possibly only one if partial is false).
Copy link
Member Author

Choose a reason for hiding this comment

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

None of the john-samples examples are calling this else part. Anyway, the call to the method is correct.

if (tag_func[tag] != NULL)
(*tag_func[tag])(len);
else
(*tag_func4[tag])(len, 0, partial, hash); // subsquent packets.
Copy link
Member Author

Choose a reason for hiding this comment

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

Idem.

The clang compiler was complaining with the error message: "Passing
arguments to a function without a prototype is deprecated in all
versions of C".

Fix: openwall#5268.

Signed-off-by: Claudio André <[email protected]>
@claudioandre-br
Copy link
Member Author

I created a file to use the symmetric "stuff":

$ gpg -a --symmetric --cipher-algo AES256 old.hash 

$ ../run/gpg2john old.hash.asc

This first “else” was executed once. The second was called 6 times. The same output was produced and it is crackable.

Copy link
Member

@solardiz solardiz left a comment

Choose a reason for hiding this comment

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

Let's figure out the discrepancy in pointer placement/counts.

NULL,
NULL,
NULL,
Symmetrically_Encrypted_and_MDC_Packet,
Copy link
Member

Choose a reason for hiding this comment

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

The functions removed from the old/first array are separated by 8 other pointers, but here they're separated by only 7 NULLs. A bug?

Separately (but maybe related), I notice that the old array initializer had 65 lines, whereas the tag mask is such that there should probably be only 64 - a bug? Harmless?

Copy link
Member

Choose a reason for hiding this comment

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

The first commit (f4df772) of gpg2john had that non-multiple of 4. Jim added a second typedef in 2fee9ee for #477.

@solardiz
Copy link
Member

solardiz commented Dec 4, 2024

This first “else” was executed once. The second was called 6 times. The same output was produced and it is crackable.

That's cool. No idea how it's possible if I counted the pointers between the two 4-argument functions right. Was the code buggy prior to your changes? Did gpg2john produce the same or different output before this PR's changes?

Anyhow, please add your new test input to the john-samples repo. Thank you!

@claudioandre-br
Copy link
Member Author

I'll push (soon) it again to see if anything is missing!

@solardiz
Copy link
Member

solardiz commented Dec 5, 2024

@claudioandre-br I see you've inserted the missing NULL now. However, that this bug went unnoticed means we have no test case for this functionality (the function that was presumably at the wrong index before this NULL addition), right?

@claudioandre-br
Copy link
Member Author

My local version has been tested ('íf' and 'else'). But let's keep this waiting until i can test it again.

There weren't supposed to be two different versions.

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.

3 participants