Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Edited by sciSpider (sch jbop) (X_X)@==(Q_Q)@

...

Code Block
bgColor#ffcccc

int establish() {
  struct sockaddr_in sa;              /*  This will store the listening socket's address  */
  int s;                              /*  This will hold the listening socket  */

  /*  Fill up the structure with address and port number  */

  sa.sin_port = htons(portnum);

  /*  Other system calls like socket()  */

  if (bind(s, (struct sockaddr *) &sa, sizeof(struct sockaddr_in)) < 0) {
    /* Perform cleanup */  
  }  

  /* Return */
}

int main(void) {
   int s = establish();

  /*  Block with accept() until a client connects  */
   
   switch (fork()) {
      case -1 :  /* Error, clean up and quit */
      case  0 :  /* This is the child, handle the client */
      default :  /* This is the parent, continue blocking */
   }
} 

...

Code Block
bgColor#ccccff

/*  Code with elevated privileges  */

int establish() {
  struct sockaddr_in sa;              /*  This will store the listening socket's address  */
  int s;                              /*  This will hold the listening socket  */

  /* Fill up the structure with address and port number */

  sa.sin_port = htons(portnum);

  /* Other system calls like socket() */

  if (bind(s, (struct sockaddr *) &sa, sizeof(struct sockaddr_in)) < 0)  { 
    /* Perform cleanup */  
  }

  /* Return */  
}

int main(void) {
   int s = establish();

   if (setuid(getuid()) == -1) {   /* Drop privileges permanently */
      /*  Handle the error  */
   }

  /* Block with accept() until a client connects */
      
   switch (fork()) {
      case -1: /* Error, clean up and quit */
      case  0: /* Close all open file descriptors
                * This is the child, handle the client 
                */
      default: /* This is the parent, continue blocking */
   }
} 

...

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

POS02-A

high

likely

high

P9

L2

Related Vulnerabilities

Search for vulnerabilities resulting from the violation of this recommendation rule on the CERT website.

References

...