LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   a CGI written in C, problem with an fopen() system call (https://www.linuxquestions.org/questions/programming-9/a-cgi-written-in-c-problem-with-an-fopen-system-call-99879/)

Sm0k3 10-03-2003 12:58 PM

a CGI written in C, problem with an fopen() system call
 
hello everyone. i have a question regaurding fopen() system call in C (this program is a CGI)..

well, for some reason, this snippet of code errors... every other fopen() seems to work 'cept for this one, and i don't think i've done anything differently from my other fopen() calls

Code:

#define HASHES "/path/to/hashes"
/* arg1-arg6 + user + pass are parsed out elsewhere from
  getenv("QUERY_STRING")
 */
/* massive part of code omitted */
c_adduser(C_PARAM)
{
if(atoi(arg3) == 1)
  {
  char hashbuff[1024];
  char hash[1024];
  FILE *HashFile;
  char* HashArrayTable[2];
 
  sprintf(hash, "%s/%s", HASHES, arg5);
/***************** this is the problem **************************************/
  if((HashFile=fopen(hash, "r")) == NULL);
    {
    fprintf(stderr, "[%s] [error] [client: %s] ", ctime(time(NULL)), getenv("REMOTE_ADDR"));
    fprintf(stderr, "%s:", hash);
    perror("Unable to open");
    printf("Invalid service<p><p>\n");
    printf("<form method=\"GET\" action=\"http://futurenet.ath.cx/cgi-bin/webmin\">\n");
    printf("<input type=\"hidden\" name=\"page\" value=\"admin\">\n");
    printf("<input type=\"hidden\" name=\"arg1\" value=\"%s\">\n", arg1);
    printf("<input type=\"hidden\" name=\"arg2\" value=\"adduser\">\n");
    printf("<input type=\"hidden\" name=\"arg3\" value=\"1\">\n");
    printf("<b>Add User</b><p>\n");
    printf("User Name:&nbsp; <input type=\"text\" name=\"user\" size=\"20\" value=\"%s\"><p>\n", user);
    printf("Password:&nbsp; <input type=\"password\" name=\"pass\" size=\"20\"><p>\n");
    printf("Level:&nbsp; <input type=\"text\" name=\"arg4\" size=\"20\" value=\"%s\"><p>\n", arg4);
    printf("<b>*</b>Service:&nbsp; <select size=\"1\" name=\"arg5\">\n");
    dp=opendir(HASHES);
    while((dirp = readdir(dp)) != NULL){
      if(strcasecmp(dirp->d_name, " ") && strcasecmp(dirp->d_name, ".") && strcasecmp(dirp->d_name, ".."))
      {
        printf("<option>%s</option>\n", dirp->d_name);
      }
    }
    printf("</select>\n");
    closedir(dp);
    printf("<p><input type=\"submit\" name=\"arg6\" value=\"Add User\"><p>\n</form>\n");
    return(0);
    }
// code ommited
}
// lots more code omitted

for some reason, i get a "Numerical result out of range" when i try to fopen().. could anyone shed some light on the subject:Pengy:

eric.r.turner 10-03-2003 02:11 PM

Re: a CGI written in C, problem with an fopen() system call
 
I don't know if this is related, but you probably don't want that semicolon on end of the if statement.

Code:

  if((HashFile=fopen(hash, "r")) == NULL);

Sm0k3 10-03-2003 02:18 PM

errrr..... that would help :-P... see what happens when a person codes half asleep at 3:30 in the morning...

:newbie:


All times are GMT -5. The time now is 08:36 AM.