| 1 | ################################################################################ |
1 | ################################################################################ |
| 2 | # WeBWorK Online Homework Delivery System |
2 | # WeBWorK Online Homework Delivery System |
| 3 | # Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/ |
3 | # Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/Problem.pm,v 1.196 2006/03/02 16:50:39 apizer Exp $ |
4 | # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/Problem.pm,v 1.197 2006/03/02 17:03:54 apizer Exp $ |
| 5 | # |
5 | # |
| 6 | # This program is free software; you can redistribute it and/or modify it under |
6 | # This program is free software; you can redistribute it and/or modify it under |
| 7 | # the terms of either: (a) the GNU General Public License as published by the |
7 | # the terms of either: (a) the GNU General Public License as published by the |
| 8 | # Free Software Foundation; either version 2, or (at your option) any later |
8 | # Free Software Foundation; either version 2, or (at your option) any later |
| 9 | # version, or (b) the "Artistic License" which comes with this package. |
9 | # version, or (b) the "Artistic License" which comes with this package. |
| … | |
… | |
| 457 | my $userProblemClass = $db->{problem_user}->{record}; |
457 | my $userProblemClass = $db->{problem_user}->{record}; |
| 458 | my $globalProblem = $db->getGlobalProblem($setName, $problemNumber); # checked |
458 | my $globalProblem = $db->getGlobalProblem($setName, $problemNumber); # checked |
| 459 | # if the global problem doesn't exist either, bail! |
459 | # if the global problem doesn't exist either, bail! |
| 460 | if(not defined $globalProblem) { |
460 | if(not defined $globalProblem) { |
| 461 | my $sourceFilePath = $r->param("sourceFilePath"); |
461 | my $sourceFilePath = $r->param("sourceFilePath"); |
| 462 | die "sourceFilePath is unsafe!" unless path_is_subdir($sourceFilePath, $ce->{courseDirs}->{templates}); |
462 | die "sourceFilePath is unsafe!" unless path_is_subdir($sourceFilePath, $ce->{courseDirs}->{templates}, 1); # 1==path can be relative to dir |
| 463 | # These are problems from setmaker. If declared invalid, they won't come up |
463 | # These are problems from setmaker. If declared invalid, they won't come up |
| 464 | $self->{invalidProblem} = $self->{invalidSet} = 1 unless defined $sourceFilePath; |
464 | $self->{invalidProblem} = $self->{invalidSet} = 1 unless defined $sourceFilePath; |
| 465 | # die "Problem $problemNumber in set $setName does not exist" unless defined $sourceFilePath; |
465 | # die "Problem $problemNumber in set $setName does not exist" unless defined $sourceFilePath; |
| 466 | $problem = fake_problem($db); |
466 | $problem = fake_problem($db); |
| 467 | $problem->problem_id(1); |
467 | $problem->problem_id(1); |
| … | |
… | |
| 486 | |
486 | |
| 487 | # if the caller is asking to override the source file, and |
487 | # if the caller is asking to override the source file, and |
| 488 | # editMode calls for a temporary file, do so |
488 | # editMode calls for a temporary file, do so |
| 489 | my $sourceFilePath = $r->param("sourceFilePath"); |
489 | my $sourceFilePath = $r->param("sourceFilePath"); |
| 490 | if (defined $editMode and $editMode eq "temporaryFile" and defined $sourceFilePath) { |
490 | if (defined $editMode and $editMode eq "temporaryFile" and defined $sourceFilePath) { |
| 491 | die "sourceFilePath is unsafe!" unless path_is_subdir($sourceFilePath, $ce->{courseDirs}->{templates}); |
491 | die "sourceFilePath is unsafe!" unless path_is_subdir($sourceFilePath, $ce->{courseDirs}->{templates}, 1); # 1==path can be relative to dir |
| 492 | $problem->source_file($sourceFilePath); |
492 | $problem->source_file($sourceFilePath); |
| 493 | } |
493 | } |
| 494 | |
494 | |
| 495 | # if the problem does not have a source file or no source file has been passed in |
495 | # if the problem does not have a source file or no source file has been passed in |
| 496 | # then this is really an invalid problem (probably from a bad URL) |
496 | # then this is really an invalid problem (probably from a bad URL) |