]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed lib soname.
authorYann Collet <cyan@fb.com>
Fri, 9 Dec 2016 02:25:36 +0000 (18:25 -0800)
committerYann Collet <cyan@fb.com>
Fri, 9 Dec 2016 02:26:56 +0000 (18:26 -0800)
example : simple_compression : size overflow check

NEWS
examples/simple_compression.c
lib/Makefile

diff --git a/NEWS b/NEWS
index b4a200ad66032da1670219c1559018b596017df1..f6f1ad90bffb767c79e249599285fa990d1bd2f8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,7 +5,8 @@ cli : new : preserve file attributes
 cli : new : added zstdless and zstdgrep tools
 cli : fixed : status displays total amount decoded, even for file consisting of multiple frames (like pzstd)
 cli : fixed : zstdcat
-library : changed : only public ZSTD_ symbols are now exposed
+lib : changed : only public ZSTD_ symbols are now exposed
+lib : fixed : soname
 API : changed : zbuff prototypes now generate deprecation warnings
 API : changed : streaming decompression implicit reset on starting new frame
 API : added experimental : dictID retrieval functions
index 332ce721bf2dc91a5bc708f47ac59a5c8691faaf..deb0bbfc491bb542faae6d0e63517edf1261d7c2 100644 (file)
@@ -8,9 +8,9 @@
 
 
 
-#include <stdlib.h>    // malloc, exit
-#include <stdio.h>     // fprintf, perror
-#include <string.h>    // strerror
+#include <stdlib.h>    // malloc, free, exit
+#include <stdio.h>     // fprintf, perror, fopen, etc.
+#include <string.h>    // strlen, strcat, memset, strerror
 #include <errno.h>     // errno
 #include <sys/stat.h>  // stat
 #include <zstd.h>      // presumes zstd library is installed
@@ -45,13 +45,18 @@ static void* malloc_orDie(size_t size)
 
 static void* loadFile_orDie(const char* fileName, size_t* size)
 {
-    off_t const buffSize = fsize_orDie(fileName);
+    off_t const fileSize = fsize_orDie(fileName);
+    size_t const buffSize = (size_t)fileSize;
+    if ((off_t)buffSize < fileSize) {   /* narrowcast overflow */
+        fprintf(stderr, "%s : filesize too large \n", fileName);
+        exit(4);
+    }
     FILE* const inFile = fopen_orDie(fileName, "rb");
     void* const buffer = malloc_orDie(buffSize);
     size_t const readSize = fread(buffer, 1, buffSize, inFile);
     if (readSize != (size_t)buffSize) {
         fprintf(stderr, "fread: %s : %s \n", fileName, strerror(errno));
-        exit(4);
+        exit(5);
     }
     fclose(inFile);  /* can't fail, read only */
     *size = buffSize;
@@ -65,11 +70,11 @@ static void saveFile_orDie(const char* fileName, const void* buff, size_t buffSi
     size_t const wSize = fwrite(buff, 1, buffSize, oFile);
     if (wSize != (size_t)buffSize) {
         fprintf(stderr, "fwrite: %s : %s \n", fileName, strerror(errno));
-        exit(5);
+        exit(6);
     }
     if (fclose(oFile)) {
         perror(fileName);
-        exit(6);
+        exit(7);
     }
 }
 
@@ -84,7 +89,7 @@ static void compress_orDie(const char* fname, const char* oname)
     size_t const cSize = ZSTD_compress(cBuff, cBuffSize, fBuff, fSize, 1);
     if (ZSTD_isError(cSize)) {
         fprintf(stderr, "error compressing %s : %s \n", fname, ZSTD_getErrorName(cSize));
-        exit(7);
+        exit(8);
     }
 
     saveFile_orDie(oname, cBuff, cSize);
index 44c64b8edcf889f54e40cf9d560ea7fbea9271a0..21a805d05ada437880ec010e6a7571cb0e8a6408 100644 (file)
@@ -47,9 +47,9 @@ ifeq ($(shell uname), Darwin)
        SHARED_EXT = dylib
        SHARED_EXT_MAJOR = $(LIBVER_MAJOR).$(SHARED_EXT)
        SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
-       SONAME_FLAGS = -install_name $(PREFIX)/lib/$@.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
+       SONAME_FLAGS = -install_name $(PREFIX)/lib/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
 else
-       SONAME_FLAGS = -Wl,-soname=$@.$(SHARED_EXT).$(LIBVER_MAJOR)
+       SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
        SHARED_EXT = so
        SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
        SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)