diff options
author | Even Rouault <even.rouault@spatialys.com> | 2023-02-08 16:05:37 +0000 |
---|---|---|
committer | Even Rouault <even.rouault@spatialys.com> | 2023-02-08 16:05:37 +0000 |
commit | feb8db628d38835bd9442d1fcbaf979c05487490 (patch) | |
tree | db91e4d3e2a0b3aa712c259b0912cce0e2991edf | |
parent | c8e1289deff3fa60ba833ccec6c030934b02c281 (diff) | |
parent | 538b8f2935ce8c925a9c2b23c41aa2a8dd65a31f (diff) | |
download | libtiff-git-feb8db628d38835bd9442d1fcbaf979c05487490.tar.gz |
Merge branch 'test_ifd_loop_detection_fix_CoverityScan_ln_55' into 'master'
test_ifd_loop_detection: fix Coverity Scan issue CID 1520750: Null pointer...
See merge request libtiff/libtiff!470
-rw-r--r-- | test/test_ifd_loop_detection.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/test/test_ifd_loop_detection.c b/test/test_ifd_loop_detection.c index 99a749e5..02421f66 100644 --- a/test/test_ifd_loop_detection.c +++ b/test/test_ifd_loop_detection.c @@ -36,30 +36,34 @@ #include "tiffio.h" +/* Compare 'requested_dir_number' with number written in PageName tag + * into the IFD to identify that IFD. */ int is_requested_directory(TIFF *tif, int requested_dir_number, const char *filename) { - char *ptr; + char *ptr = NULL; + char *auxStr = NULL; if (!TIFFGetField(tif, TIFFTAG_PAGENAME, &ptr)) { fprintf(stderr, "Can't get TIFFTAG_PAGENAME tag.\n"); return 0; } - /* Retrieve directory number from ASCII string */ - char *auxStr = strchr(ptr, ' '); - int nthIFD; - nthIFD = atoi(ptr); - /* Check for reading errors */ - if (strncmp(auxStr, " th.", 4)) + if (ptr != NULL) + auxStr = strchr(ptr, ' '); + + if (ptr == NULL || auxStr == NULL || strncmp(auxStr, " th.", 4)) { + ptr = ptr == NULL ? "(null)" : ptr; fprintf(stderr, "Error reading IFD directory number from PageName tag: %s\n", ptr); return 0; } + /* Retrieve IFD identification number from ASCII string */ + const int nthIFD = atoi(ptr); if (nthIFD == requested_dir_number) { return 1; |