Sun, 17 Jul 2011 20:55:12 +0000
Complete the conversion of win32 utsname construction to bounds-checked access.
This patch changes strcat to g_strlcat with appropriate bounds.
| 3630 | 1 | /* |
| 2 | posix.uname.c - version 1.1 | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
23074
diff
changeset
|
3 | Copyright (C) 1999, 2000 |
| 3630 | 4 | Earnie Boyd and assigns |
| 5 | ||
| 6 | Fills the utsname structure with the appropriate values. | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
23074
diff
changeset
|
7 | |
| 3630 | 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU Lesser General Public License as published | |
| 10 | by the Free Software Foundation; either version 2.1, or (at your option) | |
| 11 | any later version. | |
| 12 | ||
| 13 | This program is distributed in the hope that it will be useful, | |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICUALR PURPOSE. See the | |
| 16 | GNU Lesser General Public License for more details. | |
| 17 | ||
| 18 | You should have received a copy of the GNU General Public License | |
| 19 | along with this program; if not, write to the Free Software Foundation, | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15435
diff
changeset
|
20 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301, USA. |
| 3630 | 21 | */ |
| 22 | ||
| 23 | /* | |
| 24 | Send bug reports to Earnie Boyd <earnie_boyd@yahoo.com> | |
| 25 | */ | |
| 26 | ||
| 27 | #include "utsname.h" | |
| 28 | #include <string.h> | |
| 29 | #include <stdio.h> | |
| 30 | ||
| 31 | /* ANONYMOUS unions and structs are used from the windows header definitions. | |
| 32 | These need to be defined for them to work correctly with gcc2.95.2-mingw. */ | |
| 33 | /*#define _ANONYMOUS_STRUCT*/ | |
| 34 | /*#define _ANONYMOUS_UNION*/ | |
| 35 | #include <windows.h> | |
| 23074 | 36 | #ifdef __MINGW32__ |
| 3630 | 37 | #include <_mingw.h> |
| 23074 | 38 | #endif |
| 3630 | 39 | |
| 40 | int | |
| 23074 | 41 | jabber_win32_uname( struct utsname *uts ) |
| 3630 | 42 | { |
| 43 | DWORD sLength; | |
| 44 | OSVERSIONINFO OS_version; | |
| 45 | SYSTEM_INFO System_Info; | |
| 46 | ||
| 47 | /* XXX Should these be in the global runtime */ | |
| 48 | enum WinOS {Win95, Win98, WinNT, unknown}; | |
| 49 | int MingwOS; | |
| 50 | ||
| 51 | memset( uts, 0, sizeof ( *uts ) ); | |
| 52 | OS_version.dwOSVersionInfoSize = sizeof( OSVERSIONINFO ); | |
| 53 | ||
| 54 | GetVersionEx ( &OS_version ); | |
| 55 | GetSystemInfo ( &System_Info ); | |
| 56 | ||
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
57 | g_strlcpy( uts->sysname, "WIN32_" , sizeof(uts->sysname)); |
| 3630 | 58 | switch( OS_version.dwPlatformId ) |
| 59 | { | |
| 60 | case VER_PLATFORM_WIN32_NT: | |
|
31960
d98bb67efec6
Complete the conversion of win32 utsname construction to bounds-checked access.
Ethan Blanton <elb@pidgin.im>
parents:
31959
diff
changeset
|
61 | g_strlcat( uts->sysname, "WinNT", sizeof(uts->sysname) ); |
| 3630 | 62 | MingwOS = WinNT; |
| 63 | break; | |
| 64 | case VER_PLATFORM_WIN32_WINDOWS: | |
| 65 | switch ( OS_version.dwMinorVersion ) | |
| 66 | { | |
| 67 | case 0: | |
|
31960
d98bb67efec6
Complete the conversion of win32 utsname construction to bounds-checked access.
Ethan Blanton <elb@pidgin.im>
parents:
31959
diff
changeset
|
68 | g_strlcat( uts->sysname, "Win95", sizeof(uts->sysname) ); |
| 3630 | 69 | MingwOS = Win95; |
| 70 | break; | |
| 71 | case 10: | |
|
31960
d98bb67efec6
Complete the conversion of win32 utsname construction to bounds-checked access.
Ethan Blanton <elb@pidgin.im>
parents:
31959
diff
changeset
|
72 | g_strlcat( uts->sysname, "Win98", sizeof(uts->sysname) ); |
| 3630 | 73 | MingwOS = Win98; |
| 74 | break; | |
| 75 | default: | |
|
31960
d98bb67efec6
Complete the conversion of win32 utsname construction to bounds-checked access.
Ethan Blanton <elb@pidgin.im>
parents:
31959
diff
changeset
|
76 | g_strlcat( uts->sysname, "Win??", sizeof(uts->sysname) ); |
| 3630 | 77 | MingwOS = unknown; |
| 78 | break; | |
| 79 | } | |
| 80 | break; | |
| 81 | default: | |
|
31960
d98bb67efec6
Complete the conversion of win32 utsname construction to bounds-checked access.
Ethan Blanton <elb@pidgin.im>
parents:
31959
diff
changeset
|
82 | g_strlcat( uts->sysname, "Win??", sizeof(uts->sysname) ); |
| 3630 | 83 | MingwOS = unknown; |
| 84 | break; | |
| 85 | } | |
| 86 | ||
| 23074 | 87 | #ifdef __MINGW32__ |
| 3630 | 88 | sprintf( uts->version, "%i", __MINGW32_MAJOR_VERSION ); |
| 89 | sprintf( uts->release, "%i", __MINGW32_MINOR_VERSION ); | |
| 23074 | 90 | #endif |
| 3630 | 91 | |
| 92 | switch( System_Info.wProcessorArchitecture ) | |
| 93 | { | |
| 94 | case PROCESSOR_ARCHITECTURE_PPC: | |
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
95 | g_strlcpy( uts->machine, "ppc" , sizeof( uts->machine ) ); |
| 3630 | 96 | break; |
| 97 | case PROCESSOR_ARCHITECTURE_ALPHA: | |
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
98 | g_strlcpy( uts->machine, "alpha" , sizeof( uts->machine ) ); |
| 3630 | 99 | break; |
| 100 | case PROCESSOR_ARCHITECTURE_MIPS: | |
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
101 | g_strlcpy( uts->machine, "mips" , sizeof( uts->machine ) ); |
| 3630 | 102 | break; |
| 103 | case PROCESSOR_ARCHITECTURE_INTEL: | |
| 104 | /* dwProcessorType is only valid in Win95 and Win98 | |
| 105 | wProcessorLevel is only valid in WinNT */ | |
| 106 | switch( MingwOS ) | |
| 107 | { | |
| 108 | case Win95: | |
| 109 | case Win98: | |
| 110 | switch( System_Info.dwProcessorType ) | |
| 111 | { | |
| 112 | case PROCESSOR_INTEL_386: | |
| 113 | case PROCESSOR_INTEL_486: | |
| 114 | case PROCESSOR_INTEL_PENTIUM: | |
| 115 | sprintf( uts->machine, "i%ld", System_Info.dwProcessorType ); | |
| 116 | break; | |
| 117 | default: | |
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
118 | g_strlcpy( uts->machine, "i386" , sizeof( uts->machine ) ); |
| 3630 | 119 | break; |
| 120 | } | |
| 121 | break; | |
| 122 | case WinNT: | |
| 123 | sprintf( uts->machine, "i%d86", System_Info.wProcessorLevel ); | |
| 124 | break; | |
| 125 | default: | |
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
126 | g_strlcpy( uts->machine, "unknown" , sizeof( uts->machine ) ); |
| 3630 | 127 | break; |
| 128 | } | |
| 129 | break; | |
| 130 | default: | |
|
31959
116ec59ce4ea
Fill out struct utsname on win32 using g_strlcpy instead of strcpy.
Ethan Blanton <elb@pidgin.im>
parents:
31294
diff
changeset
|
131 | g_strlcpy( uts->machine, "unknown" , sizeof( uts->machine ) ); |
| 3630 | 132 | break; |
| 133 | } | |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
23074
diff
changeset
|
134 | |
| 3630 | 135 | sLength = sizeof ( uts->nodename ) - 1; |
| 136 | GetComputerNameA( uts->nodename, &sLength ); | |
| 137 | return 1; | |
| 138 | } | |
| 139 |