src/sensor/dummy/SDL_dummysensor.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 18 Feb 2019 07:50:33 -0800
changeset 12612 07c39cbbeacf
parent 12503 806492103856
permissions -rw-r--r--
Fixed bug 4500 - Heap-Buffer Overflow in Map1toN pertaining to SDL_pixels.c

Petr Pisar

The reproducer has these data in BITMAPINFOHEADER:

biSize = 40
biBitCount = 8
biClrUsed = 131075

SDL_LoadBMP_RW() function passes biBitCount as a color depth to SDL_CreateRGBSurface(), thus 256-color pallete is allocated. But then biClrUsed colors are read from a file and stored into the palette. SDL_LoadBMP_RW should report an error if biClrUsed is greater than 2^biBitCount.
slouken@12131
     1
/*
slouken@12131
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
slouken@12131
     4
slouken@12131
     5
  This software is provided 'as-is', without any express or implied
slouken@12131
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@12131
     7
  arising from the use of this software.
slouken@12131
     8
slouken@12131
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@12131
    10
  including commercial applications, and to alter it and redistribute it
slouken@12131
    11
  freely, subject to the following restrictions:
slouken@12131
    12
slouken@12131
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@12131
    14
     claim that you wrote the original software. If you use this software
slouken@12131
    15
     in a product, an acknowledgment in the product documentation would be
slouken@12131
    16
     appreciated but is not required.
slouken@12131
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@12131
    18
     misrepresented as being the original software.
slouken@12131
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@12131
    20
*/
slouken@12131
    21
slouken@12131
    22
#include "SDL_config.h"
slouken@12131
    23
slouken@12131
    24
#if defined(SDL_SENSOR_DUMMY) || defined(SDL_SENSOR_DISABLED)
slouken@12131
    25
slouken@12131
    26
#include "SDL_error.h"
slouken@12131
    27
#include "SDL_sensor.h"
slouken@12131
    28
#include "SDL_dummysensor.h"
slouken@12131
    29
#include "../SDL_syssensor.h"
slouken@12131
    30
slouken@12131
    31
static int
slouken@12131
    32
SDL_DUMMY_SensorInit(void)
slouken@12131
    33
{
slouken@12131
    34
    return 0;
slouken@12131
    35
}
slouken@12131
    36
slouken@12131
    37
static int
slouken@12131
    38
SDL_DUMMY_SensorGetCount(void)
slouken@12131
    39
{
slouken@12131
    40
    return 0;
slouken@12131
    41
}
slouken@12131
    42
slouken@12131
    43
static void
slouken@12131
    44
SDL_DUMMY_SensorDetect(void)
slouken@12131
    45
{
slouken@12131
    46
}
slouken@12131
    47
slouken@12131
    48
static const char *
slouken@12131
    49
SDL_DUMMY_SensorGetDeviceName(int device_index)
slouken@12131
    50
{
slouken@12131
    51
    return NULL;
slouken@12131
    52
}
slouken@12131
    53
slouken@12131
    54
static SDL_SensorType
slouken@12131
    55
SDL_DUMMY_SensorGetDeviceType(int device_index)
slouken@12131
    56
{
slouken@12131
    57
    return SDL_SENSOR_INVALID;
slouken@12131
    58
}
slouken@12131
    59
slouken@12131
    60
static int
slouken@12131
    61
SDL_DUMMY_SensorGetDeviceNonPortableType(int device_index)
slouken@12131
    62
{
slouken@12131
    63
    return -1;
slouken@12131
    64
}
slouken@12131
    65
slouken@12131
    66
static SDL_SensorID
slouken@12131
    67
SDL_DUMMY_SensorGetDeviceInstanceID(int device_index)
slouken@12131
    68
{
slouken@12131
    69
    return -1;
slouken@12131
    70
}
slouken@12131
    71
slouken@12131
    72
static int
slouken@12131
    73
SDL_DUMMY_SensorOpen(SDL_Sensor *sensor, int device_index)
slouken@12131
    74
{
slouken@12131
    75
    return SDL_Unsupported();
slouken@12131
    76
}
slouken@12131
    77
    
slouken@12131
    78
static void
slouken@12135
    79
SDL_DUMMY_SensorUpdate(SDL_Sensor *sensor)
slouken@12131
    80
{
slouken@12131
    81
}
slouken@12131
    82
slouken@12131
    83
static void
slouken@12135
    84
SDL_DUMMY_SensorClose(SDL_Sensor *sensor)
slouken@12131
    85
{
slouken@12131
    86
}
slouken@12131
    87
slouken@12131
    88
static void
slouken@12131
    89
SDL_DUMMY_SensorQuit(void)
slouken@12131
    90
{
slouken@12131
    91
}
slouken@12131
    92
slouken@12131
    93
SDL_SensorDriver SDL_DUMMY_SensorDriver =
slouken@12131
    94
{
slouken@12131
    95
    SDL_DUMMY_SensorInit,
slouken@12131
    96
    SDL_DUMMY_SensorGetCount,
slouken@12131
    97
    SDL_DUMMY_SensorDetect,
slouken@12131
    98
    SDL_DUMMY_SensorGetDeviceName,
slouken@12131
    99
    SDL_DUMMY_SensorGetDeviceType,
slouken@12131
   100
    SDL_DUMMY_SensorGetDeviceNonPortableType,
slouken@12131
   101
    SDL_DUMMY_SensorGetDeviceInstanceID,
slouken@12131
   102
    SDL_DUMMY_SensorOpen,
slouken@12131
   103
    SDL_DUMMY_SensorUpdate,
slouken@12131
   104
    SDL_DUMMY_SensorClose,
slouken@12131
   105
    SDL_DUMMY_SensorQuit,
slouken@12131
   106
};
slouken@12131
   107
slouken@12131
   108
#endif /* SDL_SENSOR_DUMMY || SDL_SENSOR_DISABLED */
slouken@12131
   109
slouken@12131
   110
/* vi: set ts=4 sw=4 expandtab: */