tags:

views:

176

answers:

4

Heres my simple html source

<html>
<head>
<title>
Dec2Bin
</title>
<script type="text/javascript">
function  app()
{
var decimal = prompt("Numero en Decimal");
alert("El numero " + decimal + " en codigo binario es igual a " + dec2bin(decimal));
}
function dec2bin(decimal)
{
var binario="";
while(decimal!=0)
{
if(decimal % 2==0)
{
binario+="1";
}
else
{
binario+="0"
}
decimal=decimal/2
}

return binario ;
}
</script>
</head>
<body>
<input type="button" onclick="app()" value="Procesar" />
</body>
</html>

Avg keeps telling me its a virus.. if I remove the javascript it stops... what can I do?

+2  A: 

I'm not 100% sure if this is the cause, but your while-loop:

while(decimal!=0)
{
if(decimal % 2==0)
binario+="1";
else
binario+="0"
}

doesn't terminate because decimal doesn't change until outside the loop. Thus, running that loop should lock up your browser.


The only other thing I can see in your updated code is that your prompt does not coerce decimal to a number.

If the user doesn't input a number, decimal/2 will return NaN, which will never equal zero, so your loop won't terminate. I would suggest using parseInt to convert to an integer, and then if that returns NaN, you could either assign 0 to decimal or find some other way to skip your while-loop (such as changing your while-loop's condition to decimal != 0 || decimal != NaN.

I doubt that an anti-virus would pick that up, but it's not impossible.

Mark Rushakoff
I just fixed and it still keeps saying its a virus.... arrhghhh
NachoF
Post your updated code.
Mark Rushakoff
+3  A: 

You appear to have an endless loop because decimal will never equal 0. I could see where AVG might not like this.

function dec2bin(decimal) {
    var binario="";
    while(decimal!=0) {
        if(decimal % 2==0)
            binario+="1";
        else
            binario+="0"
    }
    decimal/=2
    return binario ;
}

I did a quick google search and pulled up a cleaner function:

function dec2bin(dec) {
    var bits = [];
    var remainder = 0;
    while (dec >= 2) {
        remainder = dec % 2;
        bits.push(remainder);
        dec = (dec - remainder) / 2;
    }
    bits.push(dec);
    bits.reverse();
    return bits.join("");
}
cballou
What about `number.toString(2);` :-)
CMS
A: 

Best thing to do is uninstall AVG. Virus scanners are a scam, and they significantly reduce the performance of your machine. If you're really worried about malware, best thing to do is install ubuntu as the main OS of your machine and run windows inside a VM such as virtual box.

Breton
Okay, so downvotes for really great advice? what has this site come to?
Breton
Not particularly relevent or true. He asked why his code was being flagged as a virus, not anything to do with malware or avoiding it.
SLC
What a weird answer... I would like the recipe for chocolate cake... Answer by Breton: Why don't you eat a hamburger? Or maybe you do not have to eat, just watch tv.
enguerran
More like: My car alarm keeps going off? what can I do? Uninstall car alarm. they don't work anyway.
Breton
That is: AVG is probably flagging it because it's javascript, not because of anything actually in the content of the javascript. Virus Scanners are inneffective means of protection, and only cause harm, and a false sense of security. Best thing to do is get rid of the things.
Breton
I don't understand how anyone can describe antivirus as a scam. People at my place of work get both virus attachments and legitimate attachments in their e-mails all the time, and the antivirus removes the viruses.All it would take is one click of Document.doc.exe and our network would be compromised without them.
SLC
Don't open suspicious attachments, simple as that. A virus scanner won't save you from the latest viruses, they are released at such a rapid rate the vendors can't keep up. The only viruses you're protected from are OLD threats that nobody is using anymore.
Breton
SLC: You need to be blocking all EXEs from mail period. Anti-virus is increasingly ineffective at detecting the enormous amount of trojans and exploits out there; if you are relying solely on AV to stop your users running mail-borne executables you are going to get hit bad.
bobince
@bobince THANK YOU, I was starting to think SO was taken over by people who only started using a computer last year. Basically, the malware problem is so bad, that if you really want to deal with it, you should be using virtual machines, and keep a clean backup image. Using antivirus is a bit like trying to protect yourself from robbery by wearing a heavy suit of armour. While you're busy writhing on the ground trying to stand up, your theieves have easy access to your back pocket and can just pick it out and stroll away, to stretch the metaphore. If AVG is causing you a problem, get rid of it
Breton
Okay so the smoke still hasn't cleared yet? why is this still being downvoted? yerg. How about reading some post 1999 security literature guys?
Breton
There's a lot of things we need, sadly unless you have the luxury of being the first person ever to do your job you don't get much choice of what infrastructure there is in place. We don't have an exchange server, and our hosting company has sucky options for mail filtering.
SLC
+1  A: 

Whilst it would be lovely if AV tools could automatically solve the halting problem(!), it is likely just another in a long string of false positives from today's utterly hopeless anti-virus industry. Maybe renaming some variables and moving the code about a bit would stop it in the short term, but in general false positives are a tiresome fact of life for any programmer.

The only other thing to check is: is AVG detecting that exact source posted above in a local file with nothing else in it as a virus? For me, AVG at virustotal is not flagging such a file as suspicious. Does it only detect it online? If so you would need to inspect the View->Source to see that there hasn't been a compromise on your server unexpectedly injecting a malicious script into the page at serve-time.

bobince