ia64/xen-unstable

changeset 17838:e5c9c8e6e726

tools: replace sprintf with snprintf where applicable

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 12 15:41:15 2008 +0100 (2008-06-12)
parents ebbd0e8c3e72
children 0089fe3d209d
files tools/console/daemon/io.c tools/fs-back/fs-ops.c tools/fs-back/fs-xenbus.c tools/libfsimage/zfs/fsys_zfs.c tools/libxc/xc_dom_x86.c tools/misc/nsplitd/nsplitd.c tools/misc/xenperf.c tools/vnet/vnet-module/varp_util.h tools/vnet/vnet-module/vnet.c tools/vtpm_manager/migration/vtpm_migratord_handler.c tools/xenmon/xenbaked.c
line diff
     1.1 --- a/tools/console/daemon/io.c	Thu Jun 12 15:22:35 2008 +0100
     1.2 +++ b/tools/console/daemon/io.c	Thu Jun 12 15:41:15 2008 +0100
     1.3 @@ -525,7 +525,8 @@ static int domain_create_ring(struct dom
     1.4  	} else
     1.5  		dom->use_consolepath = 0;
     1.6  
     1.7 -	sprintf(path, "%s/type", dom->use_consolepath ? dom->conspath: dom->serialpath);
     1.8 +	snprintf(path, sizeof(path), "%s/type",
     1.9 +		dom->use_consolepath ? dom->conspath: dom->serialpath);
    1.10  	type = xs_read(xs, XBT_NULL, path, NULL);
    1.11  	if (type && strcmp(type, "xenconsoled") != 0) {
    1.12  		free(type);
     2.1 --- a/tools/fs-back/fs-ops.c	Thu Jun 12 15:22:35 2008 +0100
     2.2 +++ b/tools/fs-back/fs-ops.c	Thu Jun 12 15:41:15 2008 +0100
     2.3 @@ -55,7 +55,8 @@ void dispatch_file_open(struct mount *mo
     2.4      printf("File open issued for %s\n", file_name); 
     2.5      assert(BUFFER_SIZE > 
     2.6             strlen(file_name) + strlen(mount->export->export_path) + 1); 
     2.7 -    sprintf(full_path, "%s/%s", mount->export->export_path, file_name);
     2.8 +    snprintf(full_path, sizeof(full_path), "%s/%s",
     2.9 +           mount->export->export_path, file_name);
    2.10      assert(xc_gnttab_munmap(mount->gnth, file_name, 1) == 0);
    2.11      printf("Issuing open for %s\n", full_path);
    2.12      fd = open(full_path, O_RDWR);
    2.13 @@ -311,7 +312,8 @@ void dispatch_remove(struct mount *mount
    2.14      printf("File remove issued for %s\n", file_name); 
    2.15      assert(BUFFER_SIZE > 
    2.16             strlen(file_name) + strlen(mount->export->export_path) + 1); 
    2.17 -    sprintf(full_path, "%s/%s", mount->export->export_path, file_name);
    2.18 +    snprintf(full_path, sizeof(full_path), "%s/%s",
    2.19 +           mount->export->export_path, file_name);
    2.20      assert(xc_gnttab_munmap(mount->gnth, file_name, 1) == 0);
    2.21      printf("Issuing remove for %s\n", full_path);
    2.22      ret = remove(full_path);
    2.23 @@ -355,8 +357,10 @@ void dispatch_rename(struct mount *mount
    2.24             strlen(old_file_name) + strlen(mount->export->export_path) + 1); 
    2.25      assert(BUFFER_SIZE > 
    2.26             strlen(new_file_name) + strlen(mount->export->export_path) + 1); 
    2.27 -    sprintf(old_full_path, "%s/%s", mount->export->export_path, old_file_name);
    2.28 -    sprintf(new_full_path, "%s/%s", mount->export->export_path, new_file_name);
    2.29 +    snprintf(old_full_path, sizeof(old_full_path), "%s/%s",
    2.30 +           mount->export->export_path, old_file_name);
    2.31 +    snprintf(new_full_path, sizeof(new_full_path), "%s/%s",
    2.32 +           mount->export->export_path, new_file_name);
    2.33      assert(xc_gnttab_munmap(mount->gnth, buf, 1) == 0);
    2.34      printf("Issuing rename for %s -> %s\n", old_full_path, new_full_path);
    2.35      ret = rename(old_full_path, new_full_path);
    2.36 @@ -398,7 +402,8 @@ void dispatch_create(struct mount *mount
    2.37      printf("File create issued for %s\n", file_name); 
    2.38      assert(BUFFER_SIZE > 
    2.39             strlen(file_name) + strlen(mount->export->export_path) + 1); 
    2.40 -    sprintf(full_path, "%s/%s", mount->export->export_path, file_name);
    2.41 +    snprintf(full_path, sizeof(full_path), "%s/%s",
    2.42 +           mount->export->export_path, file_name);
    2.43      assert(xc_gnttab_munmap(mount->gnth, file_name, 1) == 0);
    2.44      /* We can advance the request consumer index, from here on, the request
    2.45       * should not be used (it may be overrinden by a response) */
    2.46 @@ -447,7 +452,8 @@ void dispatch_list(struct mount *mount, 
    2.47      printf("Dir list issued for %s\n", file_name); 
    2.48      assert(BUFFER_SIZE > 
    2.49             strlen(file_name) + strlen(mount->export->export_path) + 1); 
    2.50 -    sprintf(full_path, "%s/%s", mount->export->export_path, file_name);
    2.51 +    snprintf(full_path, sizeof(full_path), "%s/%s",
    2.52 +           mount->export->export_path, file_name);
    2.53      /* We can advance the request consumer index, from here on, the request
    2.54       * should not be used (it may be overrinden by a response) */
    2.55      mount->ring.req_cons++;
    2.56 @@ -540,7 +546,8 @@ void dispatch_fs_space(struct mount *mou
    2.57      printf("Fs space issued for %s\n", file_name); 
    2.58      assert(BUFFER_SIZE > 
    2.59             strlen(file_name) + strlen(mount->export->export_path) + 1); 
    2.60 -    sprintf(full_path, "%s/%s", mount->export->export_path, file_name);
    2.61 +    snprintf(full_path, sizeof(full_path), "%s/%s",
    2.62 +           mount->export->export_path, file_name);
    2.63      assert(xc_gnttab_munmap(mount->gnth, file_name, 1) == 0);
    2.64      printf("Issuing fs space for %s\n", full_path);
    2.65      ret = statfs(full_path, &stat);
     3.1 --- a/tools/fs-back/fs-xenbus.c	Thu Jun 12 15:22:35 2008 +0100
     3.2 +++ b/tools/fs-back/fs-xenbus.c	Thu Jun 12 15:41:15 2008 +0100
     3.3 @@ -22,8 +22,8 @@ static bool xenbus_printf(struct xs_hand
     3.4      va_list args;
     3.5      
     3.6      va_start(args, fmt);
     3.7 -    sprintf(fullpath,"%s/%s", node, path);
     3.8 -    vsprintf(val, fmt, args);
     3.9 +    snprintf(fullpath, sizeof(fullpath), "%s/%s", node, path);
    3.10 +    vsnprintf(val, sizeof(val), fmt, args);
    3.11      va_end(args);
    3.12      printf("xenbus_printf (%s) <= %s.\n", fullpath, val);    
    3.13  
    3.14 @@ -72,7 +72,7 @@ int xenbus_register_export(struct fs_exp
    3.15      printf("XS transaction is %d\n", xst); 
    3.16   
    3.17      /* Create node string */
    3.18 -    sprintf(node, "%s/%d", EXPORTS_NODE, export->export_id); 
    3.19 +    snprintf(node, sizeof(node), "%s/%d", EXPORTS_NODE, export->export_id); 
    3.20      /* Remove old export (if exists) */ 
    3.21      xs_rm(xsh, xst, node);
    3.22  
    3.23 @@ -116,20 +116,20 @@ void xenbus_read_mount_request(struct mo
    3.24  
    3.25      assert(xsh != NULL);
    3.26  #if 0
    3.27 -    sprintf(node, WATCH_NODE"/%d/%d/frontend", 
    3.28 +    snprintf(node, sizeof(node), WATCH_NODE"/%d/%d/frontend", 
    3.29                             mount->dom_id, mount->export->export_id);
    3.30      frontend = xs_read(xsh, XBT_NULL, node, NULL);
    3.31  #endif
    3.32      mount->frontend = frontend;
    3.33 -    sprintf(node, "%s/state", frontend);
    3.34 +    snprintf(node, sizeof(node), "%s/state", frontend);
    3.35      s = xs_read(xsh, XBT_NULL, node, NULL);
    3.36      assert(strcmp(s, STATE_READY) == 0);
    3.37      free(s);
    3.38 -    sprintf(node, "%s/ring-ref", frontend);
    3.39 +    snprintf(node, sizeof(node), "%s/ring-ref", frontend);
    3.40      s = xs_read(xsh, XBT_NULL, node, NULL);
    3.41      mount->gref = atoi(s);
    3.42      free(s);
    3.43 -    sprintf(node, "%s/event-channel", frontend);
    3.44 +    snprintf(node, sizeof(node), "%s/event-channel", frontend);
    3.45      s = xs_read(xsh, XBT_NULL, node, NULL);
    3.46      mount->remote_evtchn = atoi(s);
    3.47      free(s);
    3.48 @@ -158,12 +158,12 @@ void xenbus_write_backend_node(struct mo
    3.49      assert(xsh != NULL);
    3.50      self_id = get_self_id();
    3.51      printf("Our own dom_id=%d\n", self_id);
    3.52 -    sprintf(node, "%s/backend", mount->frontend);
    3.53 -    sprintf(backend_node, "/local/domain/%d/"ROOT_NODE"/%d",
    3.54 +    snprintf(node, sizeof(node), "%s/backend", mount->frontend);
    3.55 +    snprintf(backend_node, sizeof(backend_node), "/local/domain/%d/"ROOT_NODE"/%d",
    3.56                                  self_id, mount->mount_id);
    3.57      xs_write(xsh, XBT_NULL, node, backend_node, strlen(backend_node));
    3.58  
    3.59 -    sprintf(node, ROOT_NODE"/%d/state", mount->mount_id);
    3.60 +    snprintf(node, sizeof(node), ROOT_NODE"/%d/state", mount->mount_id);
    3.61      xs_write(xsh, XBT_NULL, node, STATE_INITIALISED, strlen(STATE_INITIALISED));
    3.62  }
    3.63  
    3.64 @@ -174,7 +174,7 @@ void xenbus_write_backend_ready(struct m
    3.65  
    3.66      assert(xsh != NULL);
    3.67      self_id = get_self_id();
    3.68 -    sprintf(node, ROOT_NODE"/%d/state", mount->mount_id);
    3.69 +    snprintf(node, sizeof(node), ROOT_NODE"/%d/state", mount->mount_id);
    3.70      xs_write(xsh, XBT_NULL, node, STATE_READY, strlen(STATE_READY));
    3.71  }
    3.72  
     4.1 --- a/tools/libfsimage/zfs/fsys_zfs.c	Thu Jun 12 15:22:35 2008 +0100
     4.2 +++ b/tools/libfsimage/zfs/fsys_zfs.c	Thu Jun 12 15:41:15 2008 +0100
     4.3 @@ -1336,7 +1336,7 @@ zfs_open(fsi_file_t *ffi, char *filename
     4.4  			char zfs_bootstr[] = "zfs-bootfs=";
     4.5  			char zfs_bootpath[] = ",bootpath='";
     4.6  
     4.7 -			sprintf(temp, "%llu", (unsigned long long)
     4.8 +			snprintf(temp, sizeof(temp), "%llu", (unsigned long long)
     4.9  			    current_bootfs_obj);
    4.10  			alloc_size = strlen(zfs_bootstr) +
    4.11  			    strlen(current_rootpool) +
     5.1 --- a/tools/libxc/xc_dom_x86.c	Thu Jun 12 15:22:35 2008 +0100
     5.2 +++ b/tools/libxc/xc_dom_x86.c	Thu Jun 12 15:41:15 2008 +0100
     5.3 @@ -418,7 +418,7 @@ static int start_info_x86_32(struct xc_d
     5.4      xc_dom_printf("%s: called\n", __FUNCTION__);
     5.5  
     5.6      memset(start_info, 0, sizeof(*start_info));
     5.7 -    sprintf(start_info->magic, dom->guest_type);
     5.8 +    snprintf(start_info->magic, sizeof(start_info->magic), dom->guest_type);
     5.9      start_info->nr_pages = dom->total_pages;
    5.10      start_info->shared_info = shinfo << PAGE_SHIFT_X86;
    5.11      start_info->pt_base = dom->pgtables_seg.vstart;
    5.12 @@ -457,7 +457,7 @@ static int start_info_x86_64(struct xc_d
    5.13      xc_dom_printf("%s: called\n", __FUNCTION__);
    5.14  
    5.15      memset(start_info, 0, sizeof(*start_info));
    5.16 -    sprintf(start_info->magic, dom->guest_type);
    5.17 +    snprintf(start_info->magic, sizeof(start_info->magic), dom->guest_type);
    5.18      start_info->nr_pages = dom->total_pages;
    5.19      start_info->shared_info = shinfo << PAGE_SHIFT_X86;
    5.20      start_info->pt_base = dom->pgtables_seg.vstart;
     6.1 --- a/tools/misc/nsplitd/nsplitd.c	Thu Jun 12 15:22:35 2008 +0100
     6.2 +++ b/tools/misc/nsplitd/nsplitd.c	Thu Jun 12 15:41:15 2008 +0100
     6.3 @@ -106,7 +106,7 @@ static void fault(char *format, ...)
     6.4      
     6.5      /* XXX This is a bit dubious, but there is no vsyslog */
     6.6      va_start(ap, format);
     6.7 -    vsprintf(logbuf, format, ap);
     6.8 +    vsnprintf(logbuf, sizeof(logbuf), format, ap);
     6.9      syslog(LOG_ERR, logbuf);
    6.10      va_end(ap);
    6.11      exit(1);
     7.1 --- a/tools/misc/xenperf.c	Thu Jun 12 15:22:35 2008 +0100
     7.2 +++ b/tools/misc/xenperf.c	Thu Jun 12 15:41:15 2008 +0100
     7.3 @@ -202,7 +202,7 @@ int main(int argc, char *argv[])
     7.4                          strncpy(hypercall_name, hypercall_name_table[j],
     7.5                                  sizeof(hypercall_name));
     7.6                      else
     7.7 -                        sprintf(hypercall_name, "[%d]", j);
     7.8 +                        snprintf(hypercall_name, sizeof(hypercall_name), "[%d]", j);
     7.9                      hypercall_name[sizeof(hypercall_name)-1]='\0';
    7.10                      printf("%-35s ", hypercall_name);
    7.11                      printf("%12u\n", (unsigned int)val[j]);
     8.1 --- a/tools/vnet/vnet-module/varp_util.h	Thu Jun 12 15:22:35 2008 +0100
     8.2 +++ b/tools/vnet/vnet-module/varp_util.h	Thu Jun 12 15:41:15 2008 +0100
     8.3 @@ -53,11 +53,11 @@ static inline const char *VarpAddr_ntoa(
     8.4      switch(addr->family){
     8.5      default:
     8.6      case AF_INET:
     8.7 -        sprintf(buf, "%u.%u.%u.%u",
     8.8 +        snprintf(buf, sizeof(buf), "%u.%u.%u.%u",
     8.9                  NIPQUAD(addr->u.ip4));
    8.10          break;
    8.11      case AF_INET6:
    8.12 -        sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
    8.13 +        snprintf(buf, sizeof(buf), "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
    8.14                  NIP6(addr->u.ip6));
    8.15          break;
    8.16      }
    8.17 @@ -66,7 +66,7 @@ static inline const char *VarpAddr_ntoa(
    8.18  
    8.19  static inline const char *VnetId_ntoa(VnetId *vnet, char buf[VNET_ID_BUF])
    8.20  {
    8.21 -    sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
    8.22 +    snprintf(buf, sizeof(buf), "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
    8.23              ntohs(vnet->u.vnet16[0]), \
    8.24              ntohs(vnet->u.vnet16[1]), \
    8.25              ntohs(vnet->u.vnet16[2]), \
     9.1 --- a/tools/vnet/vnet-module/vnet.c	Thu Jun 12 15:22:35 2008 +0100
     9.2 +++ b/tools/vnet/vnet-module/vnet.c	Thu Jun 12 15:41:15 2008 +0100
     9.3 @@ -354,7 +354,7 @@ static int vnet_setup(void){
     9.4          if(err) break;
     9.5          vnetid = VNET_VIF + i;
     9.6          vnet->vnet = toVnetId(vnetid);
     9.7 -        sprintf(vnet->device, "vnif%04x", vnetid);
     9.8 +        snprintf(vnet->device, sizeof(vnet->device), "vnif%04x", vnetid);
     9.9          vnet->security = (vnetid > 10 ? security : 0);
    9.10          err = Vnet_create(vnet);
    9.11          Vnet_decref(vnet);
    10.1 --- a/tools/vtpm_manager/migration/vtpm_migratord_handler.c	Thu Jun 12 15:22:35 2008 +0100
    10.2 +++ b/tools/vtpm_manager/migration/vtpm_migratord_handler.c	Thu Jun 12 15:41:15 2008 +0100
    10.3 @@ -49,8 +49,8 @@
    10.4  // This must be updated to the longest command name. Currently GETINST
    10.5  #define VTPM_SH_CMD_SIZE (strlen(VTPM_SH_CMD_HDR) + strlen(VTPM_SH_CMD_FTR) + 1 + strlen(VTPM_SH_GETINST) + 2)
    10.6  
    10.7 -void handle_vtpm_mig_step2(buffer_t *in_param_buf, buffer_t *result_buf){
    10.8 -
    10.9 +void handle_vtpm_mig_step2(buffer_t *in_param_buf, buffer_t *result_buf)
   10.10 +{
   10.11    TPM_TAG tag = VTPM_TAG_RSP;
   10.12    buffer_t out_param_buf= NULL_BUF, mig_key_buf=NULL_BUF; 
   10.13    TPM_RESULT status=TPM_SUCCESS, cmd_status;
   10.14 @@ -97,13 +97,14 @@ void handle_vtpm_mig_step2(buffer_t *in_
   10.15    return;
   10.16  }
   10.17  
   10.18 -void handle_vtpm_mig_step3(buffer_t *in_param_buf, buffer_t *result_buf){
   10.19 -  
   10.20 +void handle_vtpm_mig_step3(buffer_t *in_param_buf, buffer_t *result_buf)
   10.21 +{
   10.22    TPM_TAG tag = VTPM_TAG_RSP;
   10.23    buffer_t out_param_buf= NULL_BUF, mig_key_buf=NULL_BUF, empty_buf=NULL_BUF;
   10.24    TPM_RESULT status=TPM_SUCCESS, cmd_status;
   10.25    UINT32 out_param_size, instance;
   10.26    char *shell_cmd_str=NULL;
   10.27 +  size_t shell_cmd_strlen;
   10.28    FILE *shell_f=NULL;
   10.29  
   10.30    if ( (!in_param_buf) || (!result_buf) ) {
   10.31 @@ -124,16 +125,20 @@ void handle_vtpm_mig_step3(buffer_t *in_
   10.32    }
   10.33  
   10.34    // ====== Call hotplug-script and get an instance ======
   10.35 -  shell_cmd_str = (char *) malloc(VTPM_SH_CMD_SIZE + name_data32.size + 10); // 10 is just padding for the UINT32
   10.36 +  shell_cmd_strlen = VTPM_SH_CMD_SIZE + name_data32.size + 10;
   10.37 +  shell_cmd_str = (char *) malloc(shell_cmd_strlen); // 10 is just padding for the UINT32
   10.38  
   10.39 -  sprintf(shell_cmd_str, VTPM_SH_CMD_HDR VTPM_SH_GETINST VTPM_SH_CMD_FTR);
   10.40 +  snprintf(shell_cmd_str, shell_cmd_strlen,
   10.41 +	VTPM_SH_CMD_HDR VTPM_SH_GETINST VTPM_SH_CMD_FTR);
   10.42  
   10.43    shell_f = popen(shell_cmd_str, "r");
   10.44    fscanf(shell_f, "%d", &instance);
   10.45    pclose(shell_f);
   10.46    
   10.47    // ====== Call hotplug-script and add instance ======
   10.48 -  sprintf(shell_cmd_str, VTPM_SH_CMD_HDR VTPM_SH_ADD " %s %d" VTPM_SH_CMD_FTR, name_data32.data, instance);
   10.49 +  snprintf(shell_cmd_str, shell_cmd_strlen,
   10.50 +	VTPM_SH_CMD_HDR VTPM_SH_ADD " %s %d" VTPM_SH_CMD_FTR,
   10.51 +	name_data32.data, instance);
   10.52    system(shell_cmd_str);
   10.53  
   10.54    // ========= Call vtpm_manager and load VTPM =======
   10.55 @@ -156,7 +161,8 @@ void handle_vtpm_mig_step3(buffer_t *in_
   10.56    TPMTRYRETURN(cmd_status);
   10.57  
   10.58    // ====== Call hotplug-script and resume instance ======
   10.59 -  sprintf(shell_cmd_str, VTPM_SH_CMD_HDR VTPM_SH_RESUME " %d" VTPM_SH_CMD_FTR, instance);
   10.60 +  snprintf(shell_cmd_str, shell_cmd_strlen,
   10.61 +	VTPM_SH_CMD_HDR VTPM_SH_RESUME " %d" VTPM_SH_CMD_FTR, instance);
   10.62    system(shell_cmd_str);
   10.63  
   10.64    goto egress;
    11.1 --- a/tools/xenmon/xenbaked.c	Thu Jun 12 15:22:35 2008 +0100
    11.2 +++ b/tools/xenmon/xenbaked.c	Thu Jun 12 15:41:15 2008 +0100
    11.3 @@ -749,9 +749,13 @@ void qos_init_domain(int domid, int idx)
    11.4      new_qos->domain_info[idx].blocked_start_time = 0;
    11.5      new_qos->domain_info[idx].id = domid;
    11.6      if (domid == IDLE_DOMAIN_ID)
    11.7 -        sprintf(new_qos->domain_info[idx].name, "Idle Task%d", global_cpu);
    11.8 +        snprintf(new_qos->domain_info[idx].name,
    11.9 +		sizeof(new_qos->domain_info[idx].name),
   11.10 +		"Idle Task%d", global_cpu);
   11.11      else
   11.12 -        sprintf(new_qos->domain_info[idx].name, "Domain#%d", domid);
   11.13 +        snprintf(new_qos->domain_info[idx].name,
   11.14 +		sizeof(new_qos->domain_info[idx].name),
   11.15 +		"Domain#%d", domid);
   11.16    
   11.17      for (i=0; i<NSAMPLES; i++) {
   11.18          new_qos->qdata[i].ns_gotten[idx] = 0;