Bug Summary

File:kauth/kdb.c
Location:line 49, column 48
Description:Access to field 'data' results in a dereference of a null pointer (loaded from variable 'ti')

Annotated Source Code

1/*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
4 *
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
8 */
9
10#include <afsconfig.h>
11#include <afs/param.h>
12
13#include <roken.h>
14
15#include <afs/cmd.h>
16#include <afs/afsutil.h>
17
18#include "kauth.h"
19#include "kalog.h"
20
21#ifdef AUTH_DBM_LOG
22
23const char *dbmfile;
24
25static int
26cmdproc(struct cmd_syndesc *as, void * arock)
27{
28 DBM *kdb;
29 datum key, data;
30 kalog_elt rdata;
31 afs_int32 cnt = 0;
32 struct cmd_item *ti;
33
34 if (as->parms[0].items) {
1
Taking false branch
35 dbmfile = as->parms[0].items->data;
36 }
37 kdb = dbm_open(dbmfile, O_RDONLY0x0000, KALOG_DB_MODE0600);
38 if (!kdb) {
2
Taking false branch
39 perror(dbmfile);
40 exit(1);
41 }
42 if (!(ti = as->parms[1].items)) {
3
Taking true branch
43 printf("Printing all entries found in %s\n", dbmfile);
44 for (key = dbm_firstkey(kdb); key.dptr;
4
Loop condition is true. Entering loop body
45 key = afs_dbm_nextkey(kdb, key)dbm_nextkey(kdb), cnt++) {
46 if (as->parms[2].items) {
5
Taking true branch
47 data = dbm_fetch(kdb, key);
48 if (!data.dptr) {
6
Taking true branch
49 fprintf(stderr__stderrp, "%s: no entry exists\n", ti->data);
7
Access to field 'data' results in a dereference of a null pointer (loaded from variable 'ti')
50 continue;
51 }
52 if (data.dsize != sizeof(kalog_elt)) {
53 fprintf(stderr__stderrp, "%s: data came out corrupt\n", ti->data);
54 continue;
55 }
56 memcpy(&rdata, data.dptr, sizeof(kalog_elt));
57 if (! as->parms[3].items) {
58 char *hostName;
59 hostName = hostutil_GetNameByINet(rdata.host);
60 printf("%s: last operation from host %s at %s",
61 (char *)key.dptr, hostName,
62 ctime(&rdata.last_use));
63 } else {
64 char *hostIP;
65 char hoststr[16];
66 hostIP = afs_inet_ntoa_r(rdata.host, hoststr);
67 printf("%s: last operation from host %s at %s",
68 (char *)key.dptr, hostIP,
69 ctime(&rdata.last_use));
70 }
71 } else {
72 printf("\t%s\n", (char *)key.dptr);
73 }
74 }
75 printf("%d entries were found\n", cnt);
76 } else {
77 for (; ti; ti = ti->next) {
78 key.dsize = strlen(ti->data) + 1;
79 key.dptr = ti->data;
80 data = dbm_fetch(kdb, key);
81 if (!data.dptr) {
82 fprintf(stderr__stderrp, "%s: no entry exists\n", ti->data);
83 continue;
84 }
85 if (data.dsize != sizeof(kalog_elt)) {
86 fprintf(stderr__stderrp, "%s: data came out corrupt\n", ti->data);
87 continue;
88 }
89 memcpy(&rdata, data.dptr, sizeof(kalog_elt));
90 printf("%s: last operation from host %x at %s", ti->data,
91 rdata.host, ctime(&rdata.last_use));
92 }
93 }
94 dbm_close(kdb);
95 return 0;
96}
97
98
99#include "AFS_component_version_number.c"
100
101int
102main(int argc, char **argv)
103{
104 struct cmd_syndesc *ts;
105 afs_int32 code;
106 char dbmfile_help[AFSDIR_PATH_MAX256];
107
108 sprintf(dbmfile_help, "dbmfile to use (default %s)",
109 AFSDIR_SERVER_KALOGDB_FILEPATHgetDirPath(AFSDIR_SERVER_KALOGDB_FILEPATH_ID));
110 dbmfile = AFSDIR_SERVER_KALOGDB_FILEPATHgetDirPath(AFSDIR_SERVER_KALOGDB_FILEPATH_ID);
111 ts = cmd_CreateSyntax(NULL((void *)0), cmdproc, NULL((void *)0), "Dump contents of dbm database");
112 cmd_AddParm(ts, "-dbmfile", CMD_SINGLE2, CMD_OPTIONAL1, dbmfile_help);
113 cmd_AddParm(ts, "-key", CMD_SINGLE2, CMD_OPTIONAL1,
114 "extract entries that match specified key");
115 cmd_AddParm(ts, "-long", CMD_FLAG1, CMD_OPTIONAL1, "print long info for each entry");
116 cmd_AddParm(ts, "-numeric", CMD_FLAG1, CMD_OPTIONAL1, "addresses only");
117 code = cmd_Dispatch(argc, argv);
118 return code;
119}
120#else
121
122#include "AFS_component_version_number.c"
123
124int
125main(void)
126{
127 printf("kdb not supported\n");
128 return 1;
129}
130#endif