diff options
author | Christian Hesse <mail@eworm.de> | 2013-07-11 01:58:42 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2013-07-11 01:58:42 +0200 |
commit | 8f4ae4338662e8ab26aca95b551756242727d45e (patch) | |
tree | edb4a4f28d9ce37126b7ff0b57a50684e458cd24 /cqrlogo.c | |
parent | dfd0d24855ccd75832dc5bcaafa77c60bee150de (diff) | |
download | cqrlogo-8f4ae4338662e8ab26aca95b551756242727d45e.tar.gz cqrlogo-8f4ae4338662e8ab26aca95b551756242727d45e.tar.zst |
make scale and border handling more robust
Diffstat (limited to 'cqrlogo.c')
-rw-r--r-- | cqrlogo.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -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) { |