]> granicus.if.org Git - php/commitdiff
Fix the wrong use of snprintf which is introduced in 1d2f61904987133d542c68cd349cf313...
authorXinchen Hui <laruence@php.net>
Mon, 10 Sep 2012 15:08:54 +0000 (23:08 +0800)
committerXinchen Hui <laruence@php.net>
Mon, 10 Sep 2012 15:08:54 +0000 (23:08 +0800)
ext/fileinfo/libmagic.patch
ext/fileinfo/libmagic/apprentice.c

index 30364fb978c6064a517514d416693c56650bc8fb..1fc656ef1e9f88833aa75ac4f230390e52edd188 100644 (file)
@@ -316,8 +316,6 @@ diff -u libmagic.origin/apprentice.c libmagic/apprentice.c
  apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
      const char *fn, int action)
  {
--      int errs = 0;
-+      int errs = 0, mflen = 0;
        struct magic_entry *marray;
        uint32_t marraycount, i, mentrycount = 0, starttest;
 -      size_t slen, files = 0, maxfiles = 0;
@@ -356,7 +354,7 @@ diff -u libmagic.origin/apprentice.c libmagic/apprentice.c
                }
                while ((d = readdir(dir)) != NULL) {
 -                      if (asprintf(&mfn, "%s/%s", fn, d->d_name) < 0) {
-+                      if ((mflen = snprintf(mfn, sizeof(mfn), "%s/%s", fn, d->d_name)) < 0) {
++                      if (snprintf(mfn, sizeof(mfn), "%s/%s", fn, d->d_name) < 0) {
                                file_oomem(ms,
                                    strlen(fn) + strlen(d->d_name) + 2);
                                errs++;
@@ -379,7 +377,7 @@ diff -u libmagic.origin/apprentice.c libmagic/apprentice.c
                                }
                        }
 -                      filearr[files++] = mfn;
-+                      filearr[files++] = estrndup(mfn, mflen);
++                      filearr[files++] = estrndup(mfn);
                }
                closedir(dir);
                qsort(filearr, files, sizeof(*filearr), cmpstrp);
index 98bde27a2d78415d4a64e5e2755c3346ff969a44..f5f99395a36704366b230f88e43972d1a89ff2b4 100644 (file)
@@ -753,7 +753,7 @@ private int
 apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
     const char *fn, int action)
 {
-       int errs = 0, mflen = 0;
+       int errs = 0;
        struct magic_entry *marray;
        uint32_t marraycount, i, mentrycount = 0, starttest;
        size_t files = 0, maxfiles = 0;
@@ -782,7 +782,7 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
                        goto out;
                }
                while ((d = readdir(dir)) != NULL) {
-                       if ((mflen = snprintf(mfn, sizeof(mfn), "%s/%s", fn, d->d_name)) < 0) {
+                       if (snprintf(mfn, sizeof(mfn), "%s/%s", fn, d->d_name) < 0) {
                                file_oomem(ms,
                                    strlen(fn) + strlen(d->d_name) + 2);
                                errs++;
@@ -804,7 +804,7 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
                                        goto out;
                                }
                        }
-                       filearr[files++] = estrndup(mfn, mflen);
+                       filearr[files++] = estrdup(mfn);
                }
                closedir(dir);
                qsort(filearr, files, sizeof(*filearr), cmpstrp);