]> git.mxchange.org Git - flightgear.git/blob - src/GUI/AirportList.cxx
Frederic Bouvier discovered a buffer overflow in the airport select dialog.
[flightgear.git] / src / GUI / AirportList.cxx
1 #include <string.h>     // strncpy()
2
3 #include <Main/globals.hxx>
4 #include <Airports/simple.hxx>
5
6 #include "AirportList.hxx"
7
8
9 AirportList::AirportList (int x, int y, int width, int height)
10     : puList(x, y, width, height)
11 {
12     char buf[1024];
13
14     _airports = globals->get_airports();
15     _nAirports = _airports->size();
16
17     _content = new char *[_nAirports+1];
18     for (int i = 0; i < _nAirports; i++) {
19         const FGAirport *airport = _airports->getAirport(i);
20         snprintf(buf, 1023, "%s  %s\0",
21                  airport->id.c_str(),
22                  airport->name.c_str());
23
24         unsigned int buf_len = (strlen(buf) > 1023) ? 1023 : strlen(buf);
25         
26         _content[i] = new char[buf_len+1];
27         memcpy(_content[i], buf, buf_len);
28         _content[i][buf_len] = '\0';
29     }
30     _content[_nAirports] = 0;
31     newList(_content);
32 }
33
34 AirportList::~AirportList ()
35 {
36     for (int i = 0; i < _nAirports; i++) {
37         delete _content[i];
38         _content[i] = 0;
39     }
40     delete [] _content;
41 }
42
43 char *
44 AirportList::getStringValue ()
45 {
46     return (char *)_airports->getAirport(getIntegerValue())->id.c_str();
47 }
48
49 // end of AirportList.cxx
50