@@ -158,12 +158,18 @@ int limited=0; /* 1=Limit cyls copied */
158
158
159
159
/* read the CKD device header */
160
160
rc = read (ifd , & devhdr , CKDDASD_DEVHDR_SIZE );
161
+ if (rc != CKDDASD_DEVHDR_SIZE )
162
+ {
163
+ fprintf (stderr , "cckd2ckd: %s read error: %s\n" ,
164
+ ifile , strerror (errno ));
165
+ exit (2 );
166
+ }
161
167
if (memcmp (devhdr .devid , "CKD_C370" , 8 ) != 0 )
162
168
{
163
169
fprintf (stderr ,
164
170
"cckd2ckd: input file %s is not a compressed ckd file\n" ,
165
171
ifile );
166
- exit (2 );
172
+ exit (3 );
167
173
}
168
174
memcpy (devhdr .devid , "CKD_P370" , 8 );
169
175
@@ -179,6 +185,12 @@ int limited=0; /* 1=Limit cyls copied */
179
185
180
186
/* read the compressed CKD device header */
181
187
rc = read (ifd , & cdevhdr , CCKDDASD_DEVHDR_SIZE );
188
+ if (rc != CCKDDASD_DEVHDR_SIZE )
189
+ {
190
+ fprintf (stderr , "cckd2ckd: %s read error: %s\n" ,
191
+ ifile , strerror (errno ));
192
+ exit (4 );
193
+ }
182
194
183
195
/* check the byte order of the file vs the machine */
184
196
if (((cdevhdr .options & CCKD_BIGENDIAN ) != 0 && chk_endian () == 0 ) ||
@@ -188,7 +200,19 @@ int limited=0; /* 1=Limit cyls copied */
188
200
/* get area for primary lookup table and read it in */
189
201
if (swapend ) swapend4 ((unsigned char * )& cdevhdr .numl1tab );
190
202
l1 = malloc (cdevhdr .numl1tab * CCKD_L1ENT_SIZE );
203
+ if (l1 == NULL )
204
+ {
205
+ fprintf (stderr , "lookup table malloc error: %s\n" ,
206
+ strerror (errno ));
207
+ exit (5 );
208
+ }
191
209
rc = read (ifd , l1 , cdevhdr .numl1tab * CCKD_L1ENT_SIZE );
210
+ if (rc != cdevhdr .numl1tab * CCKD_L1ENT_SIZE )
211
+ {
212
+ fprintf (stderr , "cckd2ckd: %s read error: %s\n" ,
213
+ ifile , strerror (errno ));
214
+ exit (6 );
215
+ }
192
216
if (swapend )
193
217
for (i = 0 ; i < cdevhdr .numl1tab ; i ++ )
194
218
swapend4 ((unsigned char * )& l1 [i ]);
@@ -214,7 +238,19 @@ int limited=0; /* 1=Limit cyls copied */
214
238
else
215
239
{
216
240
rc = lseek (ifd , l1 [i ], SEEK_SET );
241
+ if (rc == -1 )
242
+ {
243
+ fprintf (stderr , "cckd2ckd: %s lseek error: %s\n" ,
244
+ ifile , strerror (errno ));
245
+ exit (7 );
246
+ }
217
247
rc = read (ifd , & l2 , CCKD_L2TAB_SIZE );
248
+ if (rc != CCKD_L2TAB_SIZE )
249
+ {
250
+ fprintf (stderr , "cckd2ckd: %s read error: %s\n" ,
251
+ ifile , strerror (errno ));
252
+ exit (8 );
253
+ }
218
254
}
219
255
/* find the last used entry in the level 2 table */
220
256
for (j = 255 ; j > 0 ; j -- )
@@ -256,6 +292,12 @@ int limited=0; /* 1=Limit cyls copied */
256
292
/* get buffers */
257
293
buf = malloc (trksz );
258
294
buf2 = malloc (trksz );
295
+ if (buf == NULL || buf2 == NULL )
296
+ {
297
+ fprintf (stderr , "cckd2ckd: buffer malloc error: %s\n" ,
298
+ strerror (errno ));
299
+ exit (9 );
300
+ }
259
301
260
302
/* process each entry in the primary lookup table */
261
303
for (i = 0 ; i * 256 < trks || l1 [i ] != 0 ; i ++ )
@@ -267,7 +309,19 @@ int limited=0; /* 1=Limit cyls copied */
267
309
else
268
310
{
269
311
rc = lseek (ifd , l1 [i ], SEEK_SET );
312
+ if (rc == -1 )
313
+ {
314
+ fprintf (stderr , "cckd2ckd: %s lseek error: %s\n" ,
315
+ ifile , strerror (errno ));
316
+ exit (10 );
317
+ }
270
318
rc = read (ifd , & l2 , CCKD_L2TAB_SIZE );
319
+ if (rc != CCKD_L2TAB_SIZE )
320
+ {
321
+ fprintf (stderr , "cckd2ckd: %s read error: %s\n" ,
322
+ ifile , strerror (errno ));
323
+ exit (11 );
324
+ }
271
325
if (swapend ) /* fix byte order if necessary */
272
326
for (j = 0 ; j < 256 ; j ++ )
273
327
{
@@ -279,9 +333,7 @@ int limited=0; /* 1=Limit cyls copied */
279
333
280
334
/* process each entry in the secondary lookup table */
281
335
for (j = 0 ;
282
-
283
336
j < 256 && (i * 256 + j < trks || (l1 [i ] != 0 && l2 [j ].pos != 0 ));
284
-
285
337
j ++ )
286
338
287
339
{
@@ -300,7 +352,7 @@ int limited=0; /* 1=Limit cyls copied */
300
352
fprintf (stderr ,
301
353
"cckd2ckd: %s close error: %s\n" ,
302
354
ofile , strerror (errno ));
303
- exit (3 );
355
+ exit (12 );
304
356
}
305
357
* sfxptr = '0' + fileseq ;
306
358
}
@@ -326,16 +378,17 @@ int limited=0; /* 1=Limit cyls copied */
326
378
fprintf (stderr ,
327
379
"cckd2ckd: %s open error: %s\n" ,
328
380
ofile , strerror (errno ));
329
- exit (4 );
381
+ exit (13 );
330
382
}
383
+
331
384
/* write the devhdr */
332
385
rc = write (ofd , & devhdr , CKDDASD_DEVHDR_SIZE );
333
386
if (rc != CKDDASD_DEVHDR_SIZE )
334
387
{
335
388
fprintf (stderr ,
336
389
"cckd2ckd: %s write error: %s\n" ,
337
390
ofile , strerror (errno ));
338
- exit (5 );
391
+ exit (14 );
339
392
}
340
393
}
341
394
@@ -348,7 +401,21 @@ int limited=0; /* 1=Limit cyls copied */
348
401
else
349
402
{
350
403
rc = lseek (ifd , l2 [j ].pos , SEEK_SET );
404
+ if (rc == -1 )
405
+ {
406
+ fprintf (stderr , "cckd2ckd: %s lseek error: %s\n" ,
407
+ ifile , strerror (errno ));
408
+ exit (15 );
409
+ }
410
+
351
411
rc = read (ifd , buf , l2 [j ].len );
412
+ if (rc != l2 [j ].len )
413
+ {
414
+ fprintf (stderr , "cckd2ckd: %s read error: %s\n" ,
415
+ ifile , strerror (errno ));
416
+ exit (16 );
417
+ }
418
+
352
419
/* uncompress the track image */
353
420
compress = buf [0 ];
354
421
buf [0 ] = 0 ;
@@ -444,7 +511,7 @@ int limited=0; /* 1=Limit cyls copied */
444
511
fprintf (stderr ,
445
512
"cckd2ckd: %s write error: %s\n" ,
446
513
ofile , strerror (errno ));
447
- exit (6 );
514
+ exit (17 );
448
515
}
449
516
450
517
/* update status information */
@@ -455,7 +522,7 @@ int limited=0; /* 1=Limit cyls copied */
455
522
{
456
523
fprintf (stderr ,
457
524
"cckd2ckd: Terminated due to errors\n" );
458
- exit (7 );
525
+ exit (18 );
459
526
}
460
527
}
461
528
}
@@ -472,15 +539,15 @@ int limited=0; /* 1=Limit cyls copied */
472
539
fprintf (stderr ,
473
540
"cckd2ckd: %s close error: %s\n" ,
474
541
ofile , strerror (errno ));
475
- exit (8 );
542
+ exit (19 );
476
543
}
477
544
rc = close (ifd );
478
545
if (rc < 0 )
479
546
{
480
547
fprintf (stderr ,
481
548
"cckd2ckd: %s close error: %s\n" ,
482
549
ifile , strerror (errno ));
483
- exit (9 );
550
+ exit (20 );
484
551
}
485
552
486
553
if (quiet == 0 || errs > 0 )
@@ -509,7 +576,7 @@ void syntax ()
509
576
" -quiet quiet mode, don't display status\n"
510
577
" -validate validate track images [default]\n"
511
578
" -novalidate don't validate track images\n" );
512
- exit (9 );
579
+ exit (21 );
513
580
} /* end function syntax */
514
581
515
582
int abbrev (char * tst , char * cmp )
@@ -615,10 +682,11 @@ int kl,dl; /* Key/Data lengths */
615
682
{
616
683
kl = buf [sz + 5 ];
617
684
dl = buf [sz + 6 ] * 256 + buf [sz + 7 ];
685
+
618
686
/* fix for track overflow bit */
619
687
memcpy (cchh2 , & buf [sz ], 4 ); cchh2 [0 ] &= 0x7f ;
620
- /* fix for funny formatted vm disks */
621
688
689
+ /* fix for funny formatted vm disks */
622
690
if (r == 1 ) memcpy (cchh , cchh2 , 4 );
623
691
624
692
if (memcmp (cchh , cchh2 , 4 ) != 0 || buf [sz + 4 ] == 0 ||
0 commit comments