Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 167248 | Differences between
and this patch

Collapse All | Expand All

(-)cracklib-2.8.19/lib/packlib.c (-11 / +90 lines)
Lines 59-64 Link Here
59
    return (pdesc64.header.pih_magic == PIH_MAGIC);
59
    return (pdesc64.header.pih_magic == PIH_MAGIC);
60
}
60
}
61
61
62
static uint16_t read_little_endian16 (const uint8_t *bytes)
63
{
64
	return (
65
		((uint16_t)bytes[0] << 0) |
66
		((uint16_t)bytes[1] << 8)
67
	);
68
}
69
70
static uint32_t read_little_endian32 (const uint8_t *bytes)
71
{
72
	return (
73
		((uint32_t)bytes[0] << 0) |
74
		((uint32_t)bytes[1] << 8) |
75
		((uint32_t)bytes[2] << 16) |
76
		((uint32_t)bytes[3] << 24)
77
	);
78
}
79
80
static void write_little_endian16 (uint16_t x, uint8_t *bytes)
81
{
82
	bytes[0] = x >> 0;
83
	bytes[1] = x >> 8;
84
}
85
86
static void write_little_endian32 (uint32_t x, uint8_t *bytes)
87
{
88
	bytes[0] = x >> 0;
89
	bytes[1] = x >> 8;
90
	bytes[2] = x >> 16;
91
	bytes[3] = x >> 24;
92
}
93
94
static struct pi_header header_to_portable (struct pi_header x)
95
{
96
	struct pi_header y;
97
	write_little_endian32(x.pih_magic, (uint8_t *)&y.pih_magic);
98
	write_little_endian32(x.pih_numwords, (uint8_t *)&y.pih_numwords);
99
	write_little_endian16(x.pih_blocklen, (uint8_t *)&y.pih_blocklen);
100
	write_little_endian16(x.pih_pad, (uint8_t *)&y.pih_pad);
101
	return y;
102
}
103
104
static struct pi_header header_from_portable (struct pi_header x)
105
{
106
	struct pi_header y;
107
	y.pih_magic = read_little_endian32((uint8_t *)&x.pih_magic);
108
	y.pih_numwords = read_little_endian32((uint8_t *)&x.pih_numwords);
109
	y.pih_blocklen = read_little_endian16((uint8_t *)&x.pih_blocklen);
110
	y.pih_pad = read_little_endian16((uint8_t *)&x.pih_pad);
111
	return y;
112
}
113
114
static void hwms_from_portable (uint32_t *hwms)
115
{
116
	int i;
117
	for (i = 0; i < 256; i++) {
118
		hwms[i] = read_little_endian32((uint8_t *)&hwms[i]);
119
	}
120
}
121
122
static void hwms_to_portable (uint32_t *hwms)
123
{
124
	int i;
125
	for (i = 0; i < 256; i++) {
126
		write_little_endian32(hwms[i], (uint8_t *)&hwms[i]);
127
	}
128
}
62
129
63
PWDICT *
130
PWDICT *
64
PWOpen(prefix, mode)
131
PWOpen(prefix, mode)
Lines 74-79 Link Here
74
    FILE *dfp;
141
    FILE *dfp;
75
    FILE *ifp;
142
    FILE *ifp;
76
    FILE *wfp;
143
    FILE *wfp;
144
    struct pi_header phdr;
77
145
78
    if (pdesc.header.pih_magic == PIH_MAGIC)
146
    if (pdesc.header.pih_magic == PIH_MAGIC)
79
    {
147
    {
Lines 147-159 Link Here
147
	pdesc.header.pih_magic = PIH_MAGIC;
215
	pdesc.header.pih_magic = PIH_MAGIC;
148
	pdesc.header.pih_blocklen = NUMWORDS;
216
	pdesc.header.pih_blocklen = NUMWORDS;
149
	pdesc.header.pih_numwords = 0;
217
	pdesc.header.pih_numwords = 0;
150
218
	
151
	fwrite((char *) &pdesc.header, sizeof(pdesc.header), 1, ifp);
219
	phdr = header_to_portable(pdesc.header);
220
	fwrite((char *) &phdr, sizeof(phdr), 1, ifp);
152
    } else
221
    } else
153
    {
222
    {
154
	pdesc.flags &= ~PFOR_WRITE;
223
	pdesc.flags &= ~PFOR_WRITE;
155
224
156
	if (!fread((char *) &pdesc.header, sizeof(pdesc.header), 1, ifp))
225
	
226
	if (!fread((char *) &phdr, sizeof(phdr), 1, ifp))
157
	{
227
	{
158
	    fprintf(stderr, "%s: error reading header\n", prefix);
228
	    fprintf(stderr, "%s: error reading header\n", prefix);
159
229
Lines 171-176 Link Here
171
	    }
241
	    }
172
	    return ((PWDICT *) 0);
242
	    return ((PWDICT *) 0);
173
	}
243
	}
244
	
245
	pdesc.header = header_from_portable(phdr);
174
246
175
        if ((pdesc.header.pih_magic == 0) || (pdesc.header.pih_numwords == 0))
247
        if ((pdesc.header.pih_magic == 0) || (pdesc.header.pih_numwords == 0))
176
        {
248
        {
Lines 294-302 Link Here
294
                    pdesc.hwms[i] = pdesc64.hwms[i];
366
                    pdesc.hwms[i] = pdesc64.hwms[i];
295
                }
367
                }
296
            } 
368
            } 
297
            else if (fread(pdesc.hwms, 1, sizeof(pdesc.hwms), wfp) != sizeof(pdesc.hwms))
369
            else {
298
	    {
370
		if (fread(pdesc.hwms, 1, sizeof(pdesc.hwms), wfp) != sizeof(pdesc.hwms)) {
299
		pdesc.flags &= ~PFOR_USEHWMS;
371
			pdesc.flags &= ~PFOR_USEHWMS;
372
		} else {
373
			hwms_from_portable(pdesc.hwms);
374
		}
300
	    }
375
	    }
301
#if DEBUG
376
#if DEBUG
302
            for (i=1; i<=0xff; i++)
377
            for (i=1; i<=0xff; i++)
Lines 330-337 Link Here
330
	    fprintf(stderr, "index magic fseek failed\n");
405
	    fprintf(stderr, "index magic fseek failed\n");
331
	    return (-1);
406
	    return (-1);
332
	}
407
	}
333
408
	
334
	if (!fwrite((char *) &pwp->header, sizeof(pwp->header), 1, pwp->ifp))
409
	struct pi_header phdr = header_to_portable(pwp->header);
410
	if (!fwrite((char *) &phdr, sizeof(phdr), 1, pwp->ifp))
335
	{
411
	{
336
	    fprintf(stderr, "index magic fwrite failed\n");
412
	    fprintf(stderr, "index magic fwrite failed\n");
337
	    return (-1);
413
	    return (-1);
Lines 350-355 Link Here
350
	    	printf("hwm[%02x] = %d\n", i, pwp->hwms[i]);
426
	    	printf("hwm[%02x] = %d\n", i, pwp->hwms[i]);
351
#endif
427
#endif
352
	    }
428
	    }
429
	    hwms_to_portable(pwp->hwms);
353
	    fwrite(pwp->hwms, 1, sizeof(pwp->hwms), pwp->wfp);
430
	    fwrite(pwp->hwms, 1, sizeof(pwp->hwms), pwp->wfp);
354
	}
431
	}
355
    }
432
    }
Lines 399-410 Link Here
399
    if ((pwp->flags & PFOR_FLUSH) || !(pwp->count % NUMWORDS))
476
    if ((pwp->flags & PFOR_FLUSH) || !(pwp->count % NUMWORDS))
400
    {
477
    {
401
	int i;
478
	int i;
402
	uint32_t datum;
479
	uint32_t datum, pdatum;
403
	register char *ostr;
480
	register char *ostr;
404
481
405
	datum = (uint32_t) ftell(pwp->dfp);
482
	datum = (uint32_t) ftell(pwp->dfp);
406
483
	
407
	fwrite((char *) &datum, sizeof(datum), 1, pwp->ifp);
484
	write_little_endian32(datum, (uint8_t *)&pdatum);
485
	fwrite((char *) &pdatum, sizeof(pdatum), 1, pwp->ifp);
408
486
409
	fputs(pwp->data[0], pwp->dfp);
487
	fputs(pwp->data[0], pwp->dfp);
410
	putc(0, pwp->dfp);
488
	putc(0, pwp->dfp);
Lines 486-491 Link Here
486
           perror("(index fread failed)");
564
           perror("(index fread failed)");
487
           return ((char *) 0);
565
           return ((char *) 0);
488
       }
566
       }
567
       datum = read_little_endian32((uint8_t *)&datum);
489
    }
568
    }
490
569
491
	int r = 1;
570
	int r = 1;

Return to bug 167248