summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik de Castro Lopo <erikd@mega-nerd.com>2014-10-29 20:56:12 -0700
committerErik de Castro Lopo <erikd@mega-nerd.com>2014-10-29 20:56:12 -0700
commit1d0ff7edd41b1da62c68a339adfca6480e13497e (patch)
tree373a072b2930877474238b2f1d1035ffe26ca4ad
parent7da769461c56177ee4ffcb90b555019507c5d172 (diff)
src/sndfile.c : Return an error if the file path is too long.
-rw-r--r--src/common.h2
-rw-r--r--src/sndfile.c18
2 files changed, 15 insertions, 5 deletions
diff --git a/src/common.h b/src/common.h
index f421ce4..304c573 100644
--- a/src/common.h
+++ b/src/common.h
@@ -712,8 +712,8 @@ enum
SFE_BAD_CHUNK_FORMAT,
SFE_BAD_CHUNK_MARKER,
SFE_BAD_CHUNK_DATA_PTR,
-
SFE_ALAC_FAIL_TMPFILE,
+ SFE_FILENAME_TOO_LONG,
SFE_MAX_ERROR /* This must be last in list. */
} ;
diff --git a/src/sndfile.c b/src/sndfile.c
index 6565b02..73ca625 100644
--- a/src/sndfile.c
+++ b/src/sndfile.c
@@ -261,6 +261,8 @@ ErrorStruct SndfileErrors [] =
{ SFE_BAD_CHUNK_FORMAT , "Error : Reading/writing chunks from this file format is not supported." },
{ SFE_BAD_CHUNK_MARKER , "Error : Bad chunk marker." },
{ SFE_BAD_CHUNK_DATA_PTR , "Error : Bad data pointer in SF_CHUNK_INFO struct." },
+ { SFE_FILENAME_TOO_LONG , "Error : Supplied filename too long." },
+
{ SFE_MAX_ERROR , "Maximum error number." },
{ SFE_MAX_ERROR + 1 , NULL }
@@ -274,7 +276,7 @@ static int guess_file_type (SF_PRIVATE *psf) ;
static int validate_sfinfo (SF_INFO *sfinfo) ;
static int validate_psf (SF_PRIVATE *psf) ;
static void save_header_info (SF_PRIVATE *psf) ;
-static void copy_filename (SF_PRIVATE *psf, const char *path) ;
+static int copy_filename (SF_PRIVATE *psf, const char *path) ;
static int psf_close (SF_PRIVATE *psf) ;
static int try_resource_fork (SF_PRIVATE * psf) ;
@@ -328,7 +330,10 @@ sf_open (const char *path, int mode, SF_INFO *sfinfo)
psf_log_printf (psf, "File : %s\n", path) ;
- copy_filename (psf, path) ;
+ if (copy_filename (psf, path) != 0)
+ { sf_errno = psf->error ;
+ return NULL ;
+ } ;
psf->file.mode = mode ;
if (strcmp (path, "-") == 0)
@@ -2590,11 +2595,16 @@ save_header_info (SF_PRIVATE *psf)
{ snprintf (sf_parselog, sizeof (sf_parselog), "%s", psf->parselog.buf) ;
} /* save_header_info */
-static void
+static int
copy_filename (SF_PRIVATE *psf, const char *path)
{ const char *ccptr ;
char *cptr ;
+ if (strlen (path) > 1 && strlen (path) - 1 >= sizeof (psf->file.path.c))
+ { psf->error = SFE_FILENAME_TOO_LONG ;
+ return psf->error ;
+ } ;
+
snprintf (psf->file.path.c, sizeof (psf->file.path.c), "%s", path) ;
if ((ccptr = strrchr (path, '/')) || (ccptr = strrchr (path, '\\')))
ccptr ++ ;
@@ -2610,7 +2620,7 @@ copy_filename (SF_PRIVATE *psf, const char *path)
else
psf->file.dir.c [0] = 0 ;
- return ;
+ return 0 ;
} /* copy_filename */
/*==============================================================================