diff options
author | Eric Wong <normalperson@yhbt.net> | 2006-07-30 10:31:41 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2006-07-30 10:31:41 +0000 |
commit | 263a9d583a74a94fef652bb40f4035b9c0c1612e (patch) | |
tree | 52f15e2c2d0e60e87bb1a135c55e4345e2511f2f /src/decode.c | |
parent | 4144afe551eca63366316c013019bce9ad81bc94 (diff) | |
download | mpd-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 'src/decode.c')
-rw-r--r-- | src/decode.c | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/src/decode.c b/src/decode.c index 8eacddb07..144edd70f 100644 --- a/src/decode.c +++ b/src/decode.c @@ -112,9 +112,7 @@ static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) { \ decodeWaitedOn = 0; \ if(openAudioDevice(&(cb->audioFormat))<0) { \ - strncpy(pc->erroredUrl, pc->utf8url, \ - MAXPATHLEN); \ - pc->erroredUrl[MAXPATHLEN] = '\0'; \ + pathcpy_trunc(pc->erroredUrl, pc->utf8url); \ pc->error = PLAYER_ERROR_AUDIO; \ ERROR("problems opening audio device while playing \"%s\"\n", pc->utf8url); \ quitDecode(pc,dc); \ @@ -129,8 +127,7 @@ static int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) cb->audioFormat.sampleRate; \ } \ else if(dc->state!=DECODE_STATE_START || decode_pid <= 0) { \ - strncpy(pc->erroredUrl, pc->utf8url, MAXPATHLEN); \ - pc->erroredUrl[MAXPATHLEN] = '\0'; \ + pathcpy_trunc(pc->erroredUrl, pc->utf8url); \ pc->error = PLAYER_ERROR_FILE; \ quitDecode(pc,dc); \ return; \ @@ -145,15 +142,13 @@ static int waitOnDecode(PlayerControl * pc, DecoderControl * dc, OutputBuffer * cb, int *decodeWaitedOn) { MpdTag *tag = NULL; - strncpy(pc->currentUrl, pc->utf8url, MAXPATHLEN); - pc->currentUrl[MAXPATHLEN] = '\0'; + pathcpy_trunc(pc->currentUrl, pc->utf8url); while (decode_pid > 0 && dc->start) my_usleep(10000); if (dc->start || dc->error != DECODE_ERROR_NOERROR) { - strncpy(pc->erroredUrl, pc->utf8url, MAXPATHLEN); - pc->erroredUrl[MAXPATHLEN] = '\0'; + pathcpy_trunc(pc->erroredUrl, pc->utf8url); pc->error = PLAYER_ERROR_FILE; quitDecode(pc, dc); return -1; @@ -229,9 +224,7 @@ static int decodeSeek(PlayerControl * pc, DecoderControl * dc, if(pause) pc->state = PLAYER_STATE_PAUSE; \ else { \ if(openAudioDevice(NULL)<0) { \ - strncpy(pc->erroredUrl, pc->utf8url, \ - MAXPATHLEN); \ - pc->erroredUrl[MAXPATHLEN] = '\0'; \ + pathcpy_trunc(pc->erroredUrl, pc->utf8url); \ pc->error = PLAYER_ERROR_AUDIO; \ ERROR("problems opening audio device while playing \"%s\"\n", pc->utf8url); \ quitDecode(pc,dc); \ @@ -286,8 +279,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, copyMpdTagToOutputBuffer(cb, NULL); - strncpy(dc->utf8url, pc->utf8url, MAXPATHLEN); - dc->utf8url[MAXPATHLEN] = '\0'; + pathcpy_trunc(dc->utf8url, pc->utf8url); if (openInputStream(&inStream, path) < 0) { dc->error = DECODE_ERROR_FILE; @@ -396,8 +388,7 @@ static void decodeStart(PlayerControl * pc, OutputBuffer * cb, } if (ret < 0 || ret == DECODE_ERROR_UNKTYPE) { - strncpy(pc->erroredUrl, dc->utf8url, MAXPATHLEN); - pc->erroredUrl[MAXPATHLEN] = '\0'; + pathcpy_trunc(pc->erroredUrl, dc->utf8url); if (ret != DECODE_ERROR_UNKTYPE) dc->error = DECODE_ERROR_FILE; else { @@ -439,8 +430,7 @@ static int decoderInit(PlayerControl * pc, OutputBuffer * cb, /* END OF CHILD */ } else if (decode_pid < 0) { unblockSignals(); - strncpy(pc->erroredUrl, pc->utf8url, MAXPATHLEN); - pc->erroredUrl[MAXPATHLEN] = '\0'; + pathcpy_trunc(pc->erroredUrl, pc->utf8url); pc->error = PLAYER_ERROR_SYSTEM; return -1; } |