Skip to content
Snippets Groups Projects
Commit e8197404 authored by RSchirm's avatar RSchirm
Browse files

Schließen einiger Sicherheitslücken im code und änderung des LIKE Befehls zu...

Schließen einiger Sicherheitslücken im code und änderung des LIKE Befehls zu IS um Feherquellen zu beseitigen
parent fea7d697
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -2,6 +2,10 @@
#include <stdlib.h>
#include <string.h>
#define bool int
#define true 1
#define false 0
char program[60] = "./barcodesearcher ";
void setStringToOrigin (void) {
......@@ -22,11 +26,25 @@ void barcodeLength (char *input) {
int main (void)
{
char input[50];
char input[20];
bool wrongInput = false;
while(1) {
if(scanf("%s" , input))
if(fscanf(stdin, "%s" , input))
{
for (int i = 0; i < strlen(input) -1 && !wrongInput; i++)
{
if(input[i] < '0' || input[i] > '9'){
wrongInput = true;
}
}
if(strlen(input) > 13 || wrongInput) {
printf("wrong input!\n");
continue;
}
if(strlen(input)<13) {
barcodeLength(input);
}
......@@ -34,6 +52,7 @@ int main (void)
WEXITSTATUS(system(program));
setStringToOrigin();
}
fflush(stdin);
}
return 0;
}
......
#!/bin/sh
#der erste Teil des Barcode-scanners
temp=$(sqlite3 storage.db "SELECT * FROM database WHERE barcode LIKE '%$1%'")
temp=$(sqlite3 storage.db "SELECT * FROM database WHERE barcode IS '$1'")
if [ -n "$temp" ]
then
sqlite3 storage.db "REPLACE INTO temp (barcode,productName,companyName,productMass) SELECT * FROM database WHERE barcode LIKE '%$1%'"
sqlite3 storage.db "REPLACE INTO temp (barcode,productName,companyName,productMass) SELECT * FROM database WHERE barcode IS '$1'"
echo Produkt wurde in datenbank gefunden!
sqlite3 storage.db "SELECT * FROM temp WHERE barcode LIKE '%$1%'"
sqlite3 storage.db "SELECT * FROM temp WHERE barcode IS '$1'"
else
temp=$(curl -L -s "https://world.openfoodfacts.org/product/$1" \
......@@ -25,7 +25,7 @@ else
productMass=$(echo $temp | cut -d "-" -f3 | sed -r "/\s*/s///" | sed -r "/\s*/s///")
sqlite3 storage.db "REPLACE INTO temp VALUES ('$1','$productName','$companyName','$productMass')"
echo $productName von $companyName, $productMass wurde gefunden.
echo $productName $productMass von $companyName wurde gefunden!
else
echo produkt nicht gefunden!
......
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment