Keep getting error with email validation script

G

grocery_stocker

Tad said:
How was using & screwing him up?

Okay, this is late at night. I need to cook dinner and such. Here is
the best thing my minimum wage mind can came up with in terms of having
& screw himself. Say I modify the code such that:

#!/usr/bin/perl
use warnings;

#test value;
my $email = "cdalten\@eecs\.berkeley\.edu";
my $screw = "la";

sub valid_address($){
my ($addr) = @_;
my ($domain, $name, $valid);
($name, $domain) = (split/@/,$addr);
$valid = 0;

#yes I know I should used fork()/exec;
system("nslookup $domain");
}

&valid_address($email, $screw);

Notice that the number of arguments passed the function don't match.
I'm sure you could imagine someone accidently passing more args to the
function that necessary. When I run the code, I get

miss_xtc@linux:~/perl> ./val.pl
Note: nslookup is deprecated and may be removed from future releases.
Consider using the `dig' or `host' programs instead. Run nslookup with
the `-sil[ent]' option to prevent this message from appearing.
Server: 63.93.96.20
Address: 63.93.96.20#53

Non-authoritative answer:
Name: eecs.berkeley.edu
Address: 169.229.60.27
Name: eecs.berkeley.edu
Address: 169.229.60.161

The computer lets this code pass.

Now I remove the & from valid_address
#!/usr/bin/perl
use warnings;

#test value;
my $email = "cdalten\@eecs\.berkeley\.edu";
my $screw = "la";

sub valid_address($){
my ($addr) = @_;
my ($domain, $name, $valid);
($name, $domain) = (split/@/,$addr);
$valid = 0;

#yes I know I should used fork()/exec;
system("nslookup $domain");
}

#note, no & thingy.
valid_address($email, $screw);

Now, when I run the code, I get
miss_xtc@linux:~/perl> ./val.pl
Too many arguments for main::valid_address at ./val.pl line 18, near
"$screw)"
Execution of ./val.pl aborted due to compilation errors.

Look, it won't pass. Maybe another time I'll take up more one the whole
system() thingy. Did I miss the point? Look at me from the side, does
the dress make my ass look big?
 
T

Tad McClellan

grocery_stocker said:
Here is
the best thing my minimum wage mind can came up with in terms of having
& screw himself. Say I modify the code such that:


If you modify the code, then you are answering a question from
the one that I posed.

I know full well the effect of using an ampersand on function calls,
but none of those effects are going to happen in the code you claimed
was "screwed". It does not use prototypes, and it does not call
functions with no argument list, so using an ampersand does NOT
screw anything up.

Claiming that using the ampersand is a problem for the OP is
simply leading him on a wild goose chase.
 
P

Peter J. Holzer

Tad said:
What is unsafe about the system() function?

Using the shell is certainly unsafe, but you can use the system()
function in such a way that it won't use a shell.

Is that what you meant?

I should probably explore this before I shoot off my mouth, but under
*nix, you can screw yourself with system() by having the user do
something really inane with the input. Like

char arr[200];
system(arr);

The user then can go like
ls -al; rm

That's not Unix, that's C. The C language defines a standard library
function called "system". The Perl language also defines a standard
function called "system". Both are system dependent [0] and they closely
related, but they are not the same. At least on Unix systems, Perl
"system" can be often be used in a safe manner with user-supplied input,
while C "system" cannot.
This is because system() under *nix uses the fork/exec model.

No, this is because C system invokes the shell.
So is the behavior different using Perl?

Yes. Perl system doesn't necessarily invoke the shell. Please read
perldoc -f system.

hp

[0] I.e., C "system" doesn't do the same thing on Unix and Windows, and
neither does Perl "system".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,279
Latest member
LaRoseDermaBottle

Latest Threads

Top