Chameleon

Chameleon Commit Details

Date:2014-01-07 09:36:06 (10 years 3 months ago)
Author:Chuck Fry
Commit:2310
Parents: 2309
Message:Fix memory leak, defend against buffer overruns
Changes:
M/branches/chucko/i386/boot2/graphics.c

File differences

branches/chucko/i386/boot2/graphics.c
5050
5151
5252
53
54
5553
5654
5755
......
7472
7573
7674
77
78
79
75
76
8077
8178
8279
......
8683
8784
8885
86
87
88
89
8990
9091
91
92
93
94
95
96
92
93
94
95
96
97
98
9799
98100
99101
......
109111
110112
111113
114
112115
113116
114117
......
123126
124127
125128
126
129
130
131
132
133
134
135
136
137
127138
128139
129140
......
173184
174185
175186
187
176188
177189
178190
179
191
192
180193
181194
182195
......
187200
188201
189202
190
191
192
193
203
204
205
206
207
194208
195209
196210
{
VBEInfoBlock vbeInfo;
int err, small;
char *buff = malloc(sizeof(char)*256);
if(!buff) return 0;
bzero( &vbeInfo, sizeof(vbeInfo) );
strcpy( (char*)&vbeInfo, "VBE2" );
{
VBEInfoBlock vbeInfo;
int err, small;
char *buff = malloc(sizeof(char)*256);
if(!buff) return 0;
char* buff = NULL;
bzero( &vbeInfo, sizeof(vbeInfo) );
strcpy( (char*)&vbeInfo, "VBE2" );
err = getVBEInfo( &vbeInfo );
if ( strncmp( (char *)vbeInfo.VESASignature, "VESA", 4 ) )
return 0;
buff = malloc(sizeof(char) * 256);
if (!buff)
return 0;
small = (vbeInfo.TotalMemory < 16);
sprintf(buff, "VESA v%d.%d %d%s (%s)\n",
vbeInfo.VESAVersion >> 8,
vbeInfo.VESAVersion & 0xf,
small ? (vbeInfo.TotalMemory * 64) : (vbeInfo.TotalMemory / 16),
small ? "KB" : "MB",
VBEDecodeFP(const char *, vbeInfo.OEMStringPtr) );
snprintf(buff, 256,
"VESA v%d.%d %d%s (%s)\n",
vbeInfo.VESAVersion >> 8,
vbeInfo.VESAVersion & 0xf,
small ? (vbeInfo.TotalMemory * 64) : (vbeInfo.TotalMemory / 16),
small ? "KB" : "MB",
VBEDecodeFP(const char *, vbeInfo.OEMStringPtr) );
return buff;
}
VBEModeInfoBlock modeInfo;
int err;
int line;
char* vbeInfoString = NULL;
bzero( &vbeInfo, sizeof(vbeInfo) );
strcpy( (char*)&vbeInfo, "VBE2" );
clearScreenRows(0, 24);
setCursorPosition( 0, 0, 1 );
printf( getVBEInfoString() );
vbeInfoString = getVBEInfoString();
if (!vbeInfoString) {
printf("Error: getVBEInfoString failed\n");
return;
}
printf("%s", vbeInfoString);
free(vbeInfoString);
vbeInfoString = NULL;
printf("Video modes supported:\n", VBEDecodeFP(const char *, vbeInfo.OEMStringPtr));
// Loop through the mode list, and find the matching mode.
char *buff=malloc(sizeof(char)*3072);
if(!buff) return 0;
int bufflen = 0;
// Loop through the mode list, and find the matching mode.
for ( modePtr = VBEDecodeFP( unsigned short *, vbeInfo.VideoModePtr );
*modePtr != modeEndOfList; modePtr++ )
(*modePtr != modeEndOfList) && (bufflen < 3072); /* prevent buffer overrun */
modePtr++ )
{
// Get mode information.
continue;
}
sprintf(buff+strlen(buff), "Mode %x: %dx%dx%d mm:%d attr:%x\n",
*modePtr, modeInfo.XResolution, modeInfo.YResolution,
modeInfo.BitsPerPixel, modeInfo.MemoryModel,
modeInfo.ModeAttributes);
bufflen +=
snprintf(buff+bufflen, 3072-bufflen, "Mode %x: %dx%dx%d mm:%d attr:%x\n",
*modePtr, modeInfo.XResolution, modeInfo.YResolution,
modeInfo.BitsPerPixel, modeInfo.MemoryModel,
modeInfo.ModeAttributes);
}
return buff;

Archive Download the corresponding diff file

Revision: 2310