From 82bdf6d5ae69dc7680ff7a710711bc5ecdefe2b7 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Mon, 3 Aug 2009 13:53:26 +0200 Subject: [PATCH] Fix phyp escape_specialcharacters. A couple of minor fixes to phyp escape_specialcharacters. Make it a static function (since it's only used in phyp/phyp_driver.c), and make it take a dstlen parameter. This paves the way for removing strncpy in the future. Signed-off-by: Chris Lalancette --- src/phyp/phyp_driver.c | 10 ++++++---- src/phyp/phyp_driver.h | 2 -- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index cbfd31b248..f457cf4669 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -53,6 +53,8 @@ #define VIR_FROM_THIS VIR_FROM_PHYP +static int escape_specialcharacters(char *src, char *dst, size_t dstlen); + /* * URI: phyp://user@[hmc|ivm]/managed_system * */ @@ -94,7 +96,7 @@ phypOpen(virConnectPtr conn, return VIR_DRV_OPEN_ERROR; } - if (escape_specialcharacters(conn->uri->path, string) == -1) { + if (escape_specialcharacters(conn->uri->path, string, sizeof(string)) == -1) { virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP, VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s", _("Error parsing 'path'. Invalid characters.")); @@ -1341,8 +1343,8 @@ init_uuid_db(virConnectPtr conn) return; } -int -escape_specialcharacters(char *src, char *dst) +static int +escape_specialcharacters(char *src, char *dst, size_t dstlen) { size_t len = strlen(src); char temp_buffer[len]; @@ -1367,7 +1369,7 @@ escape_specialcharacters(char *src, char *dst) } temp_buffer[j] = '\0'; - if (strncpy(dst, temp_buffer, j) == NULL) + if (strncpy(dst, temp_buffer, dstlen) == NULL) return -1; return 0; diff --git a/src/phyp/phyp_driver.h b/src/phyp/phyp_driver.h index fd824b33bd..f16b6fee6b 100644 --- a/src/phyp/phyp_driver.h +++ b/src/phyp/phyp_driver.h @@ -62,5 +62,3 @@ char *phypGetBackingDevice(virConnectPtr conn, const char *managed_system, int phypDiskType(virConnectPtr conn, char *backing_device); SSH_SESSION *openSSHSession(virConnectPtr conn, virConnectAuthPtr auth); - -int escape_specialcharacters(char *src, char *dst); -- GitLab