mirror of
https://github.com/gnif/LookingGlass.git
synced 2026-08-22 07:01:30 +00:00
[client] config: reject malformed window geometry
This commit is contained in:
@@ -27,10 +27,12 @@
|
|||||||
#include "common/paths.h"
|
#include "common/paths.h"
|
||||||
#include "common/stringutils.h"
|
#include "common/stringutils.h"
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
// forwards
|
// forwards
|
||||||
static bool optRendererParse (struct Option * opt, const char * str);
|
static bool optRendererParse (struct Option * opt, const char * str);
|
||||||
@@ -813,6 +815,28 @@ static char * optRendererToString(struct Option * opt)
|
|||||||
return strdup(LG_Renderers[g_params.forceRendererIndex]->getName());
|
return strdup(LG_Renderers[g_params.forceRendererIndex]->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool parsePair(const char * str, long long * first, long long * second)
|
||||||
|
{
|
||||||
|
if (!str)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
char * end;
|
||||||
|
errno = 0;
|
||||||
|
const long long x = strtoll(str, &end, 10);
|
||||||
|
if (errno == ERANGE || end == str || *end != 'x')
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const char * next = end + 1;
|
||||||
|
errno = 0;
|
||||||
|
const long long y = strtoll(next, &end, 10);
|
||||||
|
if (errno == ERANGE || end == next || *end != '\0')
|
||||||
|
return false;
|
||||||
|
|
||||||
|
*first = x;
|
||||||
|
*second = y;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool optPosParse(struct Option * opt, const char * str)
|
static bool optPosParse(struct Option * opt, const char * str)
|
||||||
{
|
{
|
||||||
if (!str)
|
if (!str)
|
||||||
@@ -824,13 +848,16 @@ static bool optPosParse(struct Option * opt, const char * str)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sscanf(str, "%dx%d", &g_params.x, &g_params.y) == 2)
|
long long x;
|
||||||
{
|
long long y;
|
||||||
g_params.center = false;
|
if (!parsePair(str, &x, &y) ||
|
||||||
return true;
|
x < INT_MIN || x > INT_MAX || y < INT_MIN || y > INT_MAX)
|
||||||
}
|
return false;
|
||||||
|
|
||||||
return false;
|
g_params.x = (int)x;
|
||||||
|
g_params.y = (int)y;
|
||||||
|
g_params.center = false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static StringList optPosValues(struct Option * opt)
|
static StringList optPosValues(struct Option * opt)
|
||||||
@@ -863,17 +890,15 @@ static char * optPosToString(struct Option * opt)
|
|||||||
|
|
||||||
static bool optSizeParse(struct Option * opt, const char * str)
|
static bool optSizeParse(struct Option * opt, const char * str)
|
||||||
{
|
{
|
||||||
if (!str)
|
long long width;
|
||||||
|
long long height;
|
||||||
|
if (!parsePair(str, &width, &height) ||
|
||||||
|
width < 1 || width > UINT_MAX || height < 1 || height > UINT_MAX)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (sscanf(str, "%ux%u", &g_params.w, &g_params.h) == 2)
|
g_params.w = (unsigned int)width;
|
||||||
{
|
g_params.h = (unsigned int)height;
|
||||||
if (g_params.w < 1 || g_params.h < 1)
|
return true;
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static StringList optSizeValues(struct Option * opt)
|
static StringList optSizeValues(struct Option * opt)
|
||||||
|
|||||||
Reference in New Issue
Block a user