Ver Fonte

Replaced sprintf() calls with snprintf().

Ryan C. Gordon há 8 anos atrás
pai
commit
f8ed5c6f7e
3 ficheiros alterados com 7 adições e 7 exclusões
  1. 4 3
      src/archiver_dir.c
  2. 2 3
      src/physfs.c
  3. 1 1
      src/platform_windows.c

+ 4 - 3
src/archiver_dir.c

@@ -13,10 +13,11 @@
 
 
 
 
 
 
-static char *cvtToDependent(const char *prepend, const char *path, char *buf)
+static char *cvtToDependent(const char *prepend, const char *path,
+                            char *buf, const size_t buflen)
 {
 {
     BAIL_IF(buf == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
     BAIL_IF(buf == NULL, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
-    sprintf(buf, "%s%s", prepend ? prepend : "", path);
+    snprintf(buf, buflen, "%s%s", prepend ? prepend : "", path);
 
 
     if (__PHYSFS_platformDirSeparator != '/')
     if (__PHYSFS_platformDirSeparator != '/')
     {
     {
@@ -31,7 +32,7 @@ static char *cvtToDependent(const char *prepend, const char *path, char *buf)
 
 
 #define CVT_TO_DEPENDENT(buf, pre, dir) { \
 #define CVT_TO_DEPENDENT(buf, pre, dir) { \
     const size_t len = ((pre) ? strlen((char *) pre) : 0) + strlen(dir) + 1; \
     const size_t len = ((pre) ? strlen((char *) pre) : 0) + strlen(dir) + 1; \
-    buf = cvtToDependent((char*)pre,dir,(char*)__PHYSFS_smallAlloc(len)); \
+    buf = cvtToDependent((char*)pre,dir,(char*)__PHYSFS_smallAlloc(len),len); \
 }
 }
 
 
 
 

+ 2 - 3
src/physfs.c

@@ -9,7 +9,6 @@
  */
  */
 
 
 /* !!! FIXME: ERR_PAST_EOF shouldn't trigger for reads. Just return zero. */
 /* !!! FIXME: ERR_PAST_EOF shouldn't trigger for reads. Just return zero. */
-/* !!! FIXME: use snprintf(), not sprintf(). */
 
 
 #define __PHYSICSFS_INTERNAL__
 #define __PHYSICSFS_INTERNAL__
 #include "physfs_internal.h"
 #include "physfs_internal.h"
@@ -1831,7 +1830,7 @@ static void setSaneCfgAddPath(const char *i, const size_t l, const char *dirsep,
     char *str = (char *) __PHYSFS_smallAlloc(allocsize);
     char *str = (char *) __PHYSFS_smallAlloc(allocsize);
     if (str != NULL)
     if (str != NULL)
     {
     {
-        sprintf(str, "%s%s%s", d, dirsep, i);
+        snprintf(str, allocsize, "%s%s%s", d, dirsep, i);
         PHYSFS_mount(str, NULL, archivesFirst == 0);
         PHYSFS_mount(str, NULL, archivesFirst == 0);
         __PHYSFS_smallFree(str);
         __PHYSFS_smallFree(str);
     } /* if */
     } /* if */
@@ -2272,7 +2271,7 @@ static void enumCallbackFilterSymLinks(void *_data, const char *origdir,
         const DirHandle *dh = data->dirhandle;
         const DirHandle *dh = data->dirhandle;
         PHYSFS_Stat statbuf;
         PHYSFS_Stat statbuf;
 
 
-        sprintf(path, "%s%s%s", trimmedDir, *trimmedDir ? "/" : "", fname);
+        snprintf(path, slen, "%s%s%s", trimmedDir, *trimmedDir ? "/" : "", fname);
         if (dh->funcs->stat(dh->opaque, path, &statbuf))
         if (dh->funcs->stat(dh->opaque, path, &statbuf))
         {
         {
             /* Pass it on to the application if it's not a symlink. */
             /* Pass it on to the application if it's not a symlink. */

+ 1 - 1
src/platform_windows.c

@@ -413,7 +413,7 @@ char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
         BAIL(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
         BAIL(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
     } /* if */
     } /* if */
 
 
-    sprintf(retval, "%s\\%s\\%s\\", utf8, org, app);
+    snprintf(retval, len, "%s\\%s\\%s\\", utf8, org, app);
     allocator.Free(utf8);
     allocator.Free(utf8);
     return retval;
     return retval;
 } /* __PHYSFS_platformCalcPrefDir */
 } /* __PHYSFS_platformCalcPrefDir */