diff options
-rw-r--r-- | config.def.h | 8 | ||||
-rw-r--r-- | cqrlogo.c | 10 |
2 files changed, 13 insertions, 5 deletions
diff --git a/config.def.h b/config.def.h index d95e45d..b54c7a3 100644 --- a/config.def.h +++ b/config.def.h @@ -1,9 +1,13 @@ /* pixels are scaled up by this factor */ -#define QRCODE_SCALE 2 +#define QRCODE_SCALE 2 +/* this is the maximum scale factor */ +#define QRCODE_MAX_SCALE 8 /* width of the border * this is defined to at least 4, but works well with less */ -# define QRCODE_BORDER 1 +# define QRCODE_BORDER 1 +/* this is the maximum border width */ +# define QRCODE_MAX_BORDER 8 /* error correction level used for QR code * possible values: QR_ECLEVEL_L (lowest, about 7% error can be corrected) @@ -168,7 +168,7 @@ int main(int argc, char **argv) { struct bitmap_t * bitmap; char *match = NULL; - int scale = QRCODE_SCALE, border = QRCODE_BORDER; + unsigned int scale = QRCODE_SCALE, border = QRCODE_BORDER; /* get query string for later use */ char * query_string = getenv("QUERY_STRING"); @@ -204,11 +204,15 @@ int main(int argc, char **argv) { if (query_string ) { /* do we have a special scale? */ if ((match = strstr(query_string, "scale=")) != NULL) - sscanf(match, "scale=%u", &scale); + if ((sscanf(match, "scale=%u", &scale)) > 0) + if (scale < 1 || scale > QRCODE_MAX_SCALE) + scale = QRCODE_SCALE; /* width of the border? */ if ((match = strstr(query_string, "border=")) != NULL) - sscanf(match, "border=%u", &border); + if ((sscanf(match, "border=%u", &border)) > 0) + if (border > QRCODE_MAX_BORDER) + border = QRCODE_BORDER; } if ((bitmap = encode_qrcode(http_referer, scale, border)) == NULL) { |