1 /* 2 * Copyright (c) 2020, Masatake YAMATO 3 * 4 * This source code is released into the public domain. 5 * 6 * Testing the guard condition for NULL pointer dereference 7 */ 8 9 #include "readtags.h" 10 11 #include <stdio.h> 12 #include <stdlib.h> 13 #include <string.h> 14 #include <unistd.h> 15 16 int main(void)17main (void) 18 { 19 char *srcdir = getenv ("srcdir"); 20 if (srcdir) 21 { 22 if (chdir (srcdir) == -1) 23 { 24 perror ("chdir"); 25 return 99; 26 } 27 } 28 29 tagFile *t; 30 tagFileInfo info; 31 32 const char *tags0 = "./null-deref.tags"; 33 t = tagsOpen (tags0, &info); 34 if (t == NULL 35 || info.status.opened == 0) 36 { 37 fprintf (stderr, "unexpected result (t: %p, opened: %d)\n", 38 t, info.status.opened); 39 return 1; 40 } 41 fprintf (stderr, "ok\n"); 42 43 tagEntry e; 44 45 /* Without fix, this program crashes in tagsFirst(). */ 46 tagsFirst (t, &e); 47 tagsClose (t); 48 return 0; 49 } 50