WINED3D: Better version string parsing for VENDOR_NVIDIA in
IWineD3DImpl_FillGLCaps
H. Verbeet
hverbeet at gmail.com
Wed Jan 18 17:02:08 CST 2006
The current code for parsing nVidia version strings in
IWineD3DImpl_FillGLCaps doesn't check the result of strstr calls for
NULL pointers. Also, copying the version numbers to a temporary buffer
of a fixed size before passing them to atoi is both unsafe and
unnessecary, since atoi is defined to only convert the initial portion
of the string passed to it anyway.
Changelog:
- Better version string parsing for VENDOR_NVIDIA in IWineD3DImpl_FillGLCaps
-------------- next part --------------
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index 466d3e4..07543bb 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -268,30 +268,38 @@ static BOOL IWineD3DImpl_FillGLCaps(Wine
switch (gl_info->gl_vendor) {
case VENDOR_NVIDIA:
gl_string_cursor = strstr(gl_string, "NVIDIA");
+ if (!gl_string_cursor) {
+ ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
+ break;
+ }
+
gl_string_cursor = strstr(gl_string_cursor, " ");
- while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
- if (*gl_string_cursor) {
- char tmp[16];
- int cursor = 0;
+ if (!gl_string_cursor) {
+ ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
+ break;
+ }
- while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
- tmp[cursor++] = *gl_string_cursor;
- ++gl_string_cursor;
- }
- tmp[cursor] = 0;
- major = atoi(tmp);
+ while (*gl_string_cursor == ' ') {
+ ++gl_string_cursor;
+ }
- if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
+ if (!*gl_string_cursor) {
+ ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
+ break;
+ }
+
+ major = atoi(gl_string_cursor);
+ while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
++gl_string_cursor;
+ }
- cursor = 0;
- while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
- tmp[cursor++] = *gl_string_cursor;
- ++gl_string_cursor;
- }
- tmp[cursor] = 0;
- minor = atoi(tmp);
+ if (*gl_string_cursor++ != '.') {
+ ERR_(d3d_caps)("Invalid nVidia version string: %s\n", debugstr_a(gl_string));
+ break;
}
+
+ minor = atoi(gl_string_cursor);
+
break;
case VENDOR_ATI:
More information about the wine-patches
mailing list