~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/ddc/edid.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/ddc/edid.c,v 1.4 2003/02/17 16:08:27 dawes Exp $ */
 
2
 
 
3
/* edid.c:  retrieve EDID record from raw DDC1 data stream: data 
 
4
 * is contained in an array of unsigned int each unsigned int 
 
5
 * contains one bit if bit is 0 unsigned int has to be zero else 
 
6
 * unsigned int > 0 
 
7
 * 
 
8
 * Copyright 1998 by Egbert Eich <Egbert.Eich@Physik.TU-Darmstadt.DE>
 
9
 */
 
10
#include "misc.h"
 
11
#include "xf86.h"
 
12
#include "xf86_ansic.h"
 
13
#include "xf86_OSproc.h"
 
14
#include "xf86DDC.h"
 
15
#include "ddcPriv.h"
 
16
 
 
17
static int find_start(unsigned int *);
 
18
static unsigned char * find_header(unsigned char *);
 
19
static unsigned char * resort(unsigned char *);
 
20
 
 
21
unsigned char *
 
22
GetEDID_DDC1(unsigned int *s_ptr)
 
23
{
 
24
    unsigned char *d_block, *d_pos;
 
25
    unsigned int *s_pos, *s_end;
 
26
    int s_start;
 
27
    int i,j;
 
28
    s_start = find_start(s_ptr);
 
29
    if (s_start==-1) return NULL;
 
30
    s_end = s_ptr + NUM;
 
31
    s_pos = s_ptr + s_start;
 
32
    d_block=xalloc(EDID1_LEN);
 
33
    if (!d_block) return NULL;
 
34
    d_pos = d_block;
 
35
    for (i=0;i<EDID1_LEN;i++) {
 
36
        for (j=0;j<8;j++) {
 
37
            *d_pos <<= 1;
 
38
            if (*s_pos) {
 
39
                *d_pos |= 0x01;
 
40
            }
 
41
            s_pos++; if (s_pos == s_end) s_pos=s_ptr;
 
42
        };
 
43
        s_pos++; if (s_pos == s_end) s_pos=s_ptr;
 
44
        d_pos++;
 
45
    }
 
46
    xfree(s_ptr);
 
47
    if (d_block && DDC_checksum(d_block,EDID1_LEN)) return NULL;
 
48
    return (resort(d_block));
 
49
}
 
50
 
 
51
int
 
52
DDC_checksum(unsigned char *block, int len)
 
53
{
 
54
    int i, result = 0;
 
55
    int not_null = 0;
 
56
    
 
57
    for (i=0;i<len;i++) {
 
58
        not_null |= block[i];
 
59
        result += block[i];
 
60
    }
 
61
    
 
62
#ifdef DEBUG
 
63
    if (result & 0xFF) ErrorF("DDC checksum not correct\n");
 
64
    if (!not_null) ErrorF("DDC read all Null\n");
 
65
#endif
 
66
 
 
67
    /* catch the trivial case where all bytes are 0 */
 
68
    if (!not_null) return 1;
 
69
 
 
70
    return (result&0xFF);
 
71
}
 
72
 
 
73
static int
 
74
find_start(unsigned int *ptr)
 
75
{
 
76
    unsigned int comp[9], test[9];
 
77
    int i,j;
 
78
  
 
79
    for (i=0;i<9;i++){
 
80
        comp[i] = *(ptr++);
 
81
        test[i] = 1;
 
82
    }
 
83
    for (i=0;i<127;i++){
 
84
        for (j=0;j<9;j++){
 
85
            test[j] = test[j] & !(comp[j] ^ *(ptr++));
 
86
        }
 
87
    }
 
88
    for (i=0;i<9;i++)
 
89
        if (test[i]) return (i+1);
 
90
    return (-1);
 
91
}
 
92
 
 
93
static unsigned char *
 
94
find_header(unsigned char *block)
 
95
{
 
96
    unsigned char *ptr, *head_ptr, *end;
 
97
    unsigned char header[]={0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00};
 
98
 
 
99
    ptr = block;
 
100
    end = block + EDID1_LEN;
 
101
    while (ptr<end) {
 
102
        int i;
 
103
        head_ptr = ptr;
 
104
        for (i=0;i<8;i++){
 
105
            if (header[i] != *(head_ptr++)) break;
 
106
            if (head_ptr == end) head_ptr = block;
 
107
        }
 
108
        if (i==8) break;
 
109
        ptr++; 
 
110
    }
 
111
    if (ptr == end) return (NULL);
 
112
    return (ptr);
 
113
}
 
114
 
 
115
static unsigned char *
 
116
resort(unsigned char *s_block)
 
117
{
 
118
    unsigned char *d_new, *d_ptr, *d_end, *s_ptr, *s_end;
 
119
    unsigned char tmp;
 
120
 
 
121
    s_end = s_block + EDID1_LEN;
 
122
    d_new = xalloc(EDID1_LEN);
 
123
    if (!d_new) return NULL;
 
124
    d_end = d_new + EDID1_LEN;
 
125
 
 
126
    s_ptr = find_header(s_block);
 
127
    if (!s_ptr) return NULL;
 
128
    for (d_ptr=d_new;d_ptr<d_end;d_ptr++){
 
129
        tmp = *(s_ptr++);
 
130
        *d_ptr = tmp; 
 
131
        if (s_ptr == s_end) s_ptr = s_block;
 
132
    }
 
133
    xfree(s_block);
 
134
    return (d_new);
 
135
}
 
136
 
 
137