char buffer[MAX_STRLEN(unsigned int) + 1];
for (*len = 0, i = 0; i < num; i++) {
- if (!xs_perm_to_string(&perms[i], buffer))
+ if (!xs_perm_to_string(&perms[i], buffer, sizeof(buffer)))
return NULL;
strings = talloc_realloc(ctx, strings, char,
if (lockf(fd, F_TLOCK, 0) == -1)
exit(0);
- len = sprintf(buf, "%ld\n", (long)getpid());
+ len = snprintf(buf, sizeof(buf), "%ld\n", (long)getpid());
if (write(fd, buf, len) != len)
barf_perror("Writing pid file %s", pidfile);
}
talloc_set_destructor(trans, destroy_transaction);
conn->transaction_started++;
- sprintf(id_str, "%u", trans->id);
+ snprintf(id_str, sizeof(id_str), "%u", trans->id);
send_reply(conn, XS_TRANSACTION_START, id_str, strlen(id_str)+1);
}
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <sys/uio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <string.h>
for (i = 0; i < num_perms; i++) {
char buffer[MAX_STRLEN(unsigned int)+1];
- if (!xs_perm_to_string(&perms[i], buffer))
+ if (!xs_perm_to_string(&perms[i], buffer, sizeof(buffer)))
goto unwind;
iov[i+1].iov_base = strdup(buffer);
char eventchn_str[MAX_STRLEN(eventchn)];
struct iovec iov[3];
- sprintf(domid_str, "%u", domid);
- sprintf(mfn_str, "%lu", mfn);
- sprintf(eventchn_str, "%u", eventchn);
+ snprintf(domid_str, sizeof(domid_str), "%u", domid);
+ snprintf(mfn_str, sizeof(mfn_str), "%lu", mfn);
+ snprintf(eventchn_str, sizeof(eventchn_str), "%u", eventchn);
iov[0].iov_base = domid_str;
iov[0].iov_len = strlen(domid_str) + 1;
{
char domid_str[MAX_STRLEN(domid)];
- sprintf(domid_str, "%u", domid);
+ snprintf(domid_str, sizeof(domid_str), "%u", domid);
return xs_single(h, XBT_NULL, type, domid_str, NULL);
}
{
char domid_str[MAX_STRLEN(domid)];
- sprintf(domid_str, "%u", domid);
+ snprintf(domid_str, sizeof(domid_str), "%u", domid);
return xs_single(h, XBT_NULL, XS_GET_DOMAIN_PATH, domid_str, NULL);
}
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "xs_lib.h"
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
+#include "xs_lib.h"
/* Common routines for the Xen store daemon and client library. */
const char *xs_daemon_tdb(void)
{
static char buf[PATH_MAX];
- sprintf(buf, "%s/tdb", xs_daemon_rootdir());
+ snprintf(buf, sizeof(buf), "%s/tdb", xs_daemon_rootdir());
return buf;
}
}
/* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */
-bool xs_perm_to_string(const struct xs_permissions *perm, char *buffer)
+bool xs_perm_to_string(const struct xs_permissions *perm,
+ char *buffer, size_t buf_len)
{
switch (perm->perms) {
case XS_PERM_WRITE:
errno = EINVAL;
return false;
}
- sprintf(buffer+1, "%i", (int)perm->id);
+ snprintf(buffer+1, buf_len-1, "%i", (int)perm->id);
return true;
}
const char *strings);
/* Convert permissions to a string (up to len MAX_STRLEN(unsigned int)+1). */
-bool xs_perm_to_string(const struct xs_permissions *perm, char *buffer);
+bool xs_perm_to_string(const struct xs_permissions *perm,
+ char *buffer, size_t buf_len);
/* Given a string and a length, count how many strings (nul terms). */
unsigned int xs_count_strings(const char *strings, unsigned int len);
for (i = 0; i < nperms; i++) {
if (i)
putchar(',');
- xs_perm_to_string(perms+i, buf);
+ xs_perm_to_string(perms+i, buf, sizeof(buf));
fputs(buf, stdout);
}
putchar(')');