Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6750583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:49:29+00:00 2026-05-26T12:49:29+00:00

I have a C structure like this : typedef struct ip_esp_private { /* keep

  • 0

I have a C structure like this :

 typedef struct ip_esp_private {         /* keep track of things privately */
    u_int32_t type;        
    u_int32_t ivlen;       
    u_int32_t icvlen;      
    u_int32_t keylen;       /* length of "Encryption key */
    u_int32_t akeylen;      /*length of authn key */
  //  u_int32_t key[0];       /* key itself */
  //  u_int32_t akey[0];      /*authn key itself */

    u_int32_t *key;       /* as suggested  */
    u_int32_t *akey;      /* as suggested */

 } esp_private;

Now the problem should be obvious from here when I try to write to key , the akey will be overwritten .

I am not sure how can I protect it ???

keylen and akeylen provide length of key and akey array and whole structure is to be filled at run time.

Please provide some suggestions .

EDIT :

  1. yes … u_int32_t is a typedef so dont bother about that

  2. I have changed the zero length array to pointers as edited above.This is how I need to fill in the structure ..

    case 'k':       /* Key */
            length = stringargument(arg, &temp);
            priv->keylen = length;
    
            priv->key=malloc(priv->keylen * sizeof(u_int32_t));
            /*as suggested added this step*/          
    
    
            /*as suggested commented this step*/
            priv = (esp_private *)realloc(priv,
                            sizeof(esp_private) + length);
    
    
    
            memcpy(priv->key, temp, priv->keylen);
            pack->private = priv;
            pack->modified |= ESP_MOD_KEY;
            break;
    
    case 'K':       /* Authentication  Key */       
            length = stringargument(arg, &temp);
            priv->akeylen = length;
    
            priv->akey=malloc(priv->akeylen * sizeof(u_int32_t));
            /*as suggested added this step*/
    
    
            /*as suggested commented this step*/
            priv = (esp_private *)realloc(priv,
                            sizeof(esp_private) + length);
    
    
    
            memcpy(priv->akey, temp, priv->akeylen);
            pack->private = priv;
            pack->modified |= ESP_MOD_AKEY;
    

but not working out .. may be not re-allocating carefully please suggest on this edit also.

EDIT 2:

Even after commenting the realloc as suggested , its not working out.The key and akey were supposed to take value mentioned as arg on command line but they are taking some random values.There is still something wrong here which need attention.

Please help me as the whole project has stuck in between just because of a minute error in this small piece of code.Need it soon …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:49:29+00:00Added an answer on May 26, 2026 at 12:49 pm

    So can’t you just have key and akey as pointers and malloc memory for them upon creation of an esp_private struct?

     typedef struct ip_esp_private {  
        u_int32_t type;        
        u_int32_t ivlen;       
        u_int32_t icvlen;      
        u_int32_t keylen; 
        u_int32_t akeylen; 
        u_int32_t *key;  /* change */  
        u_int32_t *akey; /* change */
     } esp_private;
    
    void esp_private_init(esp_private *ep, /* maybe some args here for type, ivlen, etc */
                         u_int32_t *key, u_int32_t keylen, u_int32_t *akey, u_int32_t akeylen)
    {
       /* maybe set up type, ivlen, etc if neccesary */
    
       ep->keylen = keylen;
       ep->key = malloc(keylen * sizeof(u_int32_t));
       /* copy argument key into ep->key */
    
       ep->akeylen = akeylen;
       ep->akey = malloc(akeylen * sizeof(u_int32_t));
       /* copy argument akey into ep->akey */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a first structure like this: typedef struct { int ivalue;
I have a C structure that looks like this typedef struct event_queue{ Event* event;
I have a structure to represent strings in memory looking like this: typedef struct
I have a structure in C like this typedef struct SKT_SubHeader_s { U32 subLength;
I have a header file including a structure like this: typedef struct { int
I have a data structure something like this: typedef struct tagSUB_DATA { double measuredValue;
I have a structure like this typedef struct{ int stat; }dot; And I would
I have a structure defined like so: typedef struct { int n; int *n_p;
I have structure for storing callback function like this: template<class T> struct CommandGlobal :
I have this structure: typedef struct { int data[10]; } small_structure; and this code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.