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 <clalance@redhat.com>
This commit is contained in:
Chris Lalancette 2009-08-03 13:53:26 +02:00
parent 701477e8c3
commit 82bdf6d5ae
2 changed files with 6 additions and 6 deletions

View File

@ -53,6 +53,8 @@
#define VIR_FROM_THIS VIR_FROM_PHYP #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 * URI: phyp://user@[hmc|ivm]/managed_system
* */ * */
@ -94,7 +96,7 @@ phypOpen(virConnectPtr conn,
return VIR_DRV_OPEN_ERROR; 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, virRaiseError(conn, NULL, NULL, 0, VIR_FROM_PHYP,
VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s", VIR_ERR_ERROR, NULL, NULL, NULL, 0, 0, "%s",
_("Error parsing 'path'. Invalid characters.")); _("Error parsing 'path'. Invalid characters."));
@ -1341,8 +1343,8 @@ init_uuid_db(virConnectPtr conn)
return; return;
} }
int static int
escape_specialcharacters(char *src, char *dst) escape_specialcharacters(char *src, char *dst, size_t dstlen)
{ {
size_t len = strlen(src); size_t len = strlen(src);
char temp_buffer[len]; char temp_buffer[len];
@ -1367,7 +1369,7 @@ escape_specialcharacters(char *src, char *dst)
} }
temp_buffer[j] = '\0'; temp_buffer[j] = '\0';
if (strncpy(dst, temp_buffer, j) == NULL) if (strncpy(dst, temp_buffer, dstlen) == NULL)
return -1; return -1;
return 0; return 0;

View File

@ -62,5 +62,3 @@ char *phypGetBackingDevice(virConnectPtr conn, const char *managed_system,
int phypDiskType(virConnectPtr conn, char *backing_device); int phypDiskType(virConnectPtr conn, char *backing_device);
SSH_SESSION *openSSHSession(virConnectPtr conn, virConnectAuthPtr auth); SSH_SESSION *openSSHSession(virConnectPtr conn, virConnectAuthPtr auth);
int escape_specialcharacters(char *src, char *dst);