@@ -86,7 +86,10 @@ struct AdfList * adfGetDirEntCache ( struct AdfVolume * const vol,
86
86
adfFreeDirList (head );
87
87
return NULL ;
88
88
}
89
- adfGetCacheEntry (& dirc , & offset , & caEntry );
89
+ if (adfGetCacheEntry (& dirc , & offset , & caEntry ) != RC_OK ) {
90
+ free (entry ); adfFreeDirList (head );
91
+ return NULL ;
92
+ }
90
93
91
94
/* converts a cache entry into a dir entry */
92
95
entry -> type = (int )caEntry .type ;
@@ -140,13 +143,14 @@ struct AdfList * adfGetDirEntCache ( struct AdfVolume * const vol,
140
143
* Returns a cache entry, starting from the offset p (the index into records[])
141
144
* This offset is updated to the end of the returned entry.
142
145
*/
143
- void adfGetCacheEntry ( const struct bDirCacheBlock * const dirc ,
144
- int * const p ,
145
- struct AdfCacheEntry * const cEntry )
146
+ RETCODE adfGetCacheEntry ( const struct bDirCacheBlock * const dirc ,
147
+ int * const p ,
148
+ struct AdfCacheEntry * const cEntry )
146
149
{
147
150
int ptr ;
148
151
149
152
ptr = * p ;
153
+ if (ptr > LOGICAL_BLOCK_SIZE - 26 ) return RC_ERROR ; /* minimum cache entry length */
150
154
151
155
/*printf("p=%d\n",ptr);*/
152
156
@@ -171,10 +175,15 @@ void adfGetCacheEntry ( const struct bDirCacheBlock * const dirc,
171
175
/* cEntry->name = (char*)malloc(sizeof(char)*(cEntry->nLen+1));
172
176
if (!cEntry->name)
173
177
return;
174
- */ memcpy (cEntry -> name , dirc -> records + ptr + 24 , cEntry -> nLen );
178
+ */
179
+ if (cEntry -> nLen < 1 || cEntry -> nLen > MAXNAMELEN ) return RC_ERROR ;
180
+ if ((ptr + 24 + cEntry -> nLen ) > LOGICAL_BLOCK_SIZE ) return RC_ERROR ;
181
+ memcpy (cEntry -> name , dirc -> records + ptr + 24 , cEntry -> nLen );
175
182
cEntry -> name [(int )(cEntry -> nLen )]= '\0' ;
176
183
177
184
cEntry -> cLen = dirc -> records [ptr + 24 + cEntry -> nLen ];
185
+ if (cEntry -> cLen > MAXCMMTLEN ) return RC_ERROR ;
186
+ if ((ptr + 24 + cEntry -> nLen + 1 + cEntry -> cLen ) > LOGICAL_BLOCK_SIZE ) return RC_ERROR ;
178
187
if (cEntry -> cLen > 0 ) {
179
188
/* cEntry->comm =(char*)malloc(sizeof(char)*(cEntry->cLen+1));
180
189
if (!cEntry->comm) {
@@ -190,6 +199,8 @@ void adfGetCacheEntry ( const struct bDirCacheBlock * const dirc,
190
199
/* the starting offset of each record must be even (68000 constraint) */
191
200
if ((* p %2 )!= 0 )
192
201
* p = (* p )+ 1 ;
202
+
203
+ return RC_OK ;
193
204
}
194
205
195
206
@@ -308,7 +319,8 @@ RETCODE adfDelFromCache ( struct AdfVolume * const vol,
308
319
offset = 0 ; n = 0 ;
309
320
while (n < dirc .recordsNb && !found ) {
310
321
oldOffset = offset ;
311
- adfGetCacheEntry (& dirc , & offset , & caEntry );
322
+ if (adfGetCacheEntry (& dirc , & offset , & caEntry ) != RC_OK )
323
+ return RC_ERROR ;
312
324
found = ( caEntry .header == (uint32_t ) headerKey );
313
325
if (found ) {
314
326
entryLen = offset - oldOffset ;
@@ -383,7 +395,8 @@ RETCODE adfAddInCache ( struct AdfVolume * const vol,
383
395
offset = 0 ; n = 0 ;
384
396
/*printf("parent=%4ld\n",dirc.parent);*/
385
397
while (n < dirc .recordsNb ) {
386
- adfGetCacheEntry (& dirc , & offset , & caEntry );
398
+ if (adfGetCacheEntry (& dirc , & offset , & caEntry ) != RC_OK )
399
+ return RC_ERROR ;
387
400
/*printf("*%4ld %2d %6ld %8lx %4d %2d:%02d:%02d %30s %22s\n",
388
401
caEntry.header, caEntry.type, caEntry.size, caEntry.protect,
389
402
caEntry.days, caEntry.mins/60, caEntry.mins%60,
@@ -473,7 +486,8 @@ RETCODE adfUpdateCache ( struct AdfVolume * const vol,
473
486
while (n < dirc .recordsNb && !found ) {
474
487
oldOffset = offset ;
475
488
/* offset is updated */
476
- adfGetCacheEntry (& dirc , & offset , & caEntry );
489
+ if (adfGetCacheEntry (& dirc , & offset , & caEntry ) != RC_OK )
490
+ return RC_ERROR ;
477
491
oLen = offset - oldOffset ;
478
492
sLen = oLen - nLen ;
479
493
/*printf("olen=%d nlen=%d\n",oLen,nLen);*/
0 commit comments