# libtiff: Merge branch 'test\_ifd\_loop\_detection\_fix\_CoverityScan\_ln\_55' into 'master'

**URL:** <https://discourse.libsdl.org/t/libtiff-merge-branch-test-ifd-loop-detection-fix-coverityscan-ln-55-into-master/42504>\
**Category:** SDL Commits\
**Created:** [February 9, 2023, 12:30am UTC](https://discourse.libsdl.org/t/libtiff-merge-branch-test-ifd-loop-detection-fix-coverityscan-ln-55-into-master/42504 "2023-02-09T00:30:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [February 9, 2023, 12:30am UTC](https://discourse.libsdl.org/t/libtiff-merge-branch-test-ifd-loop-detection-fix-coverityscan-ln-55-into-master/42504/1 "2023-02-09T00:30:09Z")

</div>

> <https://github.com/libsdl-org/libtiff/commit/feb8db628d38835bd9442d1fcbaf979c05487490>
>
> test\_ifd\_loop\_detection: fix Coverity Scan issue CID 1520750: Null pointer...
> 
> S…ee merge request libtiff/libtiff!470

```diff
From 538b8f2935ce8c925a9c2b23c41aa2a8dd65a31f Mon Sep 17 00:00:00 2001
From: Su_Laus <[EMAIL REDACTED]>
Date: Mon, 6 Feb 2023 21:23:13 +0100
Subject: [PATCH] test_ifd_loop_detection: fix Coverity Scan issue CID 1520750:
 Null pointer dereferences (NULL_RETURNS) line 55.

---
 test/test_ifd_loop_detection.c | 18 +++++++++++-------
 1 file 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;

```
