ia64/xen-unstable

changeset 16074:61ef23e45e9c

xenstore: sprintf->snprintf, and fix for OpenBSD.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir@xensource.com>
date Fri Oct 05 14:11:36 2007 +0100 (2007-10-05)
parents 1d120f6807ba
children a1d0a272c890
files tools/xenstore/xenstored_core.c tools/xenstore/xenstored_transaction.c tools/xenstore/xs.c tools/xenstore/xs_lib.c tools/xenstore/xs_lib.h tools/xenstore/xsls.c
line diff
     1.1 --- a/tools/xenstore/xenstored_core.c	Fri Oct 05 10:38:52 2007 +0100
     1.2 +++ b/tools/xenstore/xenstored_core.c	Fri Oct 05 14:11:36 2007 +0100
     1.3 @@ -685,7 +685,7 @@ static char *perms_to_strings(const void
     1.4  	char buffer[MAX_STRLEN(unsigned int) + 1];
     1.5  
     1.6  	for (*len = 0, i = 0; i < num; i++) {
     1.7 -		if (!xs_perm_to_string(&perms[i], buffer))
     1.8 +		if (!xs_perm_to_string(&perms[i], buffer, sizeof(buffer)))
     1.9  			return NULL;
    1.10  
    1.11  		strings = talloc_realloc(ctx, strings, char,
    1.12 @@ -1659,7 +1659,7 @@ static void write_pidfile(const char *pi
    1.13  	if (lockf(fd, F_TLOCK, 0) == -1)
    1.14  		exit(0);
    1.15  
    1.16 -	len = sprintf(buf, "%ld\n", (long)getpid());
    1.17 +	len = snprintf(buf, sizeof(buf), "%ld\n", (long)getpid());
    1.18  	if (write(fd, buf, len) != len)
    1.19  		barf_perror("Writing pid file %s", pidfile);
    1.20  }
     2.1 --- a/tools/xenstore/xenstored_transaction.c	Fri Oct 05 10:38:52 2007 +0100
     2.2 +++ b/tools/xenstore/xenstored_transaction.c	Fri Oct 05 14:11:36 2007 +0100
     2.3 @@ -181,7 +181,7 @@ void do_transaction_start(struct connect
     2.4  	talloc_set_destructor(trans, destroy_transaction);
     2.5  	conn->transaction_started++;
     2.6  
     2.7 -	sprintf(id_str, "%u", trans->id);
     2.8 +	snprintf(id_str, sizeof(id_str), "%u", trans->id);
     2.9  	send_reply(conn, XS_TRANSACTION_START, id_str, strlen(id_str)+1);
    2.10  }
    2.11  
     3.1 --- a/tools/xenstore/xs.c	Fri Oct 05 10:38:52 2007 +0100
     3.2 +++ b/tools/xenstore/xs.c	Fri Oct 05 14:11:36 2007 +0100
     3.3 @@ -20,6 +20,7 @@
     3.4  #include <sys/types.h>
     3.5  #include <sys/stat.h>
     3.6  #include <fcntl.h>
     3.7 +#include <sys/uio.h>
     3.8  #include <sys/socket.h>
     3.9  #include <sys/un.h>
    3.10  #include <string.h>
    3.11 @@ -519,7 +520,7 @@ bool xs_set_permissions(struct xs_handle
    3.12  	for (i = 0; i < num_perms; i++) {
    3.13  		char buffer[MAX_STRLEN(unsigned int)+1];
    3.14  
    3.15 -		if (!xs_perm_to_string(&perms[i], buffer))
    3.16 +		if (!xs_perm_to_string(&perms[i], buffer, sizeof(buffer)))
    3.17  			goto unwind;
    3.18  
    3.19  		iov[i+1].iov_base = strdup(buffer);
    3.20 @@ -687,9 +688,9 @@ bool xs_introduce_domain(struct xs_handl
    3.21  	char eventchn_str[MAX_STRLEN(eventchn)];
    3.22  	struct iovec iov[3];
    3.23  
    3.24 -	sprintf(domid_str, "%u", domid);
    3.25 -	sprintf(mfn_str, "%lu", mfn);
    3.26 -	sprintf(eventchn_str, "%u", eventchn);
    3.27 +	snprintf(domid_str, sizeof(domid_str), "%u", domid);
    3.28 +	snprintf(mfn_str, sizeof(mfn_str), "%lu", mfn);
    3.29 +	snprintf(eventchn_str, sizeof(eventchn_str), "%u", eventchn);
    3.30  
    3.31  	iov[0].iov_base = domid_str;
    3.32  	iov[0].iov_len = strlen(domid_str) + 1;
    3.33 @@ -708,7 +709,7 @@ static void * single_with_domid(struct x
    3.34  {
    3.35  	char domid_str[MAX_STRLEN(domid)];
    3.36  
    3.37 -	sprintf(domid_str, "%u", domid);
    3.38 +	snprintf(domid_str, sizeof(domid_str), "%u", domid);
    3.39  
    3.40  	return xs_single(h, XBT_NULL, type, domid_str, NULL);
    3.41  }
    3.42 @@ -728,7 +729,7 @@ char *xs_get_domain_path(struct xs_handl
    3.43  {
    3.44  	char domid_str[MAX_STRLEN(domid)];
    3.45  
    3.46 -	sprintf(domid_str, "%u", domid);
    3.47 +	snprintf(domid_str, sizeof(domid_str), "%u", domid);
    3.48  
    3.49  	return xs_single(h, XBT_NULL, XS_GET_DOMAIN_PATH, domid_str, NULL);
    3.50  }
     4.1 --- a/tools/xenstore/xs_lib.c	Fri Oct 05 10:38:52 2007 +0100
     4.2 +++ b/tools/xenstore/xs_lib.c	Fri Oct 05 14:11:36 2007 +0100
     4.3 @@ -17,12 +17,12 @@
     4.4      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     4.5  */
     4.6  
     4.7 -#include "xs_lib.h"
     4.8  #include <unistd.h>
     4.9  #include <stdio.h>
    4.10  #include <string.h>
    4.11  #include <stdlib.h>
    4.12  #include <errno.h>
    4.13 +#include "xs_lib.h"
    4.14  
    4.15  /* Common routines for the Xen store daemon and client library. */
    4.16  
    4.17 @@ -53,7 +53,7 @@ static const char *xs_daemon_path(void)
    4.18  const char *xs_daemon_tdb(void)
    4.19  {
    4.20  	static char buf[PATH_MAX];
    4.21 -	sprintf(buf, "%s/tdb", xs_daemon_rootdir());
    4.22 +	snprintf(buf, sizeof(buf), "%s/tdb", xs_daemon_rootdir());
    4.23  	return buf;
    4.24  }
    4.25  
    4.26 @@ -143,7 +143,8 @@ bool xs_strings_to_perms(struct xs_permi
    4.27  }
    4.28  
    4.29  /* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */
    4.30 -bool xs_perm_to_string(const struct xs_permissions *perm, char *buffer)
    4.31 +bool xs_perm_to_string(const struct xs_permissions *perm,
    4.32 +                       char *buffer, size_t buf_len)
    4.33  {
    4.34  	switch (perm->perms) {
    4.35  	case XS_PERM_WRITE:
    4.36 @@ -162,7 +163,7 @@ bool xs_perm_to_string(const struct xs_p
    4.37  		errno = EINVAL;
    4.38  		return false;
    4.39  	}
    4.40 -	sprintf(buffer+1, "%i", (int)perm->id);
    4.41 +	snprintf(buffer+1, buf_len-1, "%i", (int)perm->id);
    4.42  	return true;
    4.43  }
    4.44  
     5.1 --- a/tools/xenstore/xs_lib.h	Fri Oct 05 10:38:52 2007 +0100
     5.2 +++ b/tools/xenstore/xs_lib.h	Fri Oct 05 14:11:36 2007 +0100
     5.3 @@ -61,7 +61,8 @@ bool xs_strings_to_perms(struct xs_permi
     5.4  			 const char *strings);
     5.5  
     5.6  /* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */
     5.7 -bool xs_perm_to_string(const struct xs_permissions *perm, char *buffer);
     5.8 +bool xs_perm_to_string(const struct xs_permissions *perm,
     5.9 +                       char *buffer, size_t buf_len);
    5.10  
    5.11  /* Given a string and a length, count how many strings (nul terms). */
    5.12  unsigned int xs_count_strings(const char *strings, unsigned int len);
     6.1 --- a/tools/xenstore/xsls.c	Fri Oct 05 10:38:52 2007 +0100
     6.2 +++ b/tools/xenstore/xsls.c	Fri Oct 05 14:11:36 2007 +0100
     6.3 @@ -87,7 +87,7 @@ void print_dir(struct xs_handle *h, char
     6.4                  for (i = 0; i < nperms; i++) {
     6.5                      if (i)
     6.6                          putchar(',');
     6.7 -                    xs_perm_to_string(perms+i, buf);
     6.8 +                    xs_perm_to_string(perms+i, buf, sizeof(buf));
     6.9                      fputs(buf, stdout);
    6.10                  }
    6.11                  putchar(')');