LCOV - code coverage report
Current view: directory - src/trusted/desc - nacl_makeboundsock.c (source / functions) Found Hit Coverage
Test: coverage.lcov Lines: 32 26 81.2 %
Date: 2014-09-25 Functions: 0 0 -

       1                 : /*
       2                 :  * Copyright 2008 The Native Client Authors. All rights reserved.
       3                 :  * Use of this source code is governed by a BSD-style license that can be
       4                 :  * found in the LICENSE file.
       5                 :  */
       6                 : 
       7                 : #include "native_client/src/include/portability.h"
       8                 : #include "native_client/src/shared/platform/nacl_global_secure_random.h"
       9                 : #include "native_client/src/shared/platform/nacl_log.h"
      10                 : #include "native_client/src/trusted/desc/nacl_desc_base.h"
      11                 : #include "native_client/src/trusted/desc/nacl_desc_conn_cap.h"
      12                 : #include "native_client/src/trusted/desc/nacl_desc_imc_bound_desc.h"
      13                 : #include "native_client/src/trusted/service_runtime/include/sys/errno.h"
      14                 : 
      15                 : 
      16               2 : int32_t NaClCommonDescMakeBoundSock(struct NaClDesc *pair[2]) {
      17                 :   int32_t                     retval;
      18                 :   struct NaClSocketAddress    sa;
      19                 :   struct NaClDescConnCap      *ccp;
      20                 :   NaClHandle                  h;
      21                 :   struct NaClDescImcBoundDesc *idp;
      22                 : 
      23               2 :   retval = -NACL_ABI_ENOMEM;
      24               2 :   ccp = NULL;
      25               2 :   idp = NULL;
      26               2 :   h = NACL_INVALID_HANDLE;
      27                 :   /*
      28                 :    * create NaClDescConnCap object, invoke NaClBoundSocket, create
      29                 :    * an NaClDescImcDesc object.  put both into open file table.
      30                 :    */
      31               2 :   ccp = malloc(sizeof *ccp);
      32               2 :   if (NULL == ccp) {
      33               0 :     goto cleanup;
      34                 :   }
      35               2 :   idp = malloc(sizeof *idp);
      36               2 :   if (NULL == idp) {
      37               0 :     goto cleanup;
      38                 :   }
      39                 : 
      40                 :   do {
      41               2 :     NaClGenerateRandomPath(&sa.path[0], NACL_PATH_MAX);
      42               2 :     h = NaClBoundSocket(&sa);
      43                 :     NaClLog(3, "NaClCommonDescMakeBoundSock: sa: %s, h 0x%"NACL_PRIxPTR"\n",
      44               2 :             sa.path, (uintptr_t) h);
      45               2 :   } while (NACL_INVALID_HANDLE == h);
      46                 : 
      47               2 :   if (!NaClDescConnCapCtor(ccp, &sa)) {
      48               0 :     goto cleanup;
      49                 :   }
      50                 : 
      51               2 :   if (!NaClDescImcBoundDescCtor(idp, h)) {
      52               0 :     NaClDescUnref((struct NaClDesc *) ccp);
      53               0 :     goto cleanup;
      54                 :   }
      55               2 :   h = NACL_INVALID_HANDLE;  /* idp took ownership */
      56                 : 
      57               2 :   pair[0] = (struct NaClDesc *) idp;
      58               2 :   idp = NULL;
      59                 : 
      60               2 :   pair[1] = (struct NaClDesc *) ccp;
      61               2 :   ccp = NULL;
      62                 : 
      63               2 :   retval = 0;
      64                 : 
      65                 :  cleanup:
      66               2 :   free(idp);
      67               2 :   free(ccp);
      68               2 :   if (NACL_INVALID_HANDLE != h) {
      69               0 :     (void) NaClClose(h);
      70                 :   }
      71               2 :   return retval;
      72               2 : }

Generated by: LCOV version 1.7