diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-03-27 02:52:59 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-03-27 02:52:59 +0000 |
commit | 53f728a0aec357f22f04af2d8cceccac8ff4237b (patch) | |
tree | d9155666d0311bb103fe564aff7ba935489b5322 | |
parent | 12d19cccd284457be9f5be8fcdac5b9d9b894b3f (diff) | |
download | mpd-53f728a0aec357f22f04af2d8cceccac8ff4237b.tar.gz mpd-53f728a0aec357f22f04af2d8cceccac8ff4237b.tar.xz mpd-53f728a0aec357f22f04af2d8cceccac8ff4237b.zip |
just to be carfile, make sure to null terminate when using strncpy
git-svn-id: https://svn.musicpd.org/mpd/trunk@506 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/decode.c | 8 | ||||
-rw-r--r-- | src/main.c | 8 | ||||
-rw-r--r-- | src/player.c | 5 |
3 files changed, 19 insertions, 2 deletions
diff --git a/src/decode.c b/src/decode.c index ac4fcb08a..5ae2133c6 100644 --- a/src/decode.c +++ b/src/decode.c @@ -116,6 +116,7 @@ int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc, if(dc->start || dc->error!=DECODE_ERROR_NOERROR) { strncpy(pc->erroredFile,pc->file,MAXPATHLEN); + pc->erroredFile[MAXPATHLEN] = '\0'; pc->error = PLAYER_ERROR_FILE; quitDecode(pc,dc); return -1; @@ -123,6 +124,7 @@ int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc, if(initAudio(af)<0) { strncpy(pc->erroredFile,pc->file,MAXPATHLEN); + pc->erroredFile[MAXPATHLEN] = '\0'; pc->error = PLAYER_ERROR_AUDIO; quitDecode(pc,dc); return -1; @@ -184,6 +186,7 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc, else { \ if(initAudio(NULL)<0) { \ strncpy(pc->erroredFile,pc->file,MAXPATHLEN); \ + pc->erroredFile[MAXPATHLEN] = '\0' \ pc->error = PLAYER_ERROR_AUDIO; \ quitDecode(pc,dc); \ return; \ @@ -221,6 +224,7 @@ int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af, while(1) { if(dc->start) { strncpy(dc->file,pc->file,MAXPATHLEN); + dc->file[MAXPATHLEN] = '\0'; switch(pc->decodeType) { #ifdef HAVE_MAD case DECODE_TYPE_MP3: @@ -252,6 +256,9 @@ int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af, #endif default: ret = DECODE_ERROR_UNKTYPE; + strncpy(pc->erroredFile,dc->file, + MAXPATHLEN); + pc->erroredFile[MAXPATHLEN] = '\0'; } if(ret<0) { dc->error = DECODE_ERROR_FILE; @@ -273,6 +280,7 @@ int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af, } else if(pid<0) { strncpy(pc->erroredFile,pc->file,MAXPATHLEN); + pc->erroredFile[MAXPATHLEN] = '\0'; pc->error = PLAYER_ERROR_SYSTEM; return -1; } diff --git a/src/main.c b/src/main.c index 6fbb14d0b..ef6cf3a5e 100644 --- a/src/main.c +++ b/src/main.c @@ -331,11 +331,15 @@ int main(int argc, char * argv[]) { initTables(); initPlaylist(); - if(!options.dbFile) { + if(!options.dbFile) { strncpy(directorydb,playlistDir,MAXPATHLEN); + directorydb[MAXPATHLEN] = '\0'; strncat(directorydb,"/.mpddb",MAXPATHLEN-strlen(playlistDir)); } - else strncpy(directorydb,options.dbFile,MAXPATHLEN); + else { + strncpy(directorydb,options.dbFile,MAXPATHLEN); + directorydb[MAXPATHLEN] = '\0'; + } if(options.createDB>0 || readDirectoryDB()<0) { if(options.createDB<0) { ERROR("can't open db file and using \"--no-create-db\"" diff --git a/src/player.c b/src/player.c index 1685837fa..19693c2c3 100644 --- a/src/player.c +++ b/src/player.c @@ -182,6 +182,7 @@ int playerPlay(FILE * fp, char * utf8file) { struct stat st; if(stat(rmp2amp(utf8ToFsCharset(utf8file)),&st)<0) { strncpy(pc->erroredFile,pc->file,MAXPATHLEN); + pc->erroredFile[MAXPATHLEN] = '\0'; pc->error = PLAYER_ERROR_FILENOTFOUND; return 0; } @@ -190,12 +191,14 @@ int playerPlay(FILE * fp, char * utf8file) { decodeType = playerGetDecodeType(utf8file); if(decodeType < 0) { strncpy(pc->erroredFile,pc->file,MAXPATHLEN); + pc->erroredFile[MAXPATHLEN] = '\0'; pc->error = PLAYER_ERROR_UNKTYPE; return 0; } pc->decodeType = decodeType; strncpy(pc->file,rmp2amp(utf8ToFsCharset(utf8file)),MAXPATHLEN); + pc->file[MAXPATHLEN] = '\0'; pc->play = 1; if(player_pid==0 && playerInit()<0) { @@ -327,6 +330,7 @@ int queueSong(char * utf8file) { if(pc->queueState==PLAYER_QUEUE_BLANK) { strncpy(pc->file,rmp2amp(utf8ToFsCharset(utf8file)),MAXPATHLEN); + pc->file[MAXPATHLEN] = '\0'; decodeType = playerGetDecodeType(utf8file); if(decodeType < 0) return -1; @@ -393,6 +397,7 @@ int playerSeek(FILE * fp, char * utf8file, float time) { pc->decodeType = decodeType; strncpy(pc->file,file,MAXPATHLEN); + pc->file[MAXPATHLEN] = '\0'; } if(pc->error==PLAYER_ERROR_NOERROR) { |