aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputStream_http.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2006-07-30 10:31:41 +0000
committerEric Wong <normalperson@yhbt.net>2006-07-30 10:31:41 +0000
commit263a9d583a74a94fef652bb40f4035b9c0c1612e (patch)
tree52f15e2c2d0e60e87bb1a135c55e4345e2511f2f /src/inputStream_http.c
parent4144afe551eca63366316c013019bce9ad81bc94 (diff)
downloadmpd-263a9d583a74a94fef652bb40f4035b9c0c1612e.tar.gz
mpd-263a9d583a74a94fef652bb40f4035b9c0c1612e.tar.xz
mpd-263a9d583a74a94fef652bb40f4035b9c0c1612e.zip
remove clumsy strncpy use
strncpy isn't really safe because it doesn't guarantee null termination, and we have had to work around it in several places. strlcpy (from OpenBSD) isn't great, either because it often leaves errors going unchecked (by truncating strings). So we'll add the pathcpy_trunc() function with is basically strlcpy with a hardcoded MAXPATHLEN as the limit, and we'll acknowledge truncation since we only work on paths and MAXPATHLEN should be set correctly by the system headers[1]. file-specific notes: inputStream_http: eyeballing the changes here, it seems to look alright but I haven't actually tested it myself. ls: don't even bother printing a file if the filename is too long (and when is it ever?) since we won't be able to read it anyways. metadataChunk: it's only metadata, and it's only for showin the user, so truncating it here souldn't be a big issue. memset to zero in init is unecessary, so lets not waste cycles [1] - If the system headers are screwed up, then we're majorly screwed regardless of what we do :x git-svn-id: https://svn.musicpd.org/mpd/trunk@4491 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/inputStream_http.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/inputStream_http.c b/src/inputStream_http.c
index b4b6d04f2..969d2a0ea 100644
--- a/src/inputStream_http.c
+++ b/src/inputStream_http.c
@@ -306,15 +306,15 @@ static int parseUrl(InputStreamHTTPData * data, char *url)
if (colon && colon < at) {
user = malloc(colon - temp + 1);
- strncpy(user, temp, colon - temp);
+ memcpy(user, temp, colon - temp);
user[colon - temp] = '\0';
passwd = malloc(at - colon);
- strncpy(passwd, colon + 1, at - colon - 1);
+ memcpy(passwd, colon + 1, at - colon - 1);
passwd[at - colon - 1] = '\0';
} else {
user = malloc(at - temp + 1);
- strncpy(user, temp, at - temp);
+ memcpy(user, temp, at - temp);
user[at - temp] = '\0';
passwd = strdup("");
@@ -346,7 +346,7 @@ static int parseUrl(InputStreamHTTPData * data, char *url)
return -1;
data->host = malloc(len);
- strncpy(data->host, temp, len - 1);
+ memcpy(data->host, temp, len - 1);
data->host[len - 1] = '\0';
/* fetch the port */
if (colon && (!slash || slash != colon + 1)) {
@@ -354,7 +354,7 @@ static int parseUrl(InputStreamHTTPData * data, char *url)
if (slash)
len -= strlen(slash);
data->port = malloc(len + 1);
- strncpy(data->port, colon + 1, len);
+ memcpy(data->port, colon + 1, len);
data->port[len] = '\0';
DEBUG(__FILE__ ": Port: %s\n", data->port);
} else {