I have a structure defined as
struct xyz {
char *str;
int x;
int y;
};
Which I am getting as input parameter to the executable from some other program1.(other program did execve of the program2 with input parameter as this structure).
I wish to know, can I do the typecast of this input parameter as (struct xyz*)argv[1];, or I have to convert it to string format before sending it?
You can’t pass arbitrary data to a command in that way. You’ll have to serialize it to a string, or perform some IPC (e.g. through pipe/socket).
The reason for this is that the strings are null terminated. Your
char*member will have a\0on the end, and even if it doesn’t, any int less than 16843009 (0x01010101) will have a null byte in it and fail to copy properly.