Ask Your Question
0

Not able to compile packet-pkcs12-template.c

asked 2020-04-21 16:21:45 +0000

amit_wireshark gravatar image

updated 2020-04-21 16:59:06 +0000

grahamb gravatar image

Hello all,

I am new to wireshark development. I have been able to setup build environment on Cent OS7 and compile wireshark source.

But then I proceeded to make couple of changes in packet-pkcs12-template.c. I got a compile error. I fixed it but I still get the error. Changes to other dissectors like packet-xxx.c (non-asn1 generated) were compiled successfully. I then made random changes in this file to see if the compiler is really looking at the modified file. Surprisingly I do not get other errors I was expecting before the original error. I keep getting the same first error even after fixing it.

I wonder there is something that I don't know about modifying and compiling *-template.c files.

I am badly in need of help. Let me know if you need any details.

Thanks in advance.

[  7%] Built target dissectors-corba
[  7%] Building C object epan/dissectors/CMakeFiles/dissectors.dir/packet-pkcs12.c.o
./asn1/pkcs12/packet-pkcs12-template.c: In function 'PBE_decrypt_data':
./asn1/pkcs12/packet-pkcs12-template.c:344:2: error: passing argument 2 of 'tvb_new_child_real_data' discards 'const' qualifier from pointer target type [-Werror]
In file included from /root/wireshark/epan/proto.h:35:0,
                 from /root/wireshark/epan/packet.h:14,
                 from ./asn1/pkcs12/packet-pkcs12-template.c:18:
/root/wireshark/epan/tvbuff.h:150:25: note: expected 'guint8 *' but argument is of type 'const guint8 *'
 WS_DLL_PUBLIC tvbuff_t *tvb_new_child_real_data(tvbuff_t *parent,
                         ^
cc1: all warnings being treated as errors
make[2]: *** [epan/dissectors/CMakeFiles/dissectors.dir/packet-pkcs12.c.o] Error 1
make[1]: *** [epan/dissectors/CMakeFiles/dissectors.dir/all] Error 2
make: *** [all] Error 2

packet-pkcs12.c does not get generated as I see the old timestamp on this.

In packet-pkcs12-template.c, I make following change in PBE_decrypt_data() to get additional compile error:

*AKAKKSLD;
   clear_tvb = tvb_new_child_real_data(encrypted_tvb,(guint8AMIT *)clear_data, datalen, datalen);*

Originally I was trying to remove the const type casting for the 2nd parameter of the function call tvb_new_child_real_data, which I fixed in function definition/declaration etc. but I kept getting the above compile error. So I edited the file to introduce more error and I suspect that those errors are not even looked at by compiler.

I cloned the source from https://github.com/wireshark/wireshark.

edit retag flag offensive close merge delete

Comments

  • Where did you get your source, git clone or a tarball?
  • Does the generated file get, er generated, when you modify the template file?
  • Can you show us the error?
grahamb gravatar imagegrahamb ( 2020-04-21 16:29:15 +0000 )edit

Updated the original question with additional information requested.

amit_wireshark gravatar imageamit_wireshark ( 2020-04-21 16:53:01 +0000 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-04-21 17:11:51 +0000

grahamb gravatar image

A template file is compiled as it, think of it as a set of helper functions, modifying it won't regenerate the actual dissector file.

The function signature for tvb_new_child_real_data() requires a const guint8 *, hence the cast in the original code.

Presumably you've changed the type of clear_data, originally this is a char *, to whatever guint8AMIT is, but this will still need to either have an implicit type conversion to the required type, or you have to add an explicit cast.

edit flag offensive delete link more

Comments

I changed this line:

clear_tvb = tvb_new_child_real_data(encrypted_tvb,(const guint8 *)clear_data, datalen, datalen);

to:

clear_tvb = tvb_new_child_real_data(encrypted_tvb,(guint8 *)clear_data, datalen, datalen);

notice "const" from explicit type casting is removed.

I also modified tvb_new_child_real_data() definition and declaration to accept non-"const" pointer. But I still get the error at this same line in this file saying that 2nd argument to tvb_new_child_real_data() discards const qualifier. At this point I suspected if compiler was even looking at my modification, I made some other odd changes to get additional errors and compiler does not show those errors.

PATCH:
+++++++++++++++++++++++++
diff --git a/epan/dissectors/asn1/pkcs12/packet-pkcs12-template.c b/epan/dissectors/asn1/pkcs12/packet-pkcs12-template.c
index 271051e..3c8eedd 100644
--- a/epan/dissectors/asn1/pkcs12/packet-pkcs12-template.c
+++ b/epan/dissectors/asn1/pkcs12/packet-pkcs12-template.c
@@ -341,7 +341,9 @@ int PBE_decrypt_data(const char *object_identifier_id_param _U_, tvbuff_t *encry

        /* OK - so now clear_data contains the decrypted data */

-       clear_tvb = tvb_new_child_real_data(encrypted_tvb ...
(more)
amit_wireshark gravatar imageamit_wireshark ( 2020-04-21 17:46:05 +0000 )edit

patch that I tried to put above is getting formatted. I will re-do this after figuring out how to avoid auto formatting while putting the comment.

amit_wireshark gravatar imageamit_wireshark ( 2020-04-21 17:50:28 +0000 )edit

I've fixed the formatting. Use "Ctrl + K " or 4 space indent to format as code. Use backticks for inline.

I've no idea why you think modifying tvb_new_child_real_data() in such a way is required or even a good idea. Modifying the header (tvbuff.h) won't modify the code in tvbuff_real.c

grahamb gravatar imagegrahamb ( 2020-04-21 18:29:02 +0000 )edit

Thanks for the response. Sorry I did not mention my intention.

I am trying to modify wireshark code so that some of the information elements in telecom protocols (which can be called as user sensitive data) can be obfuscated. Hence, I intend to modify the packet buffer in wireshark and hence converted it (real_data in tvbuff) to non-const so that can I can overwrite these selective fields before it gets displayed (raw buffer as well as dissect tree). To do that I had to make a whole of changes to make buffer as non-const and return pointer as non-const for many functions across wireshark source.

That is how I got into this problem.

I change the function call, definition and declaration for tvb_new_child_real_data() but I get compile error.

Patch did not mention but I did modify function definition in tvbuff_real.c as well.

+++++++++++++++++
diff --git a/epan/tvbuff_real.c b ...
(more)
amit_wireshark gravatar imageamit_wireshark ( 2020-04-22 06:31:24 +0000 )edit

Thanks you. I was able to solve the problem.

amit_wireshark gravatar imageamit_wireshark ( 2020-04-24 16:37:57 +0000 )edit
0

answered 2020-04-21 22:52:53 +0000

Guy Harris gravatar image

updated 2020-04-22 03:01:05 +0000

Originally I was trying to remove the const type casting for the 2nd parameter of the function call tvb_new_child_real_data, which I fixed in function definition/declaration etc.

DO NOT DO THAT. That's NOT a "fix" to ANYTHING.

The second argument is SUPPOSED to be a const guint8 *, because neither tvb_new_child_real_data() nor any of the code that uses the data to which it's passed a pointer modifies the data to which it points; the const explicitly indicates that it will not be modified and so it can safely be passed in without a concern that it will be modified.

So PUT THE const BACK IN THE FUNCTION DECLARATION AND DEFINITION, get rid of the cast in the call, and go on from there.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-04-21 16:21:45 +0000

Seen: 301 times

Last updated: Apr 22 '20