safer file name copies

git-svn-id: https://vgmstream.svn.sourceforge.net/svnroot/vgmstream@990 51a99a44-fe44-0410-b1ba-c3e57ba2b86b
This commit is contained in:
halleyscometsw 2012-08-21 15:34:10 +00:00
parent 5a042c79ec
commit 98ebe15f45
2 changed files with 12 additions and 6 deletions

View File

@ -123,7 +123,8 @@ static off_t get_offset_stdio(STDIOSTREAMFILE *streamFile) {
} }
static void get_name_stdio(STDIOSTREAMFILE *streamfile,char *buffer,size_t length) { static void get_name_stdio(STDIOSTREAMFILE *streamfile,char *buffer,size_t length) {
strcpy(buffer,streamfile->name); strncpy(buffer,streamfile->name,length);
buffer[length-1]='\0';
} }
#ifdef PROFILE_STREAMFILE #ifdef PROFILE_STREAMFILE
@ -190,7 +191,8 @@ static STREAMFILE * open_stdio_streamfile_buffer_by_FILE(FILE *infile,const char
streamfile->buffersize = buffersize; streamfile->buffersize = buffersize;
streamfile->buffer = buffer; streamfile->buffer = buffer;
strcpy(streamfile->name,filename); strncpy(streamfile->name,filename,sizeof(streamfile->name));
streamfile->name[sizeof(streamfile->name)-1] = '\0';
return &streamfile->sf; return &streamfile->sf;
} }

View File

@ -65,12 +65,14 @@ static size_t get_offset_vfs(VFSSTREAMFILE *streamfile)
static void get_name_vfs(VFSSTREAMFILE *streamfile,char *buffer,size_t length) static void get_name_vfs(VFSSTREAMFILE *streamfile,char *buffer,size_t length)
{ {
strcpy(buffer,streamfile->name); strncpy(buffer,streamfile->name,length);
buffer[length-1]='\0';
} }
static void get_realname_vfs(VFSSTREAMFILE *streamfile,char *buffer,size_t length) static void get_realname_vfs(VFSSTREAMFILE *streamfile,char *buffer,size_t length)
{ {
strcpy(buffer,streamfile->realname); strncpy(buffer,streamfile->realname,length);
buffer[length-1]='\0';
} }
static STREAMFILE *open_vfs_by_VFSFILE(VFSFile *file,const char *path); static STREAMFILE *open_vfs_by_VFSFILE(VFSFile *file,const char *path);
@ -119,10 +121,12 @@ static STREAMFILE *open_vfs_by_VFSFILE(VFSFile *file,const char *path)
streamfile->vfsFile = file; streamfile->vfsFile = file;
streamfile->offset = 0; streamfile->offset = 0;
strcpy(streamfile->name,path); strncpy(streamfile->name,path,sizeof(streamfile->name));
streamfile->name[sizeof(streamfile->name)-1] = '\0';
{ {
gchar* realname = g_filename_from_uri(path,NULL,NULL); gchar* realname = g_filename_from_uri(path,NULL,NULL);
strcpy(streamfile->realname,realname); strncpy(streamfile->realname,realname,sizeof(streamfile->realname));
streamfile->realname[sizeof(streamfile->realname)-1] = '\0';
g_free(realname); g_free(realname);
} }