idx
int64
func_before
string
Vulnerability Classification
string
vul
int64
func_after
string
patch
string
CWE ID
string
lines_before
string
lines_after
string
13,300
FileTransfer::RemoveInputFiles(const char *sandbox_path) { char *old_iwd; int old_transfer_flag; StringList do_not_remove; const char *f; if (!sandbox_path) { ASSERT(SpoolSpace); sandbox_path = SpoolSpace; } if ( !IsDirectory(sandbox_path) ) { return; } old_iwd = Iwd; old_transfer_flag = m_final_transfer_flag; Iwd = strdup(sandbox_path); m_final_transfer_flag = 1; ComputeFilesToSend(); if ( FilesToSend == NULL ) { FilesToSend = OutputFiles; EncryptFiles = EncryptOutputFiles; DontEncryptFiles = DontEncryptOutputFiles; } FilesToSend->rewind(); while ( (f=FilesToSend->next()) ) { do_not_remove.append( condor_basename(f) ); } Directory dir( sandbox_path, desired_priv_state ); while( (f=dir.Next()) ) { if( dir.IsDirectory() ) { continue; } if ( do_not_remove.file_contains(f) == TRUE ) { continue; } dir.Remove_Current_File(); } m_final_transfer_flag = old_transfer_flag; free(Iwd); Iwd = old_iwd; return; }
DoS Exec Code
0
FileTransfer::RemoveInputFiles(const char *sandbox_path) { char *old_iwd; int old_transfer_flag; StringList do_not_remove; const char *f; if (!sandbox_path) { ASSERT(SpoolSpace); sandbox_path = SpoolSpace; } if ( !IsDirectory(sandbox_path) ) { return; } old_iwd = Iwd; old_transfer_flag = m_final_transfer_flag; Iwd = strdup(sandbox_path); m_final_transfer_flag = 1; ComputeFilesToSend(); if ( FilesToSend == NULL ) { FilesToSend = OutputFiles; EncryptFiles = EncryptOutputFiles; DontEncryptFiles = DontEncryptOutputFiles; } FilesToSend->rewind(); while ( (f=FilesToSend->next()) ) { do_not_remove.append( condor_basename(f) ); } Directory dir( sandbox_path, desired_priv_state ); while( (f=dir.Next()) ) { if( dir.IsDirectory() ) { continue; } if ( do_not_remove.file_contains(f) == TRUE ) { continue; } dir.Remove_Current_File(); } m_final_transfer_flag = old_transfer_flag; free(Iwd); Iwd = old_iwd; return; }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,301
FileTransfer::SaveTransferInfo(bool success,bool try_again,int hold_code,int hold_subcode,char const *hold_reason) { Info.success = success; Info.try_again = try_again; Info.hold_code = hold_code; Info.hold_subcode = hold_subcode; if( hold_reason ) { Info.error_desc = hold_reason; } }
DoS Exec Code
0
FileTransfer::SaveTransferInfo(bool success,bool try_again,int hold_code,int hold_subcode,char const *hold_reason) { Info.success = success; Info.try_again = try_again; Info.hold_code = hold_code; Info.hold_subcode = hold_subcode; if( hold_reason ) { Info.error_desc = hold_reason; } }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,302
FileTransfer::SendTransferAck(Stream *s,bool success,bool try_again,int hold_code,int hold_subcode,char const *hold_reason) { SaveTransferInfo(success,try_again,hold_code,hold_subcode,hold_reason); if(!PeerDoesTransferAck) { dprintf(D_FULLDEBUG,"SendTransferAck: skipping transfer ack, because peer does not support it.\n"); return; } ClassAd ad; int result; if(success) { result = 0; } else if(try_again) { result = 1; //failed for transient reasons } else { result = -1; //failed -- do not try again (ie put on hold) } ad.Assign(ATTR_RESULT,result); if(!success) { ad.Assign(ATTR_HOLD_REASON_CODE,hold_code); ad.Assign(ATTR_HOLD_REASON_SUBCODE,hold_subcode); if(hold_reason) { ad.Assign(ATTR_HOLD_REASON,hold_reason); } } s->encode(); if(!ad.put(*s) || !s->end_of_message()) { char const *ip = NULL; if(s->type() == Sock::reli_sock) { ip = ((ReliSock *)s)->get_sinful_peer(); } dprintf(D_ALWAYS,"Failed to send download %s to %s.\n", success ? "acknowledgment" : "failure report", ip ? ip : "(disconnected socket)"); } }
DoS Exec Code
0
FileTransfer::SendTransferAck(Stream *s,bool success,bool try_again,int hold_code,int hold_subcode,char const *hold_reason) { SaveTransferInfo(success,try_again,hold_code,hold_subcode,hold_reason); if(!PeerDoesTransferAck) { dprintf(D_FULLDEBUG,"SendTransferAck: skipping transfer ack, because peer does not support it.\n"); return; } ClassAd ad; int result; if(success) { result = 0; } else if(try_again) { result = 1; //failed for transient reasons } else { result = -1; //failed -- do not try again (ie put on hold) } ad.Assign(ATTR_RESULT,result); if(!success) { ad.Assign(ATTR_HOLD_REASON_CODE,hold_code); ad.Assign(ATTR_HOLD_REASON_SUBCODE,hold_subcode); if(hold_reason) { ad.Assign(ATTR_HOLD_REASON,hold_reason); } } s->encode(); if(!ad.put(*s) || !s->end_of_message()) { char const *ip = NULL; if(s->type() == Sock::reli_sock) { ip = ((ReliSock *)s)->get_sinful_peer(); } dprintf(D_ALWAYS,"Failed to send download %s to %s.\n", success ? "acknowledgment" : "failure report", ip ? ip : "(disconnected socket)"); } }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,303
FileTransfer::SimpleInit(ClassAd *Ad, bool want_check_perms, bool is_server, ReliSock *sock_to_use, priv_state priv, bool use_file_catalog, bool is_spool) { char buf[ATTRLIST_MAX_EXPRESSION]; char *dynamic_buf = NULL; jobAd = *Ad; // save job ad if( did_init ) { return 1; } user_supplied_key = is_server ? FALSE : TRUE; dprintf(D_FULLDEBUG,"entering FileTransfer::SimpleInit\n"); /* in the case of SimpleINit being called inside of Init, this will simply assign the same value to itself. */ m_use_file_catalog = use_file_catalog; desired_priv_state = priv; if ( priv == PRIV_UNKNOWN ) { want_priv_change = false; } else { want_priv_change = true; } simple_sock = sock_to_use; if (Ad->LookupString(ATTR_JOB_IWD, buf) != 1) { dprintf(D_FULLDEBUG, "FileTransfer::SimpleInit: Job Ad did not have an iwd!\n"); return 0; } Iwd = strdup(buf); if ( want_check_perms ) { if (Ad->LookupString(ATTR_OWNER, buf) != 1) { dprintf(D_FULLDEBUG, "FileTransfer::SimpleInit: Job Ad did not have an owner!\n"); return 0; } #ifdef WIN32 char ntdomain[80]; char *p_ntdomain = ntdomain; if (Ad->LookupString(ATTR_NT_DOMAIN, ntdomain) != 1) { p_ntdomain = NULL; } perm_obj = new perm(); if ( !perm_obj->init(buf,p_ntdomain) ) { delete perm_obj; perm_obj = NULL; return 0; } #endif } dynamic_buf = NULL; if (Ad->LookupString(ATTR_TRANSFER_INPUT_FILES, &dynamic_buf) == 1) { InputFiles = new StringList(dynamic_buf,","); free(dynamic_buf); dynamic_buf = NULL; } else { InputFiles = new StringList(NULL,","); } if (Ad->LookupString(ATTR_JOB_INPUT, buf) == 1) { if ( ! nullFile(buf) ) { if ( !InputFiles->file_contains(buf) ) InputFiles->append(buf); } } if (IsClient() && simple_init && is_spool) { InputFiles->rewind(); const char *x; while ((x = InputFiles->next())) { if (IsUrl(x)) { InputFiles->deleteCurrent(); } } char *list = InputFiles->print_to_string(); dprintf(D_FULLDEBUG, "Input files: %s\n", list ? list : "" ); free(list); } if ( Ad->LookupString(ATTR_ULOG_FILE, buf) == 1 ) { UserLogFile = strdup(condor_basename(buf)); } if ( Ad->LookupString(ATTR_X509_USER_PROXY, buf) == 1 ) { X509UserProxy = strdup(buf); if ( !nullFile(buf) ) { if ( !InputFiles->file_contains(buf) ) InputFiles->append(buf); } } if ( Ad->LookupString(ATTR_OUTPUT_DESTINATION, buf) == 1 ) { OutputDestination = strdup(buf); dprintf(D_FULLDEBUG, "FILETRANSFER: using OutputDestination %s\n", buf); } char* Spool = NULL; if ( IsServer() ) { Spool = param("SPOOL"); } int Cluster = 0; int Proc = 0; Ad->LookupInteger(ATTR_CLUSTER_ID, Cluster); Ad->LookupInteger(ATTR_PROC_ID, Proc); m_jobid.sprintf("%d.%d",Cluster,Proc); if ( IsServer() && Spool ) { SpoolSpace = gen_ckpt_name(Spool,Cluster,Proc,0); TmpSpoolSpace = (char*)malloc( strlen(SpoolSpace) + 10 ); sprintf(TmpSpoolSpace,"%s.tmp",SpoolSpace); } if ( ((IsServer() && !simple_init) || (IsClient() && simple_init)) && (Ad->LookupString(ATTR_JOB_CMD, buf) == 1) ) { if ( IsServer() && Spool ) { ExecFile = gen_ckpt_name(Spool,Cluster,ICKPT,0); if ( access(ExecFile,F_OK | X_OK) < 0 ) { free(ExecFile); ExecFile = NULL; } } if ( !ExecFile ) { #ifdef WIN32 if ( perm_obj && (perm_obj->read_access(buf) != 1) ) { dprintf(D_ALWAYS, "FileTrans: permission denied reading %s\n",buf); return 0; } #endif ExecFile = strdup(buf); } int xferExec; if(!Ad->LookupBool(ATTR_TRANSFER_EXECUTABLE,xferExec)) { xferExec=1; } if ( xferExec && !InputFiles->file_contains(ExecFile) ) { InputFiles->append(ExecFile); } } dynamic_buf = NULL; if (Ad->LookupString(ATTR_SPOOLED_OUTPUT_FILES, &dynamic_buf) == 1 || Ad->LookupString(ATTR_TRANSFER_OUTPUT_FILES, &dynamic_buf) == 1) { OutputFiles = new StringList(dynamic_buf,","); free(dynamic_buf); dynamic_buf = NULL; } else { upload_changed_files = true; } int streaming = 0; JobStdoutFile = ""; if(Ad->LookupString(ATTR_JOB_OUTPUT, buf) == 1 ) { JobStdoutFile = buf; Ad->LookupBool( ATTR_STREAM_OUTPUT, streaming ); if( ! streaming && ! upload_changed_files && ! nullFile(buf) ) { if( OutputFiles ) { if( !OutputFiles->file_contains(buf) ) { OutputFiles->append( buf ); } } else { OutputFiles = new StringList(buf,","); } } } streaming = 0; JobStderrFile = ""; if( Ad->LookupString(ATTR_JOB_ERROR, buf) == 1 ) { JobStderrFile = buf; Ad->LookupBool( ATTR_STREAM_ERROR, streaming ); if( ! streaming && ! upload_changed_files && ! nullFile(buf) ) { if( OutputFiles ) { if( !OutputFiles->file_contains(buf) ) { OutputFiles->append( buf ); } } else { OutputFiles = new StringList(buf,","); } } } MyString ulog; if( jobAd.LookupString(ATTR_ULOG_FILE,ulog) ) { if( outputFileIsSpooled(ulog.Value()) ) { if( OutputFiles ) { if( !OutputFiles->file_contains(ulog.Value()) ) { OutputFiles->append(ulog.Value()); } } else { OutputFiles = new StringList(buf,","); } } } if (Ad->LookupString(ATTR_ENCRYPT_INPUT_FILES, buf) == 1) { EncryptInputFiles = new StringList(buf,","); } else { EncryptInputFiles = new StringList(NULL,","); } if (Ad->LookupString(ATTR_ENCRYPT_OUTPUT_FILES, buf) == 1) { EncryptOutputFiles = new StringList(buf,","); } else { EncryptOutputFiles = new StringList(NULL,","); } if (Ad->LookupString(ATTR_DONT_ENCRYPT_INPUT_FILES, buf) == 1) { DontEncryptInputFiles = new StringList(buf,","); } else { DontEncryptInputFiles = new StringList(NULL,","); } if (Ad->LookupString(ATTR_DONT_ENCRYPT_OUTPUT_FILES, buf) == 1) { DontEncryptOutputFiles = new StringList(buf,","); } else { DontEncryptOutputFiles = new StringList(NULL,","); } bool spooling_output = false; { if (Iwd && Spool) { if(!strncmp(Iwd,Spool,strlen(Spool))) { spooling_output = true; } } } if(IsServer() && !spooling_output) { if(!InitDownloadFilenameRemaps(Ad)) return 0; } CondorError e; I_support_filetransfer_plugins = false; plugin_table = NULL; InitializePlugins(e); int spool_completion_time = 0; Ad->LookupInteger(ATTR_STAGE_IN_FINISH,spool_completion_time); last_download_time = spool_completion_time; if(IsServer()) { BuildFileCatalog(last_download_time); } else { BuildFileCatalog(); } if ( Spool ) { free(Spool); } did_init = true; return 1; }
DoS Exec Code
0
FileTransfer::SimpleInit(ClassAd *Ad, bool want_check_perms, bool is_server, ReliSock *sock_to_use, priv_state priv, bool use_file_catalog, bool is_spool) { char buf[ATTRLIST_MAX_EXPRESSION]; char *dynamic_buf = NULL; jobAd = *Ad; // save job ad if( did_init ) { return 1; } user_supplied_key = is_server ? FALSE : TRUE; dprintf(D_FULLDEBUG,"entering FileTransfer::SimpleInit\n"); /* in the case of SimpleINit being called inside of Init, this will simply assign the same value to itself. */ m_use_file_catalog = use_file_catalog; desired_priv_state = priv; if ( priv == PRIV_UNKNOWN ) { want_priv_change = false; } else { want_priv_change = true; } simple_sock = sock_to_use; if (Ad->LookupString(ATTR_JOB_IWD, buf) != 1) { dprintf(D_FULLDEBUG, "FileTransfer::SimpleInit: Job Ad did not have an iwd!\n"); return 0; } Iwd = strdup(buf); if ( want_check_perms ) { if (Ad->LookupString(ATTR_OWNER, buf) != 1) { dprintf(D_FULLDEBUG, "FileTransfer::SimpleInit: Job Ad did not have an owner!\n"); return 0; } #ifdef WIN32 char ntdomain[80]; char *p_ntdomain = ntdomain; if (Ad->LookupString(ATTR_NT_DOMAIN, ntdomain) != 1) { p_ntdomain = NULL; } perm_obj = new perm(); if ( !perm_obj->init(buf,p_ntdomain) ) { delete perm_obj; perm_obj = NULL; return 0; } #endif } dynamic_buf = NULL; if (Ad->LookupString(ATTR_TRANSFER_INPUT_FILES, &dynamic_buf) == 1) { InputFiles = new StringList(dynamic_buf,","); free(dynamic_buf); dynamic_buf = NULL; } else { InputFiles = new StringList(NULL,","); } if (Ad->LookupString(ATTR_JOB_INPUT, buf) == 1) { if ( ! nullFile(buf) ) { if ( !InputFiles->file_contains(buf) ) InputFiles->append(buf); } } if (IsClient() && simple_init && is_spool) { InputFiles->rewind(); const char *x; while ((x = InputFiles->next())) { if (IsUrl(x)) { InputFiles->deleteCurrent(); } } char *list = InputFiles->print_to_string(); dprintf(D_FULLDEBUG, "Input files: %s\n", list ? list : "" ); free(list); } if ( Ad->LookupString(ATTR_ULOG_FILE, buf) == 1 ) { UserLogFile = strdup(condor_basename(buf)); } if ( Ad->LookupString(ATTR_X509_USER_PROXY, buf) == 1 ) { X509UserProxy = strdup(buf); if ( !nullFile(buf) ) { if ( !InputFiles->file_contains(buf) ) InputFiles->append(buf); } } if ( Ad->LookupString(ATTR_OUTPUT_DESTINATION, buf) == 1 ) { OutputDestination = strdup(buf); dprintf(D_FULLDEBUG, "FILETRANSFER: using OutputDestination %s\n", buf); } char* Spool = NULL; if ( IsServer() ) { Spool = param("SPOOL"); } int Cluster = 0; int Proc = 0; Ad->LookupInteger(ATTR_CLUSTER_ID, Cluster); Ad->LookupInteger(ATTR_PROC_ID, Proc); m_jobid.sprintf("%d.%d",Cluster,Proc); if ( IsServer() && Spool ) { SpoolSpace = gen_ckpt_name(Spool,Cluster,Proc,0); TmpSpoolSpace = (char*)malloc( strlen(SpoolSpace) + 10 ); sprintf(TmpSpoolSpace,"%s.tmp",SpoolSpace); } if ( ((IsServer() && !simple_init) || (IsClient() && simple_init)) && (Ad->LookupString(ATTR_JOB_CMD, buf) == 1) ) { if ( IsServer() && Spool ) { ExecFile = gen_ckpt_name(Spool,Cluster,ICKPT,0); if ( access(ExecFile,F_OK | X_OK) < 0 ) { free(ExecFile); ExecFile = NULL; } } if ( !ExecFile ) { #ifdef WIN32 if ( perm_obj && (perm_obj->read_access(buf) != 1) ) { dprintf(D_ALWAYS, "FileTrans: permission denied reading %s\n",buf); return 0; } #endif ExecFile = strdup(buf); } int xferExec; if(!Ad->LookupBool(ATTR_TRANSFER_EXECUTABLE,xferExec)) { xferExec=1; } if ( xferExec && !InputFiles->file_contains(ExecFile) ) { InputFiles->append(ExecFile); } } dynamic_buf = NULL; if (Ad->LookupString(ATTR_SPOOLED_OUTPUT_FILES, &dynamic_buf) == 1 || Ad->LookupString(ATTR_TRANSFER_OUTPUT_FILES, &dynamic_buf) == 1) { OutputFiles = new StringList(dynamic_buf,","); free(dynamic_buf); dynamic_buf = NULL; } else { upload_changed_files = true; } int streaming = 0; JobStdoutFile = ""; if(Ad->LookupString(ATTR_JOB_OUTPUT, buf) == 1 ) { JobStdoutFile = buf; Ad->LookupBool( ATTR_STREAM_OUTPUT, streaming ); if( ! streaming && ! upload_changed_files && ! nullFile(buf) ) { if( OutputFiles ) { if( !OutputFiles->file_contains(buf) ) { OutputFiles->append( buf ); } } else { OutputFiles = new StringList(buf,","); } } } streaming = 0; JobStderrFile = ""; if( Ad->LookupString(ATTR_JOB_ERROR, buf) == 1 ) { JobStderrFile = buf; Ad->LookupBool( ATTR_STREAM_ERROR, streaming ); if( ! streaming && ! upload_changed_files && ! nullFile(buf) ) { if( OutputFiles ) { if( !OutputFiles->file_contains(buf) ) { OutputFiles->append( buf ); } } else { OutputFiles = new StringList(buf,","); } } } MyString ulog; if( jobAd.LookupString(ATTR_ULOG_FILE,ulog) ) { if( outputFileIsSpooled(ulog.Value()) ) { if( OutputFiles ) { if( !OutputFiles->file_contains(ulog.Value()) ) { OutputFiles->append(ulog.Value()); } } else { OutputFiles = new StringList(buf,","); } } } if (Ad->LookupString(ATTR_ENCRYPT_INPUT_FILES, buf) == 1) { EncryptInputFiles = new StringList(buf,","); } else { EncryptInputFiles = new StringList(NULL,","); } if (Ad->LookupString(ATTR_ENCRYPT_OUTPUT_FILES, buf) == 1) { EncryptOutputFiles = new StringList(buf,","); } else { EncryptOutputFiles = new StringList(NULL,","); } if (Ad->LookupString(ATTR_DONT_ENCRYPT_INPUT_FILES, buf) == 1) { DontEncryptInputFiles = new StringList(buf,","); } else { DontEncryptInputFiles = new StringList(NULL,","); } if (Ad->LookupString(ATTR_DONT_ENCRYPT_OUTPUT_FILES, buf) == 1) { DontEncryptOutputFiles = new StringList(buf,","); } else { DontEncryptOutputFiles = new StringList(NULL,","); } bool spooling_output = false; { if (Iwd && Spool) { if(!strncmp(Iwd,Spool,strlen(Spool))) { spooling_output = true; } } } if(IsServer() && !spooling_output) { if(!InitDownloadFilenameRemaps(Ad)) return 0; } CondorError e; I_support_filetransfer_plugins = false; plugin_table = NULL; InitializePlugins(e); int spool_completion_time = 0; Ad->LookupInteger(ATTR_STAGE_IN_FINISH,spool_completion_time); last_download_time = spool_completion_time; if(IsServer()) { BuildFileCatalog(last_download_time); } else { BuildFileCatalog(); } if ( Spool ) { free(Spool); } did_init = true; return 1; }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,304
FileTransfer::UploadFiles(bool blocking, bool final_transfer) { ReliSock sock; ReliSock *sock_to_use; StringList changed_files(NULL,","); dprintf(D_FULLDEBUG, "entering FileTransfer::UploadFiles (final_transfer=%d)\n", final_transfer ? 1 : 0); if (ActiveTransferTid >= 0) { EXCEPT("FileTransfer::UpLoadFiles called during active transfer!\n"); } if ( Iwd == NULL ) { EXCEPT("FileTransfer: Init() never called"); } if ( !simple_init && IsServer() ) { EXCEPT("FileTransfer: UploadFiles called on server side"); } if ( UserLogFile && TransferUserLog && simple_init && !nullFile( UserLogFile ) ) { if ( !InputFiles->file_contains( UserLogFile ) ) InputFiles->append( UserLogFile ); } m_final_transfer_flag = final_transfer ? 1 : 0; ComputeFilesToSend(); if ( FilesToSend == NULL ) { if ( simple_init ) { if ( IsClient() ) { FilesToSend = InputFiles; EncryptFiles = EncryptInputFiles; DontEncryptFiles = DontEncryptInputFiles; } else { FilesToSend = OutputFiles; EncryptFiles = EncryptOutputFiles; DontEncryptFiles = DontEncryptOutputFiles; } } else { FilesToSend = OutputFiles; EncryptFiles = EncryptOutputFiles; DontEncryptFiles = DontEncryptOutputFiles; } } if ( !simple_init ) { if ( FilesToSend == NULL ) { return 1; } sock.timeout(clientSockTimeout); Daemon d( DT_ANY, TransSock ); if ( !d.connectSock(&sock,0) ) { dprintf( D_ALWAYS, "FileTransfer: Unable to connect to server " "%s\n", TransSock ); return FALSE; } d.startCommand(FILETRANS_DOWNLOAD, &sock, clientSockTimeout, NULL, NULL, false, m_sec_session_id); sock.encode(); if ( !sock.put_secret(TransKey) || !sock.end_of_message() ) { return 0; } dprintf( D_FULLDEBUG, "FileTransfer::UploadFiles: sent TransKey=%s\n", TransKey ); sock_to_use = &sock; } else { ASSERT(simple_sock); sock_to_use = simple_sock; } int retval = Upload(sock_to_use,blocking); return( retval ); }
DoS Exec Code
0
FileTransfer::UploadFiles(bool blocking, bool final_transfer) { ReliSock sock; ReliSock *sock_to_use; StringList changed_files(NULL,","); dprintf(D_FULLDEBUG, "entering FileTransfer::UploadFiles (final_transfer=%d)\n", final_transfer ? 1 : 0); if (ActiveTransferTid >= 0) { EXCEPT("FileTransfer::UpLoadFiles called during active transfer!\n"); } if ( Iwd == NULL ) { EXCEPT("FileTransfer: Init() never called"); } if ( !simple_init && IsServer() ) { EXCEPT("FileTransfer: UploadFiles called on server side"); } if ( UserLogFile && TransferUserLog && simple_init && !nullFile( UserLogFile ) ) { if ( !InputFiles->file_contains( UserLogFile ) ) InputFiles->append( UserLogFile ); } m_final_transfer_flag = final_transfer ? 1 : 0; ComputeFilesToSend(); if ( FilesToSend == NULL ) { if ( simple_init ) { if ( IsClient() ) { FilesToSend = InputFiles; EncryptFiles = EncryptInputFiles; DontEncryptFiles = DontEncryptInputFiles; } else { FilesToSend = OutputFiles; EncryptFiles = EncryptOutputFiles; DontEncryptFiles = DontEncryptOutputFiles; } } else { FilesToSend = OutputFiles; EncryptFiles = EncryptOutputFiles; DontEncryptFiles = DontEncryptOutputFiles; } } if ( !simple_init ) { if ( FilesToSend == NULL ) { return 1; } sock.timeout(clientSockTimeout); Daemon d( DT_ANY, TransSock ); if ( !d.connectSock(&sock,0) ) { dprintf( D_ALWAYS, "FileTransfer: Unable to connect to server " "%s\n", TransSock ); return FALSE; } d.startCommand(FILETRANS_DOWNLOAD, &sock, clientSockTimeout, NULL, NULL, false, m_sec_session_id); sock.encode(); if ( !sock.put_secret(TransKey) || !sock.end_of_message() ) { return 0; } dprintf( D_FULLDEBUG, "FileTransfer::UploadFiles: sent TransKey=%s\n", TransKey ); sock_to_use = &sock; } else { ASSERT(simple_sock); sock_to_use = simple_sock; } int retval = Upload(sock_to_use,blocking); return( retval ); }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,305
FileTransfer::UploadThread(void *arg, Stream *s) { dprintf(D_FULLDEBUG,"entering FileTransfer::UploadThread\n"); FileTransfer * myobj = ((upload_info *)arg)->myobj; filesize_t total_bytes; int status = myobj->DoUpload( &total_bytes, (ReliSock *)s ); if(!myobj->WriteStatusToTransferPipe(total_bytes)) { return 0; } return ( status >= 0 ); }
DoS Exec Code
0
FileTransfer::UploadThread(void *arg, Stream *s) { dprintf(D_FULLDEBUG,"entering FileTransfer::UploadThread\n"); FileTransfer * myobj = ((upload_info *)arg)->myobj; filesize_t total_bytes; int status = myobj->DoUpload( &total_bytes, (ReliSock *)s ); if(!myobj->WriteStatusToTransferPipe(total_bytes)) { return 0; } return ( status >= 0 ); }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,306
FileTransfer::addFileToExeptionList( const char* filename ) { if ( !ExceptionFiles ) { ExceptionFiles = new StringList; ASSERT ( NULL != ExceptionFiles ); } else if ( ExceptionFiles->file_contains ( filename ) ) { return true; } ExceptionFiles->append ( filename ); return true; }
DoS Exec Code
0
FileTransfer::addFileToExeptionList( const char* filename ) { if ( !ExceptionFiles ) { ExceptionFiles = new StringList; ASSERT ( NULL != ExceptionFiles ); } else if ( ExceptionFiles->file_contains ( filename ) ) { return true; } ExceptionFiles->append ( filename ); return true; }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,307
FileTransfer::addOutputFile( const char* filename ) { if( ! OutputFiles ) { OutputFiles = new StringList; ASSERT(OutputFiles != NULL); } else if( OutputFiles->file_contains(filename) ) { return true; } OutputFiles->append( filename ); return true; }
DoS Exec Code
0
FileTransfer::addOutputFile( const char* filename ) { if( ! OutputFiles ) { OutputFiles = new StringList; ASSERT(OutputFiles != NULL); } else if( OutputFiles->file_contains(filename) ) { return true; } OutputFiles->append( filename ); return true; }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,308
static unsigned int compute_filename_hash(const MyString &key) { return key.Hash(); }
DoS Exec Code
0
static unsigned int compute_filename_hash(const MyString &key) { return key.Hash(); }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,309
static unsigned int compute_transthread_hash(const int &pid) { return (unsigned int)pid; }
DoS Exec Code
0
static unsigned int compute_transthread_hash(const int &pid) { return (unsigned int)pid; }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,310
char const *destDir() { return dest_dir.c_str(); }
DoS Exec Code
0
char const *destDir() { return dest_dir.c_str(); }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,311
FileTransfer::outputFileIsSpooled(char const *fname) { if(fname) { if( is_relative_to_cwd(fname) ) { if( Iwd && SpoolSpace && strcmp(Iwd,SpoolSpace)==0 ) { return true; } } else if( SpoolSpace && strncmp(fname,SpoolSpace,strlen(SpoolSpace))==0 ) { return true; } } return false; }
DoS Exec Code
0
FileTransfer::outputFileIsSpooled(char const *fname) { if(fname) { if( is_relative_to_cwd(fname) ) { if( Iwd && SpoolSpace && strcmp(Iwd,SpoolSpace)==0 ) { return true; } } else if( SpoolSpace && strncmp(fname,SpoolSpace,strlen(SpoolSpace))==0 ) { return true; } } return false; }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,312
FileTransfer::setClientSocketTimeout(int timeout) { int old_val = clientSockTimeout; clientSockTimeout = timeout; return old_val; }
DoS Exec Code
0
FileTransfer::setClientSocketTimeout(int timeout) { int old_val = clientSockTimeout; clientSockTimeout = timeout; return old_val; }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,313
FileTransfer::setPeerVersion( const char *peer_version ) { CondorVersionInfo vi( peer_version ); setPeerVersion( vi ); }
DoS Exec Code
0
FileTransfer::setPeerVersion( const char *peer_version ) { CondorVersionInfo vi( peer_version ); setPeerVersion( vi ); }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,314
FileTransfer::setPeerVersion( const CondorVersionInfo &peer_version ) { if ( peer_version.built_since_version(6,7,7) ) { TransferFilePermissions = true; } else { TransferFilePermissions = false; } if ( peer_version.built_since_version(6,7,19) && param_boolean( "DELEGATE_JOB_GSI_CREDENTIALS", true ) ) { DelegateX509Credentials = true; } else { DelegateX509Credentials = false; } if ( peer_version.built_since_version(6,7,20) ) { PeerDoesTransferAck = true; } else { PeerDoesTransferAck = false; dprintf(D_FULLDEBUG, "FileTransfer: peer (version %d.%d.%d) does not support " "transfer ack. Will use older (unreliable) protocol.\n", peer_version.getMajorVer(), peer_version.getMinorVer(), peer_version.getSubMinorVer()); } if( peer_version.built_since_version(6,9,5) ) { PeerDoesGoAhead = true; } else { PeerDoesGoAhead = false; } if( peer_version.built_since_version(7,5,4) ) { PeerUnderstandsMkdir = true; } else { PeerUnderstandsMkdir = false; } if ( peer_version.built_since_version(7,6,0) ) { TransferUserLog = false; } else { TransferUserLog = true; } }
DoS Exec Code
0
FileTransfer::setPeerVersion( const CondorVersionInfo &peer_version ) { if ( peer_version.built_since_version(6,7,7) ) { TransferFilePermissions = true; } else { TransferFilePermissions = false; } if ( peer_version.built_since_version(6,7,19) && param_boolean( "DELEGATE_JOB_GSI_CREDENTIALS", true ) ) { DelegateX509Credentials = true; } else { DelegateX509Credentials = false; } if ( peer_version.built_since_version(6,7,20) ) { PeerDoesTransferAck = true; } else { PeerDoesTransferAck = false; dprintf(D_FULLDEBUG, "FileTransfer: peer (version %d.%d.%d) does not support " "transfer ack. Will use older (unreliable) protocol.\n", peer_version.getMajorVer(), peer_version.getMinorVer(), peer_version.getSubMinorVer()); } if( peer_version.built_since_version(6,9,5) ) { PeerDoesGoAhead = true; } else { PeerDoesGoAhead = false; } if( peer_version.built_since_version(7,5,4) ) { PeerUnderstandsMkdir = true; } else { PeerUnderstandsMkdir = false; } if ( peer_version.built_since_version(7,6,0) ) { TransferUserLog = false; } else { TransferUserLog = true; } }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,315
void FileTransfer::setSecuritySession(char const *session_id) { free(m_sec_session_id); m_sec_session_id = NULL; m_sec_session_id = session_id ? strdup(session_id) : NULL; }
DoS Exec Code
0
void FileTransfer::setSecuritySession(char const *session_id) { free(m_sec_session_id); m_sec_session_id = NULL; m_sec_session_id = session_id ? strdup(session_id) : NULL; }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,316
char const *srcName() { return src_name.c_str(); }
DoS Exec Code
0
char const *srcName() { return src_name.c_str(); }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,317
FileTransfer::~FileTransfer() { if (daemonCore && ActiveTransferTid >= 0) { dprintf(D_ALWAYS, "FileTransfer object destructor called during " "active transfer. Cancelling transfer.\n"); daemonCore->Kill_Thread(ActiveTransferTid); TransThreadTable->remove(ActiveTransferTid); ActiveTransferTid = -1; } if (TransferPipe[0] >= 0) close(TransferPipe[0]); if (TransferPipe[1] >= 0) close(TransferPipe[1]); if (Iwd) free(Iwd); if (ExecFile) free(ExecFile); if (UserLogFile) free(UserLogFile); if (X509UserProxy) free(X509UserProxy); if (SpoolSpace) free(SpoolSpace); if (TmpSpoolSpace) free(TmpSpoolSpace); if (ExceptionFiles) delete ExceptionFiles; if (InputFiles) delete InputFiles; if (OutputFiles) delete OutputFiles; if (EncryptInputFiles) delete EncryptInputFiles; if (EncryptOutputFiles) delete EncryptOutputFiles; if (DontEncryptInputFiles) delete DontEncryptInputFiles; if (DontEncryptOutputFiles) delete DontEncryptOutputFiles; if (OutputDestination) delete OutputDestination; if (IntermediateFiles) delete IntermediateFiles; if (SpooledIntermediateFiles) delete SpooledIntermediateFiles; if (last_download_catalog) { CatalogEntry *entry_pointer; last_download_catalog->startIterations(); while(last_download_catalog->iterate(entry_pointer)) { delete entry_pointer; } delete last_download_catalog; } if (TransSock) free(TransSock); if (TransKey) { if ( TranskeyTable ) { MyString key(TransKey); TranskeyTable->remove(key); if ( TranskeyTable->getNumElements() == 0 ) { delete TranskeyTable; TranskeyTable = NULL; delete TransThreadTable; TransThreadTable = NULL; } } free(TransKey); } #ifdef WIN32 if (perm_obj) delete perm_obj; #endif free(m_sec_session_id); }
DoS Exec Code
0
FileTransfer::~FileTransfer() { if (daemonCore && ActiveTransferTid >= 0) { dprintf(D_ALWAYS, "FileTransfer object destructor called during " "active transfer. Cancelling transfer.\n"); daemonCore->Kill_Thread(ActiveTransferTid); TransThreadTable->remove(ActiveTransferTid); ActiveTransferTid = -1; } if (TransferPipe[0] >= 0) close(TransferPipe[0]); if (TransferPipe[1] >= 0) close(TransferPipe[1]); if (Iwd) free(Iwd); if (ExecFile) free(ExecFile); if (UserLogFile) free(UserLogFile); if (X509UserProxy) free(X509UserProxy); if (SpoolSpace) free(SpoolSpace); if (TmpSpoolSpace) free(TmpSpoolSpace); if (ExceptionFiles) delete ExceptionFiles; if (InputFiles) delete InputFiles; if (OutputFiles) delete OutputFiles; if (EncryptInputFiles) delete EncryptInputFiles; if (EncryptOutputFiles) delete EncryptOutputFiles; if (DontEncryptInputFiles) delete DontEncryptInputFiles; if (DontEncryptOutputFiles) delete DontEncryptOutputFiles; if (OutputDestination) delete OutputDestination; if (IntermediateFiles) delete IntermediateFiles; if (SpooledIntermediateFiles) delete SpooledIntermediateFiles; if (last_download_catalog) { CatalogEntry *entry_pointer; last_download_catalog->startIterations(); while(last_download_catalog->iterate(entry_pointer)) { delete entry_pointer; } delete last_download_catalog; } if (TransSock) free(TransSock); if (TransKey) { if ( TranskeyTable ) { MyString key(TransKey); TranskeyTable->remove(key); if ( TranskeyTable->getNumElements() == 0 ) { delete TranskeyTable; TranskeyTable = NULL; delete TransThreadTable; TransThreadTable = NULL; } } free(TransKey); } #ifdef WIN32 if (perm_obj) delete perm_obj; #endif free(m_sec_session_id); }
@@ -2716,7 +2716,7 @@ FileTransfer::DoUpload(filesize_t *total_bytes, ReliSock *s) } // condor_basename works for URLs - dest_filename.sprintf_cat( condor_basename(filename) ); + dest_filename.sprintf_cat( "%s", condor_basename(filename) ); } // for command 999, this string must equal the Attribute "Filename" in
CWE-134
null
null
13,318
ReadUserLogState::BasePath( const ReadUserLog::FileState &state ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { return NULL; } return istate->m_base_path; }
DoS Exec Code
0
ReadUserLogState::BasePath( const ReadUserLog::FileState &state ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { return NULL; } return istate->m_base_path; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,319
ReadUserLogState::CheckFileStatus( int fd, bool &is_empty ) { StatWrapper sb; if ( fd >= 0 ) { (void) sb.Stat( fd ); } if ( m_cur_path.Length() && !sb.IsBufValid() ) { (void) sb.Stat( m_cur_path.Value() ); } if ( sb.GetRc() ) { dprintf( D_FULLDEBUG, "StatFile: errno = %d\n", sb.GetErrno() ); return ReadUserLog::LOG_STATUS_ERROR; } filesize_t size = sb.GetBuf()->st_size; ReadUserLog::FileStatus status; if ( 0 == size ) { is_empty = true; if ( m_status_size < 0 ) { m_status_size = 0; } } else { is_empty = false; } if ( (m_status_size < 0) || (size > m_status_size) ) { status = ReadUserLog::LOG_STATUS_GROWN; } else if ( size == m_status_size ) { status = ReadUserLog::LOG_STATUS_NOCHANGE; } else { status = ReadUserLog::LOG_STATUS_SHRUNK; } m_status_size = size; Update(); return status; }
DoS Exec Code
0
ReadUserLogState::CheckFileStatus( int fd, bool &is_empty ) { StatWrapper sb; if ( fd >= 0 ) { (void) sb.Stat( fd ); } if ( m_cur_path.Length() && !sb.IsBufValid() ) { (void) sb.Stat( m_cur_path.Value() ); } if ( sb.GetRc() ) { dprintf( D_FULLDEBUG, "StatFile: errno = %d\n", sb.GetErrno() ); return ReadUserLog::LOG_STATUS_ERROR; } filesize_t size = sb.GetBuf()->st_size; ReadUserLog::FileStatus status; if ( 0 == size ) { is_empty = true; if ( m_status_size < 0 ) { m_status_size = 0; } } else { is_empty = false; } if ( (m_status_size < 0) || (size > m_status_size) ) { status = ReadUserLog::LOG_STATUS_GROWN; } else if ( size == m_status_size ) { status = ReadUserLog::LOG_STATUS_NOCHANGE; } else { status = ReadUserLog::LOG_STATUS_SHRUNK; } m_status_size = size; Update(); return status; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,320
ReadUserLogState::EventNum( const ReadUserLog::FileState &state ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { return -1; } return (filesize_t) istate->m_event_num.asint; }
DoS Exec Code
0
ReadUserLogState::EventNum( const ReadUserLog::FileState &state ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { return -1; } return (filesize_t) istate->m_event_num.asint; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,321
ReadUserLogState::GeneratePath( int rotation, MyString &path, bool initializing ) const { if ( !initializing && !m_initialized ) { return false; } if ( ( rotation < 0 ) || ( rotation > m_max_rotations ) ) { return false; } if ( !m_base_path.Length() ) { path = ""; return false; } path = m_base_path; if ( rotation ) { if ( m_max_rotations > 1 ) { path.sprintf_cat( ".%d", rotation ); } else { path += ".old"; } } return true; }
DoS Exec Code
0
ReadUserLogState::GeneratePath( int rotation, MyString &path, bool initializing ) const { if ( !initializing && !m_initialized ) { return false; } if ( ( rotation < 0 ) || ( rotation > m_max_rotations ) ) { return false; } if ( !m_base_path.Length() ) { path = ""; return false; } path = m_base_path; if ( rotation ) { if ( m_max_rotations > 1 ) { path.sprintf_cat( ".%d", rotation ); } else { path += ".old"; } } return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,322
ReadUserLogState::GetStateString( MyString &str, const char *label ) const { str = ""; if ( NULL != label ) { str.sprintf( "%s:\n", label ); } str.sprintf_cat ( " BasePath = %s\n" " CurPath = %s\n" " UniqId = %s, seq = %d\n" " rotation = %d; max = %d; offset = %ld; event = %ld; type = %d\n" " inode = %u; ctime = %d; size = %ld\n", m_base_path.Value(), m_cur_path.Value(), m_uniq_id.Value(), m_sequence, m_cur_rot, m_max_rotations, (long) m_offset, (long) m_event_num, m_log_type, (unsigned)m_stat_buf.st_ino, (int)m_stat_buf.st_ctime, (long)m_stat_buf.st_size ); }
DoS Exec Code
0
ReadUserLogState::GetStateString( MyString &str, const char *label ) const { str = ""; if ( NULL != label ) { str.sprintf( "%s:\n", label ); } str.sprintf_cat ( " BasePath = %s\n" " CurPath = %s\n" " UniqId = %s, seq = %d\n" " rotation = %d; max = %d; offset = %ld; event = %ld; type = %d\n" " inode = %u; ctime = %d; size = %ld\n", m_base_path.Value(), m_cur_path.Value(), m_uniq_id.Value(), m_sequence, m_cur_rot, m_max_rotations, (long) m_offset, (long) m_event_num, m_log_type, (unsigned)m_stat_buf.st_ino, (int)m_stat_buf.st_ctime, (long)m_stat_buf.st_size ); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,323
ReadUserLogState::GetStateString( const ReadUserLog::FileState &state, MyString &str, const char *label ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { if ( label ) { str.sprintf( "%s: no state", label ); } else { str = "no state\n"; } return; } str = ""; if ( NULL != label ) { str.sprintf( "%s:\n", label ); } str.sprintf_cat ( " signature = '%s'; version = %d; update = %ld\n" " base path = '%s'\n" " cur path = '%s'\n" " UniqId = %s, seq = %d\n" " rotation = %d; max = %d; offset = "FILESIZE_T_FORMAT";" " event num = "FILESIZE_T_FORMAT"; type = %d\n" " inode = %u; ctime = %ld; size = "FILESIZE_T_FORMAT"\n", istate->m_signature, istate->m_version, istate->m_update_time, istate->m_base_path, CurPath(state), istate->m_uniq_id, istate->m_sequence, istate->m_rotation, istate->m_max_rotations, istate->m_offset.asint, istate->m_event_num.asint, istate->m_log_type, (unsigned)istate->m_inode, istate->m_ctime, istate->m_size.asint ); }
DoS Exec Code
0
ReadUserLogState::GetStateString( const ReadUserLog::FileState &state, MyString &str, const char *label ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { if ( label ) { str.sprintf( "%s: no state", label ); } else { str = "no state\n"; } return; } str = ""; if ( NULL != label ) { str.sprintf( "%s:\n", label ); } str.sprintf_cat ( " signature = '%s'; version = %d; update = %ld\n" " base path = '%s'\n" " cur path = '%s'\n" " UniqId = %s, seq = %d\n" " rotation = %d; max = %d; offset = "FILESIZE_T_FORMAT";" " event num = "FILESIZE_T_FORMAT"; type = %d\n" " inode = %u; ctime = %ld; size = "FILESIZE_T_FORMAT"\n", istate->m_signature, istate->m_version, istate->m_update_time, istate->m_base_path, CurPath(state), istate->m_uniq_id, istate->m_sequence, istate->m_rotation, istate->m_max_rotations, istate->m_offset.asint, istate->m_event_num.asint, istate->m_log_type, (unsigned)istate->m_inode, istate->m_ctime, istate->m_size.asint ); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,324
ReadUserLogFileState::InitState( ReadUserLog::FileState &state ) { state.buf = (void *) new ReadUserLogState::FileStatePub; state.size = sizeof( ReadUserLogState::FileStatePub ); ReadUserLogFileState::FileState *istate; if ( !convertState(state, istate) ) { return false; } memset( istate, 0, sizeof(ReadUserLogState::FileStatePub) ); istate->m_log_type = LOG_TYPE_UNKNOWN; strncpy( istate->m_signature, FileStateSignature, sizeof(istate->m_signature) ); istate->m_signature[sizeof(istate->m_signature) - 1] = '\0'; istate->m_version = FILESTATE_VERSION; return true; }
DoS Exec Code
0
ReadUserLogFileState::InitState( ReadUserLog::FileState &state ) { state.buf = (void *) new ReadUserLogState::FileStatePub; state.size = sizeof( ReadUserLogState::FileStatePub ); ReadUserLogFileState::FileState *istate; if ( !convertState(state, istate) ) { return false; } memset( istate, 0, sizeof(ReadUserLogState::FileStatePub) ); istate->m_log_type = LOG_TYPE_UNKNOWN; strncpy( istate->m_signature, FileStateSignature, sizeof(istate->m_signature) ); istate->m_signature[sizeof(istate->m_signature) - 1] = '\0'; istate->m_version = FILESTATE_VERSION; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,325
ReadUserLogState::LogPosition( const ReadUserLog::FileState &state ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { return -1; } return (filesize_t) istate->m_log_position.asint; }
DoS Exec Code
0
ReadUserLogState::LogPosition( const ReadUserLog::FileState &state ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { return -1; } return (filesize_t) istate->m_log_position.asint; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,326
ReadUserLogState::LogRecordNo( const ReadUserLog::FileState &state ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { return -1; } return (filesize_t) istate->m_log_record.asint; }
DoS Exec Code
0
ReadUserLogState::LogRecordNo( const ReadUserLog::FileState &state ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { return -1; } return (filesize_t) istate->m_log_record.asint; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,327
ReadUserLogState::Offset( const ReadUserLog::FileState &state ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { return -1; } return (filesize_t) istate->m_offset.asint; }
DoS Exec Code
0
ReadUserLogState::Offset( const ReadUserLog::FileState &state ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { return -1; } return (filesize_t) istate->m_offset.asint; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,328
ReadUserLogFileState::ReadUserLogFileState( void ) { m_rw_state = NULL; m_ro_state = NULL; }
DoS Exec Code
0
ReadUserLogFileState::ReadUserLogFileState( void ) { m_rw_state = NULL; m_ro_state = NULL; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,329
ReadUserLogFileState::ReadUserLogFileState( ReadUserLog::FileState &state ) { convertState( state, m_rw_state ); m_ro_state = m_rw_state; }
DoS Exec Code
0
ReadUserLogFileState::ReadUserLogFileState( ReadUserLog::FileState &state ) { convertState( state, m_rw_state ); m_ro_state = m_rw_state; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,330
ReadUserLogFileState::ReadUserLogFileState( const ReadUserLog::FileState &state ) { m_rw_state = NULL; convertState( state, m_ro_state ); }
DoS Exec Code
0
ReadUserLogFileState::ReadUserLogFileState( const ReadUserLog::FileState &state ) { m_rw_state = NULL; convertState( state, m_ro_state ); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,331
ReadUserLogState::ReadUserLogState( const char *path, int max_rotations, int recent_thresh ) : ReadUserLogFileState( ) { Reset( RESET_INIT ); m_max_rotations = max_rotations; m_recent_thresh = recent_thresh; if ( path ) { m_base_path = path; } m_initialized = true; m_update_time = 0; }
DoS Exec Code
0
ReadUserLogState::ReadUserLogState( const char *path, int max_rotations, int recent_thresh ) : ReadUserLogFileState( ) { Reset( RESET_INIT ); m_max_rotations = max_rotations; m_recent_thresh = recent_thresh; if ( path ) { m_base_path = path; } m_initialized = true; m_update_time = 0; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,332
ReadUserLogState::ReadUserLogState( const ReadUserLog::FileState &state, int recent_thresh ) : ReadUserLogFileState( state ) { Reset( RESET_INIT ); m_recent_thresh = recent_thresh; if ( !SetState( state ) ) { dprintf( D_FULLDEBUG, "::ReadUserLogState: failed to set state from buffer\n" ); m_init_error = true; } }
DoS Exec Code
0
ReadUserLogState::ReadUserLogState( const ReadUserLog::FileState &state, int recent_thresh ) : ReadUserLogFileState( state ) { Reset( RESET_INIT ); m_recent_thresh = recent_thresh; if ( !SetState( state ) ) { dprintf( D_FULLDEBUG, "::ReadUserLogState: failed to set state from buffer\n" ); m_init_error = true; } }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,333
ReadUserLogState::ReadUserLogState( void ) : ReadUserLogFileState( ) { m_update_time = 0; Reset( RESET_INIT ); }
DoS Exec Code
0
ReadUserLogState::ReadUserLogState( void ) : ReadUserLogFileState( ) { m_update_time = 0; Reset( RESET_INIT ); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,334
ReadUserLogStateAccess::ReadUserLogStateAccess( const ReadUserLog::FileState &state) { m_state = new ReadUserLogFileState(state); }
DoS Exec Code
0
ReadUserLogStateAccess::ReadUserLogStateAccess( const ReadUserLog::FileState &state) { m_state = new ReadUserLogFileState(state); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,335
ReadUserLogState::Reset( ResetType type ) { if ( RESET_INIT == type ) { m_initialized = false; m_init_error = false; m_base_path = ""; m_max_rotations = 0; m_recent_thresh = 0; m_score_fact_ctime = 0; m_score_fact_inode = 0; m_score_fact_same_size = 0; m_score_fact_grown = 0; m_score_fact_shrunk = 0; } else if ( RESET_FULL == type ) { m_base_path = ""; } m_cur_path = ""; m_cur_rot = -1; m_uniq_id = ""; m_sequence = 0; memset( &m_stat_buf, 0, sizeof(m_stat_buf) ); m_status_size = -1; m_stat_valid = false; m_stat_time = 0; m_log_position = 0; m_log_record = 0; m_offset = 0; m_event_num = 0; m_log_type = LOG_TYPE_UNKNOWN; }
DoS Exec Code
0
ReadUserLogState::Reset( ResetType type ) { if ( RESET_INIT == type ) { m_initialized = false; m_init_error = false; m_base_path = ""; m_max_rotations = 0; m_recent_thresh = 0; m_score_fact_ctime = 0; m_score_fact_inode = 0; m_score_fact_same_size = 0; m_score_fact_grown = 0; m_score_fact_shrunk = 0; } else if ( RESET_FULL == type ) { m_base_path = ""; } m_cur_path = ""; m_cur_rot = -1; m_uniq_id = ""; m_sequence = 0; memset( &m_stat_buf, 0, sizeof(m_stat_buf) ); m_status_size = -1; m_stat_valid = false; m_stat_time = 0; m_log_position = 0; m_log_record = 0; m_offset = 0; m_event_num = 0; m_log_type = LOG_TYPE_UNKNOWN; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,336
ReadUserLogState::Rotation( int rotation, StatStructType &statbuf, bool initializing ) { if ( !initializing && !m_initialized ) { return -1; } if ( ( rotation < 0 ) || ( rotation > m_max_rotations ) ) { return -1; } if ( m_cur_rot == rotation ) { return 0; } m_uniq_id = ""; GeneratePath( rotation, m_cur_path, initializing ); m_cur_rot = rotation; m_log_type = LOG_TYPE_UNKNOWN; Update(); return StatFile( statbuf ); }
DoS Exec Code
0
ReadUserLogState::Rotation( int rotation, StatStructType &statbuf, bool initializing ) { if ( !initializing && !m_initialized ) { return -1; } if ( ( rotation < 0 ) || ( rotation > m_max_rotations ) ) { return -1; } if ( m_cur_rot == rotation ) { return 0; } m_uniq_id = ""; GeneratePath( rotation, m_cur_path, initializing ); m_cur_rot = rotation; m_log_type = LOG_TYPE_UNKNOWN; Update(); return StatFile( statbuf ); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,337
ReadUserLogState::Rotation( const ReadUserLog::FileState &state ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { return -1; } return istate->m_rotation; }
DoS Exec Code
0
ReadUserLogState::Rotation( const ReadUserLog::FileState &state ) const { const ReadUserLogFileState::FileState *istate; if ( ( !convertState(state, istate) ) || ( !istate->m_version ) ) { return -1; } return istate->m_rotation; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,338
ReadUserLogState::ScoreFile( int rot ) const { if ( rot > m_max_rotations ) { return -1; } else if ( rot < 0 ) { rot = m_cur_rot; } MyString path; if ( !GeneratePath( rot, path ) ) { return -1; } return ScoreFile( path.Value(), rot ); }
DoS Exec Code
0
ReadUserLogState::ScoreFile( int rot ) const { if ( rot > m_max_rotations ) { return -1; } else if ( rot < 0 ) { rot = m_cur_rot; } MyString path; if ( !GeneratePath( rot, path ) ) { return -1; } return ScoreFile( path.Value(), rot ); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,339
ReadUserLogState::ScoreFile( const char *path, int rot ) const { StatStructType statbuf; if ( NULL == path ) { path = CurPath( ); } if ( rot < 0 ) { rot = m_cur_rot; } if ( StatFile( path, statbuf ) ) { dprintf( D_FULLDEBUG, "ScoreFile: stat Error\n" ); return -1; } return ScoreFile( statbuf, rot ); }
DoS Exec Code
0
ReadUserLogState::ScoreFile( const char *path, int rot ) const { StatStructType statbuf; if ( NULL == path ) { path = CurPath( ); } if ( rot < 0 ) { rot = m_cur_rot; } if ( StatFile( path, statbuf ) ) { dprintf( D_FULLDEBUG, "ScoreFile: stat Error\n" ); return -1; } return ScoreFile( statbuf, rot ); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,340
ReadUserLogState::ScoreFile( const StatStructType &statbuf, int rot ) const { int score = 0; if ( rot < 0 ) { rot = m_cur_rot; } bool is_recent = ( time(NULL) < (m_update_time + m_recent_thresh) ); bool is_current = ( rot == m_cur_rot ); bool same_size = ( statbuf.st_size == m_stat_buf.st_size ); bool has_grown = ( statbuf.st_size > m_stat_buf.st_size ); MyString MatchList = ""; // For debugging if ( m_stat_buf.st_ino == statbuf.st_ino ) { score += m_score_fact_inode; if ( DebugFlags & D_FULLDEBUG ) MatchList += "inode "; } if ( m_stat_buf.st_ctime == statbuf.st_ctime ) { score += m_score_fact_ctime; if ( DebugFlags & D_FULLDEBUG ) MatchList += "ctime "; } if ( same_size ) { score += m_score_fact_same_size; if ( DebugFlags & D_FULLDEBUG ) MatchList += "same-size "; } else if ( is_recent && is_current && has_grown ) { score += m_score_fact_grown; if ( DebugFlags & D_FULLDEBUG ) MatchList += "grown "; } if ( m_stat_buf.st_size > statbuf.st_size ) { score += m_score_fact_shrunk; if ( DebugFlags & D_FULLDEBUG ) MatchList += "shrunk "; } if ( DebugFlags & D_FULLDEBUG ) { dprintf( D_FULLDEBUG, "ScoreFile: match list: %s\n", MatchList.Value() ); } if ( score < 0 ) { score = 0; } return score; }
DoS Exec Code
0
ReadUserLogState::ScoreFile( const StatStructType &statbuf, int rot ) const { int score = 0; if ( rot < 0 ) { rot = m_cur_rot; } bool is_recent = ( time(NULL) < (m_update_time + m_recent_thresh) ); bool is_current = ( rot == m_cur_rot ); bool same_size = ( statbuf.st_size == m_stat_buf.st_size ); bool has_grown = ( statbuf.st_size > m_stat_buf.st_size ); MyString MatchList = ""; // For debugging if ( m_stat_buf.st_ino == statbuf.st_ino ) { score += m_score_fact_inode; if ( DebugFlags & D_FULLDEBUG ) MatchList += "inode "; } if ( m_stat_buf.st_ctime == statbuf.st_ctime ) { score += m_score_fact_ctime; if ( DebugFlags & D_FULLDEBUG ) MatchList += "ctime "; } if ( same_size ) { score += m_score_fact_same_size; if ( DebugFlags & D_FULLDEBUG ) MatchList += "same-size "; } else if ( is_recent && is_current && has_grown ) { score += m_score_fact_grown; if ( DebugFlags & D_FULLDEBUG ) MatchList += "grown "; } if ( m_stat_buf.st_size > statbuf.st_size ) { score += m_score_fact_shrunk; if ( DebugFlags & D_FULLDEBUG ) MatchList += "shrunk "; } if ( DebugFlags & D_FULLDEBUG ) { dprintf( D_FULLDEBUG, "ScoreFile: match list: %s\n", MatchList.Value() ); } if ( score < 0 ) { score = 0; } return score; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,341
ReadUserLogState::SetScoreFactor( enum ScoreFactors which, int factor ) { switch ( which ) { case SCORE_CTIME: m_score_fact_ctime = factor; break; case SCORE_INODE: m_score_fact_inode = factor; break; case SCORE_SAME_SIZE: m_score_fact_same_size = factor; break; case SCORE_GROWN: m_score_fact_grown = factor; break; case SCORE_SHRUNK: m_score_fact_shrunk = factor; break; default: break; } Update(); }
DoS Exec Code
0
ReadUserLogState::SetScoreFactor( enum ScoreFactors which, int factor ) { switch ( which ) { case SCORE_CTIME: m_score_fact_ctime = factor; break; case SCORE_INODE: m_score_fact_inode = factor; break; case SCORE_SAME_SIZE: m_score_fact_same_size = factor; break; case SCORE_GROWN: m_score_fact_grown = factor; break; case SCORE_SHRUNK: m_score_fact_shrunk = factor; break; default: break; } Update(); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,342
ReadUserLogState::StatFile( void ) { int status = StatFile( CurPath(), m_stat_buf ); if ( 0 == status ) { m_stat_time = time( NULL ); m_stat_valid = true; Update(); } return status; }
DoS Exec Code
0
ReadUserLogState::StatFile( void ) { int status = StatFile( CurPath(), m_stat_buf ); if ( 0 == status ) { m_stat_time = time( NULL ); m_stat_valid = true; Update(); } return status; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,343
ReadUserLogState::StatFile( StatStructType &statbuf ) const { return StatFile( CurPath(), statbuf ); }
DoS Exec Code
0
ReadUserLogState::StatFile( StatStructType &statbuf ) const { return StatFile( CurPath(), statbuf ); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,344
ReadUserLogState::StatFile( const char *path, StatStructType &statbuf ) const { StatWrapper statwrap; if ( statwrap.Stat( path, StatWrapper::STATOP_STAT ) ) { return statwrap.GetRc( ); } statwrap.GetBuf( statbuf ); return 0; }
DoS Exec Code
0
ReadUserLogState::StatFile( const char *path, StatStructType &statbuf ) const { StatWrapper statwrap; if ( statwrap.Stat( path, StatWrapper::STATOP_STAT ) ) { return statwrap.GetRc( ); } statwrap.GetBuf( statbuf ); return 0; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,345
ReadUserLogState::StatFile( int fd ) { StatWrapper statwrap; if ( statwrap.Stat( fd ) ) { dprintf( D_FULLDEBUG, "StatFile: errno = %d\n", statwrap.GetErrno() ); return statwrap.GetRc( ); } statwrap.GetBuf( m_stat_buf ); m_stat_time = time( NULL ); m_stat_valid = true; Update(); return 0; }
DoS Exec Code
0
ReadUserLogState::StatFile( int fd ) { StatWrapper statwrap; if ( statwrap.Stat( fd ) ) { dprintf( D_FULLDEBUG, "StatFile: errno = %d\n", statwrap.GetErrno() ); return statwrap.GetRc( ); } statwrap.GetBuf( m_stat_buf ); m_stat_time = time( NULL ); m_stat_valid = true; Update(); return 0; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,346
ReadUserLogFileState::UninitState( ReadUserLog::FileState &state ) { ReadUserLogState::FileStatePub *istate = (ReadUserLogState::FileStatePub *) state.buf; delete istate; state.buf = NULL; state.size = 0; return true; }
DoS Exec Code
0
ReadUserLogFileState::UninitState( ReadUserLog::FileState &state ) { ReadUserLogState::FileStatePub *istate = (ReadUserLogState::FileStatePub *) state.buf; delete istate; state.buf = NULL; state.size = 0; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,347
ReadUserLogFileState::convertState( const ReadUserLog::FileState &state, const ReadUserLogFileState::FileStatePub *&pub ) { pub = (const ReadUserLogFileState::FileStatePub *) state.buf; return true; }
DoS Exec Code
0
ReadUserLogFileState::convertState( const ReadUserLog::FileState &state, const ReadUserLogFileState::FileStatePub *&pub ) { pub = (const ReadUserLogFileState::FileStatePub *) state.buf; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,348
ReadUserLogFileState::convertState( ReadUserLog::FileState &state, ReadUserLogFileState::FileState *&internal ) { ReadUserLogFileState::FileStatePub *pub; convertState(state, pub); internal = &(pub->internal); return true; }
DoS Exec Code
0
ReadUserLogFileState::convertState( ReadUserLog::FileState &state, ReadUserLogFileState::FileState *&internal ) { ReadUserLogFileState::FileStatePub *pub; convertState(state, pub); internal = &(pub->internal); return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,349
ReadUserLogStateAccess::getEventNumber( unsigned long &event_no ) const { int64_t my_event_no; if ( !m_state->getLogRecordNo(my_event_no) ) { return false; } if ( (unsigned long)my_event_no > ULONG_MAX ) { return false; } event_no = (unsigned long) my_event_no; return true; }
DoS Exec Code
0
ReadUserLogStateAccess::getEventNumber( unsigned long &event_no ) const { int64_t my_event_no; if ( !m_state->getLogRecordNo(my_event_no) ) { return false; } if ( (unsigned long)my_event_no > ULONG_MAX ) { return false; } event_no = (unsigned long) my_event_no; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,350
ReadUserLogFileState::getFileEventNum( int64_t &num ) const { if ( NULL == m_ro_state ) { return false; } num = m_ro_state->internal.m_event_num.asint; return true; }
DoS Exec Code
0
ReadUserLogFileState::getFileEventNum( int64_t &num ) const { if ( NULL == m_ro_state ) { return false; } num = m_ro_state->internal.m_event_num.asint; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,351
ReadUserLogStateAccess::getFileEventNum( unsigned long &num ) const { int64_t my_num; if ( !m_state->getFileEventNum(my_num) ) { return false; } if ( (unsigned long)my_num > ULONG_MAX ) { return false; } num = (unsigned long) my_num; return true; }
DoS Exec Code
0
ReadUserLogStateAccess::getFileEventNum( unsigned long &num ) const { int64_t my_num; if ( !m_state->getFileEventNum(my_num) ) { return false; } if ( (unsigned long)my_num > ULONG_MAX ) { return false; } num = (unsigned long) my_num; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,352
ReadUserLogStateAccess::getFileEventNumDiff( const ReadUserLogStateAccess &other, long &diff ) const { const ReadUserLogFileState *ostate; if ( !other.getState( ostate ) ) { return false; } int64_t my_num, other_num; if ( !m_state->getFileEventNum(my_num) || ! ostate->getFileEventNum(other_num) ) { return false; } int64_t idiff = my_num - other_num; diff = (long) idiff; return true; }
DoS Exec Code
0
ReadUserLogStateAccess::getFileEventNumDiff( const ReadUserLogStateAccess &other, long &diff ) const { const ReadUserLogFileState *ostate; if ( !other.getState( ostate ) ) { return false; } int64_t my_num, other_num; if ( !m_state->getFileEventNum(my_num) || ! ostate->getFileEventNum(other_num) ) { return false; } int64_t idiff = my_num - other_num; diff = (long) idiff; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,353
ReadUserLogFileState::getFileOffset( int64_t &pos ) const { if ( NULL == m_ro_state ) { return false; } pos = m_ro_state->internal.m_offset.asint; return true; }
DoS Exec Code
0
ReadUserLogFileState::getFileOffset( int64_t &pos ) const { if ( NULL == m_ro_state ) { return false; } pos = m_ro_state->internal.m_offset.asint; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,354
ReadUserLogStateAccess::getFileOffset( unsigned long &pos ) const { int64_t my_pos; if ( !m_state->getFileOffset(my_pos) ) { return false; } if ( my_pos > LONG_MAX ) { return false; } pos = (unsigned long) my_pos; return true; }
DoS Exec Code
0
ReadUserLogStateAccess::getFileOffset( unsigned long &pos ) const { int64_t my_pos; if ( !m_state->getFileOffset(my_pos) ) { return false; } if ( my_pos > LONG_MAX ) { return false; } pos = (unsigned long) my_pos; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,355
ReadUserLogStateAccess::getFileOffsetDiff( const ReadUserLogStateAccess &other, long &diff ) const { const ReadUserLogFileState *ostate; if ( !other.getState( ostate ) ) { return false; } int64_t my_pos, other_pos; if ( !m_state->getFileOffset(my_pos) || ! ostate->getFileOffset(other_pos) ) { return false; } int64_t idiff = my_pos - other_pos; diff = (long) idiff; return true; }
DoS Exec Code
0
ReadUserLogStateAccess::getFileOffsetDiff( const ReadUserLogStateAccess &other, long &diff ) const { const ReadUserLogFileState *ostate; if ( !other.getState( ostate ) ) { return false; } int64_t my_pos, other_pos; if ( !m_state->getFileOffset(my_pos) || ! ostate->getFileOffset(other_pos) ) { return false; } int64_t idiff = my_pos - other_pos; diff = (long) idiff; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,356
ReadUserLogFileState::getLogPosition( int64_t &pos ) const { if ( NULL == m_ro_state ) { return false; } pos = m_ro_state->internal.m_log_position.asint; return true; }
DoS Exec Code
0
ReadUserLogFileState::getLogPosition( int64_t &pos ) const { if ( NULL == m_ro_state ) { return false; } pos = m_ro_state->internal.m_log_position.asint; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,357
ReadUserLogStateAccess::getLogPositionDiff( const ReadUserLogStateAccess &other, long &diff ) const { const ReadUserLogFileState *ostate; if ( !other.getState( ostate ) ) { return false; } int64_t my_pos, other_pos; if ( !m_state->getLogPosition(my_pos) || ! ostate->getLogPosition(other_pos) ) { return false; } int64_t idiff = my_pos - other_pos; diff = (long) idiff; return true; }
DoS Exec Code
0
ReadUserLogStateAccess::getLogPositionDiff( const ReadUserLogStateAccess &other, long &diff ) const { const ReadUserLogFileState *ostate; if ( !other.getState( ostate ) ) { return false; } int64_t my_pos, other_pos; if ( !m_state->getLogPosition(my_pos) || ! ostate->getLogPosition(other_pos) ) { return false; } int64_t idiff = my_pos - other_pos; diff = (long) idiff; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,358
ReadUserLogFileState::getLogRecordNo( int64_t &recno ) const { if ( NULL == m_ro_state ) { return false; } recno = m_ro_state->internal.m_log_record.asint; return true; }
DoS Exec Code
0
ReadUserLogFileState::getLogRecordNo( int64_t &recno ) const { if ( NULL == m_ro_state ) { return false; } recno = m_ro_state->internal.m_log_record.asint; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,359
ReadUserLogFileState::getSequenceNo( int &seqno ) const { if ( NULL == m_ro_state ) { return false; } seqno = m_ro_state->internal.m_sequence; return true; }
DoS Exec Code
0
ReadUserLogFileState::getSequenceNo( int &seqno ) const { if ( NULL == m_ro_state ) { return false; } seqno = m_ro_state->internal.m_sequence; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,360
ReadUserLogStateAccess::getSequenceNumber( int &seqno ) const { return m_state->getSequenceNo( seqno ); }
DoS Exec Code
0
ReadUserLogStateAccess::getSequenceNumber( int &seqno ) const { return m_state->getSequenceNo( seqno ); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,361
ReadUserLogStateAccess::getState( const ReadUserLogFileState *&state ) const { state = m_state; return true; }
DoS Exec Code
0
ReadUserLogStateAccess::getState( const ReadUserLogFileState *&state ) const { state = m_state; return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,362
ReadUserLogFileState::isInitialized( void ) const { if ( NULL == m_ro_state ) { return false; } if ( strcmp( m_ro_state->internal.m_signature, FileStateSignature ) ) { return false; } return true; }
DoS Exec Code
0
ReadUserLogFileState::isInitialized( void ) const { if ( NULL == m_ro_state ) { return false; } if ( strcmp( m_ro_state->internal.m_signature, FileStateSignature ) ) { return false; } return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,363
ReadUserLogStateAccess::isInitialized( void ) const { return m_state->isInitialized( ); }
DoS Exec Code
0
ReadUserLogStateAccess::isInitialized( void ) const { return m_state->isInitialized( ); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,364
ReadUserLogFileState::isValid( void ) const { if ( !isInitialized() ) { return false; } if ( 0 == strlen(m_ro_state->internal.m_base_path) ) { return false; } return true; }
DoS Exec Code
0
ReadUserLogFileState::isValid( void ) const { if ( !isInitialized() ) { return false; } if ( 0 == strlen(m_ro_state->internal.m_base_path) ) { return false; } return true; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,365
ReadUserLogStateAccess::isValid( void ) const { return m_state->isValid( ); }
DoS Exec Code
0
ReadUserLogStateAccess::isValid( void ) const { return m_state->isValid( ); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,366
ReadUserLogFileState::~ReadUserLogFileState( void ) { }
DoS Exec Code
0
ReadUserLogFileState::~ReadUserLogFileState( void ) { }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,367
ReadUserLogState::~ReadUserLogState( void ) { Reset( RESET_FULL ); }
DoS Exec Code
0
ReadUserLogState::~ReadUserLogState( void ) { Reset( RESET_FULL ); }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,368
ReadUserLogStateAccess::~ReadUserLogStateAccess(void) { delete m_state; }
DoS Exec Code
0
ReadUserLogStateAccess::~ReadUserLogStateAccess(void) { delete m_state; }
@@ -752,7 +752,7 @@ ReadUserLogState::SetState( const ReadUserLog::FileState &state ) MyString str; GetStateString( str, "Restored reader state" ); - dprintf( D_FULLDEBUG, str.Value() ); + dprintf( D_FULLDEBUG, "%s", str.Value() ); return true; }
CWE-134
null
null
13,369
static bool blit_is_unsafe(struct CirrusVGAState *s, bool dst_only) { /* should be the case, see cirrus_bitblt_start */ assert(s->cirrus_blt_width > 0); assert(s->cirrus_blt_height > 0); if (s->cirrus_blt_width > CIRRUS_BLTBUFSIZE) { return true; } if (blit_region_is_unsafe(s, s->cirrus_blt_dstpitch, s->cirrus_blt_dstaddr & s->cirrus_addr_mask)) { return true; } if (dst_only) { return false; } if (blit_region_is_unsafe(s, s->cirrus_blt_srcpitch, s->cirrus_blt_srcaddr & s->cirrus_addr_mask)) { return true; } return false; }
DoS
0
static bool blit_is_unsafe(struct CirrusVGAState *s, bool dst_only) { /* should be the case, see cirrus_bitblt_start */ assert(s->cirrus_blt_width > 0); assert(s->cirrus_blt_height > 0); if (s->cirrus_blt_width > CIRRUS_BLTBUFSIZE) { return true; } if (blit_region_is_unsafe(s, s->cirrus_blt_dstpitch, s->cirrus_blt_dstaddr & s->cirrus_addr_mask)) { return true; } if (dst_only) { return false; } if (blit_region_is_unsafe(s, s->cirrus_blt_srcpitch, s->cirrus_blt_srcaddr & s->cirrus_addr_mask)) { return true; } return false; }
@@ -661,9 +661,14 @@ static void cirrus_invalidate_region(CirrusVGAState * s, int off_begin, int off_cur; int off_cur_end; + if (off_pitch < 0) { + off_begin -= bytesperline - 1; + } + for (y = 0; y < lines; y++) { off_cur = off_begin; off_cur_end = (off_cur + bytesperline) & s->cirrus_addr_mask; + assert(off_cur_end >= off_cur); memory_region_set_dirty(&s->vga.vram, off_cur, off_cur_end - off_cur); off_begin += off_pitch; }
CWE-125
null
null
13,370
static int cirrus_bitblt_solidfill(CirrusVGAState *s, int blt_rop) { cirrus_fill_t rop_func; if (blit_is_unsafe(s, true)) { return 0; } rop_func = cirrus_fill[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1]; rop_func(s, s->vga.vram_ptr + (s->cirrus_blt_dstaddr & s->cirrus_addr_mask), s->cirrus_blt_dstpitch, s->cirrus_blt_width, s->cirrus_blt_height); cirrus_invalidate_region(s, s->cirrus_blt_dstaddr, s->cirrus_blt_dstpitch, s->cirrus_blt_width, s->cirrus_blt_height); cirrus_bitblt_reset(s); return 1; }
DoS
0
static int cirrus_bitblt_solidfill(CirrusVGAState *s, int blt_rop) { cirrus_fill_t rop_func; if (blit_is_unsafe(s, true)) { return 0; } rop_func = cirrus_fill[rop_to_index[blt_rop]][s->cirrus_blt_pixelwidth - 1]; rop_func(s, s->vga.vram_ptr + (s->cirrus_blt_dstaddr & s->cirrus_addr_mask), s->cirrus_blt_dstpitch, s->cirrus_blt_width, s->cirrus_blt_height); cirrus_invalidate_region(s, s->cirrus_blt_dstaddr, s->cirrus_blt_dstpitch, s->cirrus_blt_width, s->cirrus_blt_height); cirrus_bitblt_reset(s); return 1; }
@@ -661,9 +661,14 @@ static void cirrus_invalidate_region(CirrusVGAState * s, int off_begin, int off_cur; int off_cur_end; + if (off_pitch < 0) { + off_begin -= bytesperline - 1; + } + for (y = 0; y < lines; y++) { off_cur = off_begin; off_cur_end = (off_cur + bytesperline) & s->cirrus_addr_mask; + assert(off_cur_end >= off_cur); memory_region_set_dirty(&s->vga.vram, off_cur, off_cur_end - off_cur); off_begin += off_pitch; }
CWE-125
null
null
13,371
static int cirrus_bitblt_videotovideo_copy(CirrusVGAState * s) { if (blit_is_unsafe(s, false)) return 0; return cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->vga.start_addr, s->cirrus_blt_srcaddr - s->vga.start_addr, s->cirrus_blt_width, s->cirrus_blt_height); }
DoS
0
static int cirrus_bitblt_videotovideo_copy(CirrusVGAState * s) { if (blit_is_unsafe(s, false)) return 0; return cirrus_do_copy(s, s->cirrus_blt_dstaddr - s->vga.start_addr, s->cirrus_blt_srcaddr - s->vga.start_addr, s->cirrus_blt_width, s->cirrus_blt_height); }
@@ -661,9 +661,14 @@ static void cirrus_invalidate_region(CirrusVGAState * s, int off_begin, int off_cur; int off_cur_end; + if (off_pitch < 0) { + off_begin -= bytesperline - 1; + } + for (y = 0; y < lines; y++) { off_cur = off_begin; off_cur_end = (off_cur + bytesperline) & s->cirrus_addr_mask; + assert(off_cur_end >= off_cur); memory_region_set_dirty(&s->vga.vram, off_cur, off_cur_end - off_cur); off_begin += off_pitch; }
CWE-125
null
null
13,372
static int cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h) { int sx = 0, sy = 0; int dx = 0, dy = 0; int depth = 0; int notify = 0; /* make sure to only copy if it's a plain copy ROP */ if (*s->cirrus_rop == cirrus_bitblt_rop_fwd_src || *s->cirrus_rop == cirrus_bitblt_rop_bkwd_src) { int width, height; depth = s->vga.get_bpp(&s->vga) / 8; if (!depth) { return 0; } s->vga.get_resolution(&s->vga, &width, &height); /* extra x, y */ sx = (src % ABS(s->cirrus_blt_srcpitch)) / depth; sy = (src / ABS(s->cirrus_blt_srcpitch)); dx = (dst % ABS(s->cirrus_blt_dstpitch)) / depth; dy = (dst / ABS(s->cirrus_blt_dstpitch)); /* normalize width */ w /= depth; /* if we're doing a backward copy, we have to adjust our x/y to be the upper left corner (instead of the lower right corner) */ if (s->cirrus_blt_dstpitch < 0) { sx -= (s->cirrus_blt_width / depth) - 1; dx -= (s->cirrus_blt_width / depth) - 1; sy -= s->cirrus_blt_height - 1; dy -= s->cirrus_blt_height - 1; } /* are we in the visible portion of memory? */ if (sx >= 0 && sy >= 0 && dx >= 0 && dy >= 0 && (sx + w) <= width && (sy + h) <= height && (dx + w) <= width && (dy + h) <= height) { notify = 1; } } /* we have to flush all pending changes so that the copy is generated at the appropriate moment in time */ if (notify) graphic_hw_update(s->vga.con); (*s->cirrus_rop) (s, s->vga.vram_ptr + (s->cirrus_blt_dstaddr & s->cirrus_addr_mask), s->vga.vram_ptr + (s->cirrus_blt_srcaddr & s->cirrus_addr_mask), s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch, s->cirrus_blt_width, s->cirrus_blt_height); if (notify) { qemu_console_copy(s->vga.con, sx, sy, dx, dy, s->cirrus_blt_width / depth, s->cirrus_blt_height); } /* we don't have to notify the display that this portion has changed since qemu_console_copy implies this */ cirrus_invalidate_region(s, s->cirrus_blt_dstaddr, s->cirrus_blt_dstpitch, s->cirrus_blt_width, s->cirrus_blt_height); return 1; }
DoS
0
static int cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h) { int sx = 0, sy = 0; int dx = 0, dy = 0; int depth = 0; int notify = 0; /* make sure to only copy if it's a plain copy ROP */ if (*s->cirrus_rop == cirrus_bitblt_rop_fwd_src || *s->cirrus_rop == cirrus_bitblt_rop_bkwd_src) { int width, height; depth = s->vga.get_bpp(&s->vga) / 8; if (!depth) { return 0; } s->vga.get_resolution(&s->vga, &width, &height); /* extra x, y */ sx = (src % ABS(s->cirrus_blt_srcpitch)) / depth; sy = (src / ABS(s->cirrus_blt_srcpitch)); dx = (dst % ABS(s->cirrus_blt_dstpitch)) / depth; dy = (dst / ABS(s->cirrus_blt_dstpitch)); /* normalize width */ w /= depth; /* if we're doing a backward copy, we have to adjust our x/y to be the upper left corner (instead of the lower right corner) */ if (s->cirrus_blt_dstpitch < 0) { sx -= (s->cirrus_blt_width / depth) - 1; dx -= (s->cirrus_blt_width / depth) - 1; sy -= s->cirrus_blt_height - 1; dy -= s->cirrus_blt_height - 1; } /* are we in the visible portion of memory? */ if (sx >= 0 && sy >= 0 && dx >= 0 && dy >= 0 && (sx + w) <= width && (sy + h) <= height && (dx + w) <= width && (dy + h) <= height) { notify = 1; } } /* we have to flush all pending changes so that the copy is generated at the appropriate moment in time */ if (notify) graphic_hw_update(s->vga.con); (*s->cirrus_rop) (s, s->vga.vram_ptr + (s->cirrus_blt_dstaddr & s->cirrus_addr_mask), s->vga.vram_ptr + (s->cirrus_blt_srcaddr & s->cirrus_addr_mask), s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch, s->cirrus_blt_width, s->cirrus_blt_height); if (notify) { qemu_console_copy(s->vga.con, sx, sy, dx, dy, s->cirrus_blt_width / depth, s->cirrus_blt_height); } /* we don't have to notify the display that this portion has changed since qemu_console_copy implies this */ cirrus_invalidate_region(s, s->cirrus_blt_dstaddr, s->cirrus_blt_dstpitch, s->cirrus_blt_width, s->cirrus_blt_height); return 1; }
@@ -661,9 +661,14 @@ static void cirrus_invalidate_region(CirrusVGAState * s, int off_begin, int off_cur; int off_cur_end; + if (off_pitch < 0) { + off_begin -= bytesperline - 1; + } + for (y = 0; y < lines; y++) { off_cur = off_begin; off_cur_end = (off_cur + bytesperline) & s->cirrus_addr_mask; + assert(off_cur_end >= off_cur); memory_region_set_dirty(&s->vga.vram, off_cur, off_cur_end - off_cur); off_begin += off_pitch; }
CWE-125
null
null
13,373
static void cirrus_init_common(CirrusVGAState *s, Object *owner, int device_id, int is_pci, MemoryRegion *system_memory, MemoryRegion *system_io) { int i; static int inited; if (!inited) { inited = 1; for(i = 0;i < 256; i++) rop_to_index[i] = CIRRUS_ROP_NOP_INDEX; /* nop rop */ rop_to_index[CIRRUS_ROP_0] = 0; rop_to_index[CIRRUS_ROP_SRC_AND_DST] = 1; rop_to_index[CIRRUS_ROP_NOP] = 2; rop_to_index[CIRRUS_ROP_SRC_AND_NOTDST] = 3; rop_to_index[CIRRUS_ROP_NOTDST] = 4; rop_to_index[CIRRUS_ROP_SRC] = 5; rop_to_index[CIRRUS_ROP_1] = 6; rop_to_index[CIRRUS_ROP_NOTSRC_AND_DST] = 7; rop_to_index[CIRRUS_ROP_SRC_XOR_DST] = 8; rop_to_index[CIRRUS_ROP_SRC_OR_DST] = 9; rop_to_index[CIRRUS_ROP_NOTSRC_OR_NOTDST] = 10; rop_to_index[CIRRUS_ROP_SRC_NOTXOR_DST] = 11; rop_to_index[CIRRUS_ROP_SRC_OR_NOTDST] = 12; rop_to_index[CIRRUS_ROP_NOTSRC] = 13; rop_to_index[CIRRUS_ROP_NOTSRC_OR_DST] = 14; rop_to_index[CIRRUS_ROP_NOTSRC_AND_NOTDST] = 15; s->device_id = device_id; if (is_pci) s->bustype = CIRRUS_BUSTYPE_PCI; else s->bustype = CIRRUS_BUSTYPE_ISA; } /* Register ioport 0x3b0 - 0x3df */ memory_region_init_io(&s->cirrus_vga_io, owner, &cirrus_vga_io_ops, s, "cirrus-io", 0x30); memory_region_set_flush_coalesced(&s->cirrus_vga_io); memory_region_add_subregion(system_io, 0x3b0, &s->cirrus_vga_io); memory_region_init(&s->low_mem_container, owner, "cirrus-lowmem-container", 0x20000); memory_region_init_io(&s->low_mem, owner, &cirrus_vga_mem_ops, s, "cirrus-low-memory", 0x20000); memory_region_add_subregion(&s->low_mem_container, 0, &s->low_mem); for (i = 0; i < 2; ++i) { static const char *names[] = { "vga.bank0", "vga.bank1" }; MemoryRegion *bank = &s->cirrus_bank[i]; memory_region_init_alias(bank, owner, names[i], &s->vga.vram, 0, 0x8000); memory_region_set_enabled(bank, false); memory_region_add_subregion_overlap(&s->low_mem_container, i * 0x8000, bank, 1); } memory_region_add_subregion_overlap(system_memory, 0x000a0000, &s->low_mem_container, 1); memory_region_set_coalescing(&s->low_mem); /* I/O handler for LFB */ memory_region_init_io(&s->cirrus_linear_io, owner, &cirrus_linear_io_ops, s, "cirrus-linear-io", s->vga.vram_size_mb * 1024 * 1024); memory_region_set_flush_coalesced(&s->cirrus_linear_io); /* I/O handler for LFB */ memory_region_init_io(&s->cirrus_linear_bitblt_io, owner, &cirrus_linear_bitblt_io_ops, s, "cirrus-bitblt-mmio", 0x400000); memory_region_set_flush_coalesced(&s->cirrus_linear_bitblt_io); /* I/O handler for memory-mapped I/O */ memory_region_init_io(&s->cirrus_mmio_io, owner, &cirrus_mmio_io_ops, s, "cirrus-mmio", CIRRUS_PNPMMIO_SIZE); memory_region_set_flush_coalesced(&s->cirrus_mmio_io); s->real_vram_size = (s->device_id == CIRRUS_ID_CLGD5446) ? 4096 * 1024 : 2048 * 1024; /* XXX: s->vga.vram_size must be a power of two */ s->cirrus_addr_mask = s->real_vram_size - 1; s->linear_mmio_mask = s->real_vram_size - 256; s->vga.get_bpp = cirrus_get_bpp; s->vga.get_offsets = cirrus_get_offsets; s->vga.get_resolution = cirrus_get_resolution; s->vga.cursor_invalidate = cirrus_cursor_invalidate; s->vga.cursor_draw_line = cirrus_cursor_draw_line; qemu_register_reset(cirrus_reset, s); }
DoS
0
static void cirrus_init_common(CirrusVGAState *s, Object *owner, int device_id, int is_pci, MemoryRegion *system_memory, MemoryRegion *system_io) { int i; static int inited; if (!inited) { inited = 1; for(i = 0;i < 256; i++) rop_to_index[i] = CIRRUS_ROP_NOP_INDEX; /* nop rop */ rop_to_index[CIRRUS_ROP_0] = 0; rop_to_index[CIRRUS_ROP_SRC_AND_DST] = 1; rop_to_index[CIRRUS_ROP_NOP] = 2; rop_to_index[CIRRUS_ROP_SRC_AND_NOTDST] = 3; rop_to_index[CIRRUS_ROP_NOTDST] = 4; rop_to_index[CIRRUS_ROP_SRC] = 5; rop_to_index[CIRRUS_ROP_1] = 6; rop_to_index[CIRRUS_ROP_NOTSRC_AND_DST] = 7; rop_to_index[CIRRUS_ROP_SRC_XOR_DST] = 8; rop_to_index[CIRRUS_ROP_SRC_OR_DST] = 9; rop_to_index[CIRRUS_ROP_NOTSRC_OR_NOTDST] = 10; rop_to_index[CIRRUS_ROP_SRC_NOTXOR_DST] = 11; rop_to_index[CIRRUS_ROP_SRC_OR_NOTDST] = 12; rop_to_index[CIRRUS_ROP_NOTSRC] = 13; rop_to_index[CIRRUS_ROP_NOTSRC_OR_DST] = 14; rop_to_index[CIRRUS_ROP_NOTSRC_AND_NOTDST] = 15; s->device_id = device_id; if (is_pci) s->bustype = CIRRUS_BUSTYPE_PCI; else s->bustype = CIRRUS_BUSTYPE_ISA; } /* Register ioport 0x3b0 - 0x3df */ memory_region_init_io(&s->cirrus_vga_io, owner, &cirrus_vga_io_ops, s, "cirrus-io", 0x30); memory_region_set_flush_coalesced(&s->cirrus_vga_io); memory_region_add_subregion(system_io, 0x3b0, &s->cirrus_vga_io); memory_region_init(&s->low_mem_container, owner, "cirrus-lowmem-container", 0x20000); memory_region_init_io(&s->low_mem, owner, &cirrus_vga_mem_ops, s, "cirrus-low-memory", 0x20000); memory_region_add_subregion(&s->low_mem_container, 0, &s->low_mem); for (i = 0; i < 2; ++i) { static const char *names[] = { "vga.bank0", "vga.bank1" }; MemoryRegion *bank = &s->cirrus_bank[i]; memory_region_init_alias(bank, owner, names[i], &s->vga.vram, 0, 0x8000); memory_region_set_enabled(bank, false); memory_region_add_subregion_overlap(&s->low_mem_container, i * 0x8000, bank, 1); } memory_region_add_subregion_overlap(system_memory, 0x000a0000, &s->low_mem_container, 1); memory_region_set_coalescing(&s->low_mem); /* I/O handler for LFB */ memory_region_init_io(&s->cirrus_linear_io, owner, &cirrus_linear_io_ops, s, "cirrus-linear-io", s->vga.vram_size_mb * 1024 * 1024); memory_region_set_flush_coalesced(&s->cirrus_linear_io); /* I/O handler for LFB */ memory_region_init_io(&s->cirrus_linear_bitblt_io, owner, &cirrus_linear_bitblt_io_ops, s, "cirrus-bitblt-mmio", 0x400000); memory_region_set_flush_coalesced(&s->cirrus_linear_bitblt_io); /* I/O handler for memory-mapped I/O */ memory_region_init_io(&s->cirrus_mmio_io, owner, &cirrus_mmio_io_ops, s, "cirrus-mmio", CIRRUS_PNPMMIO_SIZE); memory_region_set_flush_coalesced(&s->cirrus_mmio_io); s->real_vram_size = (s->device_id == CIRRUS_ID_CLGD5446) ? 4096 * 1024 : 2048 * 1024; /* XXX: s->vga.vram_size must be a power of two */ s->cirrus_addr_mask = s->real_vram_size - 1; s->linear_mmio_mask = s->real_vram_size - 256; s->vga.get_bpp = cirrus_get_bpp; s->vga.get_offsets = cirrus_get_offsets; s->vga.get_resolution = cirrus_get_resolution; s->vga.cursor_invalidate = cirrus_cursor_invalidate; s->vga.cursor_draw_line = cirrus_cursor_draw_line; qemu_register_reset(cirrus_reset, s); }
@@ -661,9 +661,14 @@ static void cirrus_invalidate_region(CirrusVGAState * s, int off_begin, int off_cur; int off_cur_end; + if (off_pitch < 0) { + off_begin -= bytesperline - 1; + } + for (y = 0; y < lines; y++) { off_cur = off_begin; off_cur_end = (off_cur + bytesperline) & s->cirrus_addr_mask; + assert(off_cur_end >= off_cur); memory_region_set_dirty(&s->vga.vram, off_cur, off_cur_end - off_cur); off_begin += off_pitch; }
CWE-125
null
null
13,374
static void cirrus_vga_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); k->realize = pci_cirrus_vga_realize; k->romfile = VGABIOS_CIRRUS_FILENAME; k->vendor_id = PCI_VENDOR_ID_CIRRUS; k->device_id = CIRRUS_ID_CLGD5446; k->class_id = PCI_CLASS_DISPLAY_VGA; set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); dc->desc = "Cirrus CLGD 54xx VGA"; dc->vmsd = &vmstate_pci_cirrus_vga; dc->props = pci_vga_cirrus_properties; dc->hotpluggable = false; }
DoS
0
static void cirrus_vga_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); k->realize = pci_cirrus_vga_realize; k->romfile = VGABIOS_CIRRUS_FILENAME; k->vendor_id = PCI_VENDOR_ID_CIRRUS; k->device_id = CIRRUS_ID_CLGD5446; k->class_id = PCI_CLASS_DISPLAY_VGA; set_bit(DEVICE_CATEGORY_DISPLAY, dc->categories); dc->desc = "Cirrus CLGD 54xx VGA"; dc->vmsd = &vmstate_pci_cirrus_vga; dc->props = pci_vga_cirrus_properties; dc->hotpluggable = false; }
@@ -661,9 +661,14 @@ static void cirrus_invalidate_region(CirrusVGAState * s, int off_begin, int off_cur; int off_cur_end; + if (off_pitch < 0) { + off_begin -= bytesperline - 1; + } + for (y = 0; y < lines; y++) { off_cur = off_begin; off_cur_end = (off_cur + bytesperline) & s->cirrus_addr_mask; + assert(off_cur_end >= off_cur); memory_region_set_dirty(&s->vga.vram, off_cur, off_cur_end - off_cur); off_begin += off_pitch; }
CWE-125
null
null
13,375
static void cirrus_vga_write_sr(CirrusVGAState * s, uint32_t val) { switch (s->vga.sr_index) { case 0x00: // Standard VGA case 0x01: // Standard VGA case 0x02: // Standard VGA case 0x03: // Standard VGA case 0x04: // Standard VGA s->vga.sr[s->vga.sr_index] = val & sr_mask[s->vga.sr_index]; if (s->vga.sr_index == 1) s->vga.update_retrace_info(&s->vga); break; case 0x06: // Unlock Cirrus extensions val &= 0x17; if (val == 0x12) { s->vga.sr[s->vga.sr_index] = 0x12; } else { s->vga.sr[s->vga.sr_index] = 0x0f; } break; case 0x10: case 0x30: case 0x50: case 0x70: // Graphics Cursor X case 0x90: case 0xb0: case 0xd0: case 0xf0: // Graphics Cursor X s->vga.sr[0x10] = val; s->vga.hw_cursor_x = (val << 3) | (s->vga.sr_index >> 5); break; case 0x11: case 0x31: case 0x51: case 0x71: // Graphics Cursor Y case 0x91: case 0xb1: case 0xd1: case 0xf1: // Graphics Cursor Y s->vga.sr[0x11] = val; s->vga.hw_cursor_y = (val << 3) | (s->vga.sr_index >> 5); break; case 0x07: // Extended Sequencer Mode cirrus_update_memory_access(s); case 0x08: // EEPROM Control case 0x09: // Scratch Register 0 case 0x0a: // Scratch Register 1 case 0x0b: // VCLK 0 case 0x0c: // VCLK 1 case 0x0d: // VCLK 2 case 0x0e: // VCLK 3 case 0x0f: // DRAM Control case 0x13: // Graphics Cursor Pattern Address case 0x14: // Scratch Register 2 case 0x15: // Scratch Register 3 case 0x16: // Performance Tuning Register case 0x18: // Signature Generator Control case 0x19: // Signature Generator Result case 0x1a: // Signature Generator Result case 0x1b: // VCLK 0 Denominator & Post case 0x1c: // VCLK 1 Denominator & Post case 0x1d: // VCLK 2 Denominator & Post case 0x1e: // VCLK 3 Denominator & Post case 0x1f: // BIOS Write Enable and MCLK select s->vga.sr[s->vga.sr_index] = val; #ifdef DEBUG_CIRRUS printf("cirrus: handled outport sr_index %02x, sr_value %02x\n", s->vga.sr_index, val); #endif break; case 0x12: // Graphics Cursor Attribute s->vga.sr[0x12] = val; s->vga.force_shadow = !!(val & CIRRUS_CURSOR_SHOW); #ifdef DEBUG_CIRRUS printf("cirrus: cursor ctl SR12=%02x (force shadow: %d)\n", val, s->vga.force_shadow); #endif break; case 0x17: // Configuration Readback and Extended Control s->vga.sr[s->vga.sr_index] = (s->vga.sr[s->vga.sr_index] & 0x38) | (val & 0xc7); cirrus_update_memory_access(s); break; default: #ifdef DEBUG_CIRRUS printf("cirrus: outport sr_index %02x, sr_value %02x\n", s->vga.sr_index, val); #endif break; } }
DoS
0
static void cirrus_vga_write_sr(CirrusVGAState * s, uint32_t val) { switch (s->vga.sr_index) { case 0x00: // Standard VGA case 0x01: // Standard VGA case 0x02: // Standard VGA case 0x03: // Standard VGA case 0x04: // Standard VGA s->vga.sr[s->vga.sr_index] = val & sr_mask[s->vga.sr_index]; if (s->vga.sr_index == 1) s->vga.update_retrace_info(&s->vga); break; case 0x06: // Unlock Cirrus extensions val &= 0x17; if (val == 0x12) { s->vga.sr[s->vga.sr_index] = 0x12; } else { s->vga.sr[s->vga.sr_index] = 0x0f; } break; case 0x10: case 0x30: case 0x50: case 0x70: // Graphics Cursor X case 0x90: case 0xb0: case 0xd0: case 0xf0: // Graphics Cursor X s->vga.sr[0x10] = val; s->vga.hw_cursor_x = (val << 3) | (s->vga.sr_index >> 5); break; case 0x11: case 0x31: case 0x51: case 0x71: // Graphics Cursor Y case 0x91: case 0xb1: case 0xd1: case 0xf1: // Graphics Cursor Y s->vga.sr[0x11] = val; s->vga.hw_cursor_y = (val << 3) | (s->vga.sr_index >> 5); break; case 0x07: // Extended Sequencer Mode cirrus_update_memory_access(s); case 0x08: // EEPROM Control case 0x09: // Scratch Register 0 case 0x0a: // Scratch Register 1 case 0x0b: // VCLK 0 case 0x0c: // VCLK 1 case 0x0d: // VCLK 2 case 0x0e: // VCLK 3 case 0x0f: // DRAM Control case 0x13: // Graphics Cursor Pattern Address case 0x14: // Scratch Register 2 case 0x15: // Scratch Register 3 case 0x16: // Performance Tuning Register case 0x18: // Signature Generator Control case 0x19: // Signature Generator Result case 0x1a: // Signature Generator Result case 0x1b: // VCLK 0 Denominator & Post case 0x1c: // VCLK 1 Denominator & Post case 0x1d: // VCLK 2 Denominator & Post case 0x1e: // VCLK 3 Denominator & Post case 0x1f: // BIOS Write Enable and MCLK select s->vga.sr[s->vga.sr_index] = val; #ifdef DEBUG_CIRRUS printf("cirrus: handled outport sr_index %02x, sr_value %02x\n", s->vga.sr_index, val); #endif break; case 0x12: // Graphics Cursor Attribute s->vga.sr[0x12] = val; s->vga.force_shadow = !!(val & CIRRUS_CURSOR_SHOW); #ifdef DEBUG_CIRRUS printf("cirrus: cursor ctl SR12=%02x (force shadow: %d)\n", val, s->vga.force_shadow); #endif break; case 0x17: // Configuration Readback and Extended Control s->vga.sr[s->vga.sr_index] = (s->vga.sr[s->vga.sr_index] & 0x38) | (val & 0xc7); cirrus_update_memory_access(s); break; default: #ifdef DEBUG_CIRRUS printf("cirrus: outport sr_index %02x, sr_value %02x\n", s->vga.sr_index, val); #endif break; } }
@@ -661,9 +661,14 @@ static void cirrus_invalidate_region(CirrusVGAState * s, int off_begin, int off_cur; int off_cur_end; + if (off_pitch < 0) { + off_begin -= bytesperline - 1; + } + for (y = 0; y < lines; y++) { off_cur = off_begin; off_cur_end = (off_cur + bytesperline) & s->cirrus_addr_mask; + assert(off_cur_end >= off_cur); memory_region_set_dirty(&s->vga.vram, off_cur, off_cur_end - off_cur); off_begin += off_pitch; }
CWE-125
null
null
13,376
static void pci_cirrus_vga_realize(PCIDevice *dev, Error **errp) { PCICirrusVGAState *d = PCI_CIRRUS_VGA(dev); CirrusVGAState *s = &d->cirrus_vga; PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); int16_t device_id = pc->device_id; /* follow real hardware, cirrus card emulated has 4 MB video memory. Also accept 8 MB/16 MB for backward compatibility. */ if (s->vga.vram_size_mb != 4 && s->vga.vram_size_mb != 8 && s->vga.vram_size_mb != 16) { error_setg(errp, "Invalid cirrus_vga ram size '%u'", s->vga.vram_size_mb); return; } /* setup VGA */ vga_common_init(&s->vga, OBJECT(dev), true); cirrus_init_common(s, OBJECT(dev), device_id, 1, pci_address_space(dev), pci_address_space_io(dev)); s->vga.con = graphic_console_init(DEVICE(dev), 0, s->vga.hw_ops, &s->vga); /* setup PCI */ memory_region_init(&s->pci_bar, OBJECT(dev), "cirrus-pci-bar0", 0x2000000); /* XXX: add byte swapping apertures */ memory_region_add_subregion(&s->pci_bar, 0, &s->cirrus_linear_io); memory_region_add_subregion(&s->pci_bar, 0x1000000, &s->cirrus_linear_bitblt_io); /* setup memory space */ /* memory #0 LFB */ /* memory #1 memory-mapped I/O */ /* XXX: s->vga.vram_size must be a power of two */ pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->pci_bar); if (device_id == CIRRUS_ID_CLGD5446) { pci_register_bar(&d->dev, 1, 0, &s->cirrus_mmio_io); } }
DoS
0
static void pci_cirrus_vga_realize(PCIDevice *dev, Error **errp) { PCICirrusVGAState *d = PCI_CIRRUS_VGA(dev); CirrusVGAState *s = &d->cirrus_vga; PCIDeviceClass *pc = PCI_DEVICE_GET_CLASS(dev); int16_t device_id = pc->device_id; /* follow real hardware, cirrus card emulated has 4 MB video memory. Also accept 8 MB/16 MB for backward compatibility. */ if (s->vga.vram_size_mb != 4 && s->vga.vram_size_mb != 8 && s->vga.vram_size_mb != 16) { error_setg(errp, "Invalid cirrus_vga ram size '%u'", s->vga.vram_size_mb); return; } /* setup VGA */ vga_common_init(&s->vga, OBJECT(dev), true); cirrus_init_common(s, OBJECT(dev), device_id, 1, pci_address_space(dev), pci_address_space_io(dev)); s->vga.con = graphic_console_init(DEVICE(dev), 0, s->vga.hw_ops, &s->vga); /* setup PCI */ memory_region_init(&s->pci_bar, OBJECT(dev), "cirrus-pci-bar0", 0x2000000); /* XXX: add byte swapping apertures */ memory_region_add_subregion(&s->pci_bar, 0, &s->cirrus_linear_io); memory_region_add_subregion(&s->pci_bar, 0x1000000, &s->cirrus_linear_bitblt_io); /* setup memory space */ /* memory #0 LFB */ /* memory #1 memory-mapped I/O */ /* XXX: s->vga.vram_size must be a power of two */ pci_register_bar(&d->dev, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->pci_bar); if (device_id == CIRRUS_ID_CLGD5446) { pci_register_bar(&d->dev, 1, 0, &s->cirrus_mmio_io); } }
@@ -661,9 +661,14 @@ static void cirrus_invalidate_region(CirrusVGAState * s, int off_begin, int off_cur; int off_cur_end; + if (off_pitch < 0) { + off_begin -= bytesperline - 1; + } + for (y = 0; y < lines; y++) { off_cur = off_begin; off_cur_end = (off_cur + bytesperline) & s->cirrus_addr_mask; + assert(off_cur_end >= off_cur); memory_region_set_dirty(&s->vga.vram, off_cur, off_cur_end - off_cur); off_begin += off_pitch; }
CWE-125
null
null
13,377
check_file_permissions_reduced(i_ctx_t *i_ctx_p, const char *fname, int len, gx_io_device *iodev, const char *permitgroup) { long i; ref *permitlist = NULL; /* an empty string (first character == 0) if '\' character is */ /* recognized as a file name separator as on DOS & Windows */ const char *win_sep2 = "\\"; bool use_windows_pathsep = (gs_file_name_check_separator(win_sep2, 1, win_sep2) == 1); uint plen = gp_file_name_parents(fname, len); /* we're protecting arbitrary file system accesses, not Postscript device accesses. * Although, note that %pipe% is explicitly checked for and disallowed elsewhere */ if (iodev != iodev_default(imemory)) { return 0; } /* Assuming a reduced file name. */ if (dict_find_string(&(i_ctx_p->userparams), permitgroup, &permitlist) <= 0) return 0; /* if Permissions not found, just allow access */ for (i=0; i<r_size(permitlist); i++) { ref permitstring; const string_match_params win_filename_params = { '*', '?', '\\', true, true /* ignore case & '/' == '\\' */ }; const byte *permstr; uint permlen; int cwd_len = 0; if (array_get(imemory, permitlist, i, &permitstring) < 0 || r_type(&permitstring) != t_string ) break; /* any problem, just fail */ permstr = permitstring.value.bytes; permlen = r_size(&permitstring); /* * Check if any file name is permitted with "*". */ if (permlen == 1 && permstr[0] == '*') return 0; /* success */ /* * If the filename starts with parent references, * the permission element must start with same number of parent references. */ if (plen != 0 && plen != gp_file_name_parents((const char *)permstr, permlen)) continue; cwd_len = gp_file_name_cwds((const char *)permstr, permlen); /* * If the permission starts with "./", absolute paths * are not permitted. */ if (cwd_len > 0 && gp_file_name_is_absolute(fname, len)) continue; /* * If the permission starts with "./", relative paths * with no "./" are allowed as well as with "./". * 'fname' has no "./" because it is reduced. */ if (string_match( (const unsigned char*) fname, len, permstr + cwd_len, permlen - cwd_len, use_windows_pathsep ? &win_filename_params : NULL)) return 0; /* success */ } /* not found */ return gs_error_invalidfileaccess; }
+Info
0
check_file_permissions_reduced(i_ctx_t *i_ctx_p, const char *fname, int len, gx_io_device *iodev, const char *permitgroup) { long i; ref *permitlist = NULL; /* an empty string (first character == 0) if '\' character is */ /* recognized as a file name separator as on DOS & Windows */ const char *win_sep2 = "\\"; bool use_windows_pathsep = (gs_file_name_check_separator(win_sep2, 1, win_sep2) == 1); uint plen = gp_file_name_parents(fname, len); /* we're protecting arbitrary file system accesses, not Postscript device accesses. * Although, note that %pipe% is explicitly checked for and disallowed elsewhere */ if (iodev != iodev_default(imemory)) { return 0; } /* Assuming a reduced file name. */ if (dict_find_string(&(i_ctx_p->userparams), permitgroup, &permitlist) <= 0) return 0; /* if Permissions not found, just allow access */ for (i=0; i<r_size(permitlist); i++) { ref permitstring; const string_match_params win_filename_params = { '*', '?', '\\', true, true /* ignore case & '/' == '\\' */ }; const byte *permstr; uint permlen; int cwd_len = 0; if (array_get(imemory, permitlist, i, &permitstring) < 0 || r_type(&permitstring) != t_string ) break; /* any problem, just fail */ permstr = permitstring.value.bytes; permlen = r_size(&permitstring); /* * Check if any file name is permitted with "*". */ if (permlen == 1 && permstr[0] == '*') return 0; /* success */ /* * If the filename starts with parent references, * the permission element must start with same number of parent references. */ if (plen != 0 && plen != gp_file_name_parents((const char *)permstr, permlen)) continue; cwd_len = gp_file_name_cwds((const char *)permstr, permlen); /* * If the permission starts with "./", absolute paths * are not permitted. */ if (cwd_len > 0 && gp_file_name_is_absolute(fname, len)) continue; /* * If the permission starts with "./", relative paths * with no "./" are allowed as well as with "./". * 'fname' has no "./" because it is reduced. */ if (string_match( (const unsigned char*) fname, len, permstr + cwd_len, permlen - cwd_len, use_windows_pathsep ? &win_filename_params : NULL)) return 0; /* success */ } /* not found */ return gs_error_invalidfileaccess; }
@@ -410,7 +410,7 @@ file_continue(i_ctx_t *i_ctx_p) } else if (code > len) /* overran string */ return_error(gs_error_rangecheck); else if (iodev != iodev_default(imemory) - || (check_file_permissions_reduced(i_ctx_p, (char *)pscratch->value.bytes, code + devlen, iodev, "PermitFileReading")) == 0) { + || (check_file_permissions(i_ctx_p, (char *)pscratch->value.bytes, code + devlen, iodev, "PermitFileReading")) == 0) { push(1); ref_assign(op, pscratch); r_set_size(op, code + devlen);
CWE-200
null
null
13,378
lib_file_open_search_with_combine(gs_file_path_ptr lib_path, const gs_memory_t *mem, i_ctx_t *i_ctx_p, const char *fname, uint flen, char *buffer, int blen, uint *pclen, ref *pfile, gx_io_device *iodev, bool starting_arg_file, char *fmode) { stream *s; const gs_file_path *pfpath = lib_path; uint pi; int code = 1; for (pi = 0; pi < r_size(&pfpath->list) && code == 1; ++pi) { const ref *prdir = pfpath->list.value.refs + pi; const char *pstr = (const char *)prdir->value.const_bytes; uint plen = r_size(prdir), blen1 = blen; gs_parsed_file_name_t pname; gp_file_name_combine_result r; /* We need to concatenate and parse the file name here * if this path has a %device% prefix. */ if (pstr[0] == '%') { /* We concatenate directly since gp_file_name_combine_* * rules are not correct for other devices such as %rom% */ code = gs_parse_file_name(&pname, pstr, plen, mem); if (code < 0) { code = 1; continue; } if (blen < max(pname.len, plen) + flen) return_error(gs_error_limitcheck); memcpy(buffer, pname.fname, pname.len); memcpy(buffer+pname.len, fname, flen); code = pname.iodev->procs.open_file(pname.iodev, buffer, pname.len + flen, fmode, &s, (gs_memory_t *)mem); if (code < 0) { code = 1; continue; } make_stream_file(pfile, s, "r"); /* fill in the buffer with the device concatenated */ memcpy(buffer, pstr, plen); memcpy(buffer+plen, fname, flen); *pclen = plen + flen; code = 0; } else { r = gp_file_name_combine(pstr, plen, fname, flen, false, buffer, &blen1); if (r != gp_combine_success) continue; if (starting_arg_file || check_file_permissions(i_ctx_p, buffer, blen1, iodev, "PermitFileReading") >= 0) { if (iodev_os_open_file(iodev, (const char *)buffer, blen1, (const char *)fmode, &s, (gs_memory_t *)mem) == 0) { *pclen = blen1; make_stream_file(pfile, s, "r"); code = 0; } } else { struct stat fstat; /* If we are not allowed to open the file by check_file_permissions_aux() * and if the file exists, throw an error....... * Otherwise, keep searching. */ if ((*iodev->procs.file_status)(iodev, (const char *)buffer, &fstat) >= 0) { code = gs_note_error(gs_error_invalidfileaccess); } } } } return code; }
+Info
0
lib_file_open_search_with_combine(gs_file_path_ptr lib_path, const gs_memory_t *mem, i_ctx_t *i_ctx_p, const char *fname, uint flen, char *buffer, int blen, uint *pclen, ref *pfile, gx_io_device *iodev, bool starting_arg_file, char *fmode) { stream *s; const gs_file_path *pfpath = lib_path; uint pi; int code = 1; for (pi = 0; pi < r_size(&pfpath->list) && code == 1; ++pi) { const ref *prdir = pfpath->list.value.refs + pi; const char *pstr = (const char *)prdir->value.const_bytes; uint plen = r_size(prdir), blen1 = blen; gs_parsed_file_name_t pname; gp_file_name_combine_result r; /* We need to concatenate and parse the file name here * if this path has a %device% prefix. */ if (pstr[0] == '%') { /* We concatenate directly since gp_file_name_combine_* * rules are not correct for other devices such as %rom% */ code = gs_parse_file_name(&pname, pstr, plen, mem); if (code < 0) { code = 1; continue; } if (blen < max(pname.len, plen) + flen) return_error(gs_error_limitcheck); memcpy(buffer, pname.fname, pname.len); memcpy(buffer+pname.len, fname, flen); code = pname.iodev->procs.open_file(pname.iodev, buffer, pname.len + flen, fmode, &s, (gs_memory_t *)mem); if (code < 0) { code = 1; continue; } make_stream_file(pfile, s, "r"); /* fill in the buffer with the device concatenated */ memcpy(buffer, pstr, plen); memcpy(buffer+plen, fname, flen); *pclen = plen + flen; code = 0; } else { r = gp_file_name_combine(pstr, plen, fname, flen, false, buffer, &blen1); if (r != gp_combine_success) continue; if (starting_arg_file || check_file_permissions(i_ctx_p, buffer, blen1, iodev, "PermitFileReading") >= 0) { if (iodev_os_open_file(iodev, (const char *)buffer, blen1, (const char *)fmode, &s, (gs_memory_t *)mem) == 0) { *pclen = blen1; make_stream_file(pfile, s, "r"); code = 0; } } else { struct stat fstat; /* If we are not allowed to open the file by check_file_permissions_aux() * and if the file exists, throw an error....... * Otherwise, keep searching. */ if ((*iodev->procs.file_status)(iodev, (const char *)buffer, &fstat) >= 0) { code = gs_note_error(gs_error_invalidfileaccess); } } } } return code; }
@@ -410,7 +410,7 @@ file_continue(i_ctx_t *i_ctx_p) } else if (code > len) /* overran string */ return_error(gs_error_rangecheck); else if (iodev != iodev_default(imemory) - || (check_file_permissions_reduced(i_ctx_p, (char *)pscratch->value.bytes, code + devlen, iodev, "PermitFileReading")) == 0) { + || (check_file_permissions(i_ctx_p, (char *)pscratch->value.bytes, code + devlen, iodev, "PermitFileReading")) == 0) { push(1); ref_assign(op, pscratch); r_set_size(op, code + devlen);
CWE-200
null
null
13,379
zopen_file(i_ctx_t *i_ctx_p, const gs_parsed_file_name_t *pfn, const char *file_access, stream **ps, gs_memory_t *mem) { gx_io_device *const iodev = pfn->iodev; int code = 0; if (pfn->fname == NULL) { /* just a device */ iodev->state = i_ctx_p; code = iodev->procs.open_device(iodev, file_access, ps, mem); iodev->state = NULL; return code; } else { /* file */ iodev_proc_open_file((*open_file)) = iodev->procs.open_file; if (open_file == 0) open_file = iodev_os_open_file; /* Check OS files to make sure we allow the type of access */ if (open_file == iodev_os_open_file) { code = check_file_permissions(i_ctx_p, pfn->fname, pfn->len, pfn->iodev, file_access[0] == 'r' ? "PermitFileReading" : "PermitFileWriting"); if (code < 0 && !file_is_tempfile(i_ctx_p, (const uchar *)pfn->fname, pfn->len)) return code; } return open_file(iodev, pfn->fname, pfn->len, file_access, ps, mem); } }
+Info
0
zopen_file(i_ctx_t *i_ctx_p, const gs_parsed_file_name_t *pfn, const char *file_access, stream **ps, gs_memory_t *mem) { gx_io_device *const iodev = pfn->iodev; int code = 0; if (pfn->fname == NULL) { /* just a device */ iodev->state = i_ctx_p; code = iodev->procs.open_device(iodev, file_access, ps, mem); iodev->state = NULL; return code; } else { /* file */ iodev_proc_open_file((*open_file)) = iodev->procs.open_file; if (open_file == 0) open_file = iodev_os_open_file; /* Check OS files to make sure we allow the type of access */ if (open_file == iodev_os_open_file) { code = check_file_permissions(i_ctx_p, pfn->fname, pfn->len, pfn->iodev, file_access[0] == 'r' ? "PermitFileReading" : "PermitFileWriting"); if (code < 0 && !file_is_tempfile(i_ctx_p, (const uchar *)pfn->fname, pfn->len)) return code; } return open_file(iodev, pfn->fname, pfn->len, file_access, ps, mem); } }
@@ -410,7 +410,7 @@ file_continue(i_ctx_t *i_ctx_p) } else if (code > len) /* overran string */ return_error(gs_error_rangecheck); else if (iodev != iodev_default(imemory) - || (check_file_permissions_reduced(i_ctx_p, (char *)pscratch->value.bytes, code + devlen, iodev, "PermitFileReading")) == 0) { + || (check_file_permissions(i_ctx_p, (char *)pscratch->value.bytes, code + devlen, iodev, "PermitFileReading")) == 0) { push(1); ref_assign(op, pscratch); r_set_size(op, code + devlen);
CWE-200
null
null
13,380
static int is_white(int c) { return c == '\x00' || c == '\x09' || c == '\x0a' || c == '\x0c' || c == '\x0d' || c == '\x20'; }
Exec Code Overflow
0
static int is_white(int c) { return c == '\x00' || c == '\x09' || c == '\x0a' || c == '\x0c' || c == '\x0d' || c == '\x20'; }
@@ -6,9 +6,6 @@ /* Scan file for objects and reconstruct xref table */ -/* Define in PDF 1.7 to be 8388607, but mupdf is more lenient. */ -#define MAX_OBJECT_NUMBER (10 << 20) - struct entry { int num; @@ -436,7 +433,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc) break; } - if (num <= 0 || num > MAX_OBJECT_NUMBER) + if (num <= 0 || num > PDF_MAX_OBJECT_NUMBER) { fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", num, gen); goto have_next_token;
CWE-119
null
null
13,381
orphan_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj) { if (doc->orphans_count == doc->orphans_max) { int new_max = (doc->orphans_max ? doc->orphans_max*2 : 32); fz_try(ctx) { doc->orphans = fz_resize_array(ctx, doc->orphans, new_max, sizeof(*doc->orphans)); doc->orphans_max = new_max; } fz_catch(ctx) { pdf_drop_obj(ctx, obj); fz_rethrow(ctx); } } doc->orphans[doc->orphans_count++] = obj; }
Exec Code Overflow
0
orphan_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj) { if (doc->orphans_count == doc->orphans_max) { int new_max = (doc->orphans_max ? doc->orphans_max*2 : 32); fz_try(ctx) { doc->orphans = fz_resize_array(ctx, doc->orphans, new_max, sizeof(*doc->orphans)); doc->orphans_max = new_max; } fz_catch(ctx) { pdf_drop_obj(ctx, obj); fz_rethrow(ctx); } } doc->orphans[doc->orphans_count++] = obj; }
@@ -6,9 +6,6 @@ /* Scan file for objects and reconstruct xref table */ -/* Define in PDF 1.7 to be 8388607, but mupdf is more lenient. */ -#define MAX_OBJECT_NUMBER (10 << 20) - struct entry { int num; @@ -436,7 +433,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc) break; } - if (num <= 0 || num > MAX_OBJECT_NUMBER) + if (num <= 0 || num > PDF_MAX_OBJECT_NUMBER) { fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", num, gen); goto have_next_token;
CWE-119
null
null
13,382
pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, int64_t *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, int64_t *tmpofs, pdf_obj **root) { fz_stream *file = doc->file; pdf_token tok; int stm_len; *stmofsp = 0; if (stmlenp) *stmlenp = -1; stm_len = 0; /* On entry to this function, we know that we've just seen * '<int> <int> obj'. We expect the next thing we see to be a * pdf object. Regardless of the type of thing we meet next * we only need to fully parse it if it is a dictionary. */ tok = pdf_lex(ctx, file, buf); if (tok == PDF_TOK_OPEN_DICT) { pdf_obj *obj, *dict = NULL; fz_try(ctx) { dict = pdf_parse_dict(ctx, doc, file, buf); } fz_catch(ctx) { fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); /* Don't let a broken object at EOF overwrite a good one */ if (file->eof) fz_rethrow(ctx); /* Silently swallow the error */ dict = pdf_new_dict(ctx, NULL, 2); } /* We must be careful not to try to resolve any indirections * here. We have just read dict, so we know it to be a non * indirected dictionary. Before we look at any values that * we get back from looking up in it, we need to check they * aren't indirected. */ if (encrypt || id || root) { obj = pdf_dict_get(ctx, dict, PDF_NAME_Type); if (!pdf_is_indirect(ctx, obj) && pdf_name_eq(ctx, obj, PDF_NAME_XRef)) { if (encrypt) { obj = pdf_dict_get(ctx, dict, PDF_NAME_Encrypt); if (obj) { pdf_drop_obj(ctx, *encrypt); *encrypt = pdf_keep_obj(ctx, obj); } } if (id) { obj = pdf_dict_get(ctx, dict, PDF_NAME_ID); if (obj) { pdf_drop_obj(ctx, *id); *id = pdf_keep_obj(ctx, obj); } } if (root) *root = pdf_keep_obj(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Root)); } } obj = pdf_dict_get(ctx, dict, PDF_NAME_Length); if (!pdf_is_indirect(ctx, obj) && pdf_is_int(ctx, obj)) stm_len = pdf_to_int(ctx, obj); if (doc->file_reading_linearly && page) { obj = pdf_dict_get(ctx, dict, PDF_NAME_Type); if (!pdf_is_indirect(ctx, obj) && pdf_name_eq(ctx, obj, PDF_NAME_Page)) { pdf_drop_obj(ctx, *page); *page = pdf_keep_obj(ctx, dict); } } pdf_drop_obj(ctx, dict); } while ( tok != PDF_TOK_STREAM && tok != PDF_TOK_ENDOBJ && tok != PDF_TOK_ERROR && tok != PDF_TOK_EOF && tok != PDF_TOK_INT ) { *tmpofs = fz_tell(ctx, file); if (*tmpofs < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file"); tok = pdf_lex(ctx, file, buf); } if (tok == PDF_TOK_STREAM) { int c = fz_read_byte(ctx, file); if (c == '\r') { c = fz_peek_byte(ctx, file); if (c == '\n') fz_read_byte(ctx, file); } *stmofsp = fz_tell(ctx, file); if (*stmofsp < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek in file"); if (stm_len > 0) { fz_seek(ctx, file, *stmofsp + stm_len, 0); fz_try(ctx) { tok = pdf_lex(ctx, file, buf); } fz_catch(ctx) { fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); fz_warn(ctx, "cannot find endstream token, falling back to scanning"); } if (tok == PDF_TOK_ENDSTREAM) goto atobjend; fz_seek(ctx, file, *stmofsp, 0); } (void)fz_read(ctx, file, (unsigned char *) buf->scratch, 9); while (memcmp(buf->scratch, "endstream", 9) != 0) { c = fz_read_byte(ctx, file); if (c == EOF) break; memmove(&buf->scratch[0], &buf->scratch[1], 8); buf->scratch[8] = c; } if (stmlenp) *stmlenp = fz_tell(ctx, file) - *stmofsp - 9; atobjend: *tmpofs = fz_tell(ctx, file); if (*tmpofs < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file"); tok = pdf_lex(ctx, file, buf); if (tok != PDF_TOK_ENDOBJ) fz_warn(ctx, "object missing 'endobj' token"); else { /* Read another token as we always return the next one */ *tmpofs = fz_tell(ctx, file); if (*tmpofs < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file"); tok = pdf_lex(ctx, file, buf); } } return tok; }
Exec Code Overflow
0
pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, int64_t *stmofsp, int *stmlenp, pdf_obj **encrypt, pdf_obj **id, pdf_obj **page, int64_t *tmpofs, pdf_obj **root) { fz_stream *file = doc->file; pdf_token tok; int stm_len; *stmofsp = 0; if (stmlenp) *stmlenp = -1; stm_len = 0; /* On entry to this function, we know that we've just seen * '<int> <int> obj'. We expect the next thing we see to be a * pdf object. Regardless of the type of thing we meet next * we only need to fully parse it if it is a dictionary. */ tok = pdf_lex(ctx, file, buf); if (tok == PDF_TOK_OPEN_DICT) { pdf_obj *obj, *dict = NULL; fz_try(ctx) { dict = pdf_parse_dict(ctx, doc, file, buf); } fz_catch(ctx) { fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); /* Don't let a broken object at EOF overwrite a good one */ if (file->eof) fz_rethrow(ctx); /* Silently swallow the error */ dict = pdf_new_dict(ctx, NULL, 2); } /* We must be careful not to try to resolve any indirections * here. We have just read dict, so we know it to be a non * indirected dictionary. Before we look at any values that * we get back from looking up in it, we need to check they * aren't indirected. */ if (encrypt || id || root) { obj = pdf_dict_get(ctx, dict, PDF_NAME_Type); if (!pdf_is_indirect(ctx, obj) && pdf_name_eq(ctx, obj, PDF_NAME_XRef)) { if (encrypt) { obj = pdf_dict_get(ctx, dict, PDF_NAME_Encrypt); if (obj) { pdf_drop_obj(ctx, *encrypt); *encrypt = pdf_keep_obj(ctx, obj); } } if (id) { obj = pdf_dict_get(ctx, dict, PDF_NAME_ID); if (obj) { pdf_drop_obj(ctx, *id); *id = pdf_keep_obj(ctx, obj); } } if (root) *root = pdf_keep_obj(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Root)); } } obj = pdf_dict_get(ctx, dict, PDF_NAME_Length); if (!pdf_is_indirect(ctx, obj) && pdf_is_int(ctx, obj)) stm_len = pdf_to_int(ctx, obj); if (doc->file_reading_linearly && page) { obj = pdf_dict_get(ctx, dict, PDF_NAME_Type); if (!pdf_is_indirect(ctx, obj) && pdf_name_eq(ctx, obj, PDF_NAME_Page)) { pdf_drop_obj(ctx, *page); *page = pdf_keep_obj(ctx, dict); } } pdf_drop_obj(ctx, dict); } while ( tok != PDF_TOK_STREAM && tok != PDF_TOK_ENDOBJ && tok != PDF_TOK_ERROR && tok != PDF_TOK_EOF && tok != PDF_TOK_INT ) { *tmpofs = fz_tell(ctx, file); if (*tmpofs < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file"); tok = pdf_lex(ctx, file, buf); } if (tok == PDF_TOK_STREAM) { int c = fz_read_byte(ctx, file); if (c == '\r') { c = fz_peek_byte(ctx, file); if (c == '\n') fz_read_byte(ctx, file); } *stmofsp = fz_tell(ctx, file); if (*stmofsp < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot seek in file"); if (stm_len > 0) { fz_seek(ctx, file, *stmofsp + stm_len, 0); fz_try(ctx) { tok = pdf_lex(ctx, file, buf); } fz_catch(ctx) { fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); fz_warn(ctx, "cannot find endstream token, falling back to scanning"); } if (tok == PDF_TOK_ENDSTREAM) goto atobjend; fz_seek(ctx, file, *stmofsp, 0); } (void)fz_read(ctx, file, (unsigned char *) buf->scratch, 9); while (memcmp(buf->scratch, "endstream", 9) != 0) { c = fz_read_byte(ctx, file); if (c == EOF) break; memmove(&buf->scratch[0], &buf->scratch[1], 8); buf->scratch[8] = c; } if (stmlenp) *stmlenp = fz_tell(ctx, file) - *stmofsp - 9; atobjend: *tmpofs = fz_tell(ctx, file); if (*tmpofs < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file"); tok = pdf_lex(ctx, file, buf); if (tok != PDF_TOK_ENDOBJ) fz_warn(ctx, "object missing 'endobj' token"); else { /* Read another token as we always return the next one */ *tmpofs = fz_tell(ctx, file); if (*tmpofs < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot tell in file"); tok = pdf_lex(ctx, file, buf); } } return tok; }
@@ -6,9 +6,6 @@ /* Scan file for objects and reconstruct xref table */ -/* Define in PDF 1.7 to be 8388607, but mupdf is more lenient. */ -#define MAX_OBJECT_NUMBER (10 << 20) - struct entry { int num; @@ -436,7 +433,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc) break; } - if (num <= 0 || num > MAX_OBJECT_NUMBER) + if (num <= 0 || num > PDF_MAX_OBJECT_NUMBER) { fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", num, gen); goto have_next_token;
CWE-119
null
null
13,383
pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int stm_num) { pdf_obj *obj; fz_stream *stm = NULL; pdf_token tok; int i, n, count; pdf_lexbuf buf; fz_var(stm); pdf_lexbuf_init(ctx, &buf, PDF_LEXBUF_SMALL); fz_try(ctx) { obj = pdf_load_object(ctx, doc, stm_num); count = pdf_to_int(ctx, pdf_dict_get(ctx, obj, PDF_NAME_N)); pdf_drop_obj(ctx, obj); stm = pdf_open_stream_number(ctx, doc, stm_num); for (i = 0; i < count; i++) { pdf_xref_entry *entry; tok = pdf_lex(ctx, stm, &buf); if (tok != PDF_TOK_INT) fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d 0 R)", stm_num); n = buf.i; if (n < 0) { fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", n, i); continue; } else if (n >= pdf_xref_len(ctx, doc)) { fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", n, i); continue; } entry = pdf_get_populating_xref_entry(ctx, doc, n); entry->ofs = stm_num; entry->gen = i; entry->num = n; entry->stm_ofs = 0; pdf_drop_obj(ctx, entry->obj); entry->obj = NULL; entry->type = 'o'; tok = pdf_lex(ctx, stm, &buf); if (tok != PDF_TOK_INT) fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d 0 R)", stm_num); } } fz_always(ctx) { fz_drop_stream(ctx, stm); pdf_lexbuf_fin(ctx, &buf); } fz_catch(ctx) { fz_rethrow(ctx); } }
Exec Code Overflow
0
pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int stm_num) { pdf_obj *obj; fz_stream *stm = NULL; pdf_token tok; int i, n, count; pdf_lexbuf buf; fz_var(stm); pdf_lexbuf_init(ctx, &buf, PDF_LEXBUF_SMALL); fz_try(ctx) { obj = pdf_load_object(ctx, doc, stm_num); count = pdf_to_int(ctx, pdf_dict_get(ctx, obj, PDF_NAME_N)); pdf_drop_obj(ctx, obj); stm = pdf_open_stream_number(ctx, doc, stm_num); for (i = 0; i < count; i++) { pdf_xref_entry *entry; tok = pdf_lex(ctx, stm, &buf); if (tok != PDF_TOK_INT) fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d 0 R)", stm_num); n = buf.i; if (n < 0) { fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", n, i); continue; } else if (n >= pdf_xref_len(ctx, doc)) { fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", n, i); continue; } entry = pdf_get_populating_xref_entry(ctx, doc, n); entry->ofs = stm_num; entry->gen = i; entry->num = n; entry->stm_ofs = 0; pdf_drop_obj(ctx, entry->obj); entry->obj = NULL; entry->type = 'o'; tok = pdf_lex(ctx, stm, &buf); if (tok != PDF_TOK_INT) fz_throw(ctx, FZ_ERROR_GENERIC, "corrupt object stream (%d 0 R)", stm_num); } } fz_always(ctx) { fz_drop_stream(ctx, stm); pdf_lexbuf_fin(ctx, &buf); } fz_catch(ctx) { fz_rethrow(ctx); } }
@@ -6,9 +6,6 @@ /* Scan file for objects and reconstruct xref table */ -/* Define in PDF 1.7 to be 8388607, but mupdf is more lenient. */ -#define MAX_OBJECT_NUMBER (10 << 20) - struct entry { int num; @@ -436,7 +433,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc) break; } - if (num <= 0 || num > MAX_OBJECT_NUMBER) + if (num <= 0 || num > PDF_MAX_OBJECT_NUMBER) { fz_warn(ctx, "ignoring object with invalid object number (%d %d R)", num, gen); goto have_next_token;
CWE-119
null
null
13,384
pdf_cache_object(fz_context *ctx, pdf_document *doc, int num) { pdf_xref_entry *x; int rnum, rgen, try_repair; fz_var(try_repair); if (num <= 0 || num >= pdf_xref_len(ctx, doc)) fz_throw(ctx, FZ_ERROR_GENERIC, "object out of range (%d 0 R); xref size %d", num, pdf_xref_len(ctx, doc)); object_updated: try_repair = 0; rnum = num; x = pdf_get_xref_entry(ctx, doc, num); if (x->obj != NULL) return x; if (x->type == 'f') { x->obj = pdf_new_null(ctx, doc); } else if (x->type == 'n') { fz_seek(ctx, doc->file, x->ofs, SEEK_SET); fz_try(ctx) { x->obj = pdf_parse_ind_obj(ctx, doc, doc->file, &doc->lexbuf.base, &rnum, &rgen, &x->stm_ofs, &try_repair); } fz_catch(ctx) { if (!try_repair || fz_caught(ctx) == FZ_ERROR_TRYLATER) fz_rethrow(ctx); } if (!try_repair && rnum != num) { pdf_drop_obj(ctx, x->obj); x->type = 'f'; x->ofs = -1; x->gen = 0; x->num = 0; x->stm_ofs = 0; x->obj = NULL; try_repair = (doc->repair_attempted == 0); } if (try_repair) { fz_try(ctx) { pdf_repair_xref(ctx, doc); pdf_prime_xref_index(ctx, doc); pdf_repair_obj_stms(ctx, doc); } fz_catch(ctx) { if (rnum == num) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse object (%d 0 R)", num); else fz_throw(ctx, FZ_ERROR_GENERIC, "found object (%d 0 R) instead of (%d 0 R)", rnum, num); } goto object_updated; } if (doc->crypt) pdf_crypt_obj(ctx, doc->crypt, x->obj, x->num, x->gen); } else if (x->type == 'o') { if (!x->obj) { x = pdf_load_obj_stm(ctx, doc, x->ofs, &doc->lexbuf.base, num); if (x == NULL) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load object stream containing object (%d 0 R)", num); if (!x->obj) fz_throw(ctx, FZ_ERROR_GENERIC, "object (%d 0 R) was not found in its object stream", num); } } else if (doc->hint_obj_offsets && read_hinted_object(ctx, doc, num)) { goto object_updated; } else if (doc->file_length && doc->linear_pos < doc->file_length) { fz_throw(ctx, FZ_ERROR_TRYLATER, "cannot find object in xref (%d 0 R) - not loaded yet?", num); } else { fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find object in xref (%d 0 R)", num); } pdf_set_obj_parent(ctx, x->obj, num); return x; }
Exec Code Overflow
0
pdf_cache_object(fz_context *ctx, pdf_document *doc, int num) { pdf_xref_entry *x; int rnum, rgen, try_repair; fz_var(try_repair); if (num <= 0 || num >= pdf_xref_len(ctx, doc)) fz_throw(ctx, FZ_ERROR_GENERIC, "object out of range (%d 0 R); xref size %d", num, pdf_xref_len(ctx, doc)); object_updated: try_repair = 0; rnum = num; x = pdf_get_xref_entry(ctx, doc, num); if (x->obj != NULL) return x; if (x->type == 'f') { x->obj = pdf_new_null(ctx, doc); } else if (x->type == 'n') { fz_seek(ctx, doc->file, x->ofs, SEEK_SET); fz_try(ctx) { x->obj = pdf_parse_ind_obj(ctx, doc, doc->file, &doc->lexbuf.base, &rnum, &rgen, &x->stm_ofs, &try_repair); } fz_catch(ctx) { if (!try_repair || fz_caught(ctx) == FZ_ERROR_TRYLATER) fz_rethrow(ctx); } if (!try_repair && rnum != num) { pdf_drop_obj(ctx, x->obj); x->type = 'f'; x->ofs = -1; x->gen = 0; x->num = 0; x->stm_ofs = 0; x->obj = NULL; try_repair = (doc->repair_attempted == 0); } if (try_repair) { fz_try(ctx) { pdf_repair_xref(ctx, doc); pdf_prime_xref_index(ctx, doc); pdf_repair_obj_stms(ctx, doc); } fz_catch(ctx) { if (rnum == num) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse object (%d 0 R)", num); else fz_throw(ctx, FZ_ERROR_GENERIC, "found object (%d 0 R) instead of (%d 0 R)", rnum, num); } goto object_updated; } if (doc->crypt) pdf_crypt_obj(ctx, doc->crypt, x->obj, x->num, x->gen); } else if (x->type == 'o') { if (!x->obj) { x = pdf_load_obj_stm(ctx, doc, x->ofs, &doc->lexbuf.base, num); if (x == NULL) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load object stream containing object (%d 0 R)", num); if (!x->obj) fz_throw(ctx, FZ_ERROR_GENERIC, "object (%d 0 R) was not found in its object stream", num); } } else if (doc->hint_obj_offsets && read_hinted_object(ctx, doc, num)) { goto object_updated; } else if (doc->file_length && doc->linear_pos < doc->file_length) { fz_throw(ctx, FZ_ERROR_TRYLATER, "cannot find object in xref (%d 0 R) - not loaded yet?", num); } else { fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find object in xref (%d 0 R)", num); } pdf_set_obj_parent(ctx, x->obj, num); return x; }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,385
pdf_count_objects(fz_context *ctx, pdf_document *doc) { return pdf_xref_len(ctx, doc); }
Exec Code Overflow
0
pdf_count_objects(fz_context *ctx, pdf_document *doc) { return pdf_xref_len(ctx, doc); }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,386
pdf_drop_document(fz_context *ctx, pdf_document *doc) { fz_drop_document(ctx, &doc->super); }
Exec Code Overflow
0
pdf_drop_document(fz_context *ctx, pdf_document *doc) { fz_drop_document(ctx, &doc->super); }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,387
pdf_drop_document_imp(fz_context *ctx, pdf_document *doc) { int i; fz_defer_reap_start(ctx); /* Type3 glyphs in the glyph cache can contain pdf_obj pointers * that we are about to destroy. Simplest solution is to bin the * glyph cache at this point. */ fz_try(ctx) fz_purge_glyph_cache(ctx); fz_catch(ctx) { /* Swallow error, but continue dropping */ } pdf_drop_js(ctx, doc->js); pdf_drop_xref_sections(ctx, doc); fz_free(ctx, doc->xref_index); pdf_drop_obj(ctx, doc->focus_obj); fz_drop_stream(ctx, doc->file); pdf_drop_crypt(ctx, doc->crypt); pdf_drop_obj(ctx, doc->linear_obj); if (doc->linear_page_refs) { for (i=0; i < doc->linear_page_count; i++) pdf_drop_obj(ctx, doc->linear_page_refs[i]); fz_free(ctx, doc->linear_page_refs); } fz_free(ctx, doc->hint_page); fz_free(ctx, doc->hint_shared_ref); fz_free(ctx, doc->hint_shared); fz_free(ctx, doc->hint_obj_offsets); for (i=0; i < doc->num_type3_fonts; i++) { fz_try(ctx) fz_decouple_type3_font(ctx, doc->type3_fonts[i], (void *)doc); fz_always(ctx) fz_drop_font(ctx, doc->type3_fonts[i]); fz_catch(ctx) { /* Swallow error, but continue dropping */ } } fz_free(ctx, doc->type3_fonts); pdf_drop_ocg(ctx, doc); pdf_drop_portfolio(ctx, doc); pdf_empty_store(ctx, doc); pdf_lexbuf_fin(ctx, &doc->lexbuf.base); pdf_drop_resource_tables(ctx, doc); fz_drop_colorspace(ctx, doc->oi); for (i = 0; i < doc->orphans_count; i++) pdf_drop_obj(ctx, doc->orphans[i]); fz_free(ctx, doc->orphans); fz_free(ctx, doc->rev_page_map); fz_defer_reap_end(ctx); }
Exec Code Overflow
0
pdf_drop_document_imp(fz_context *ctx, pdf_document *doc) { int i; fz_defer_reap_start(ctx); /* Type3 glyphs in the glyph cache can contain pdf_obj pointers * that we are about to destroy. Simplest solution is to bin the * glyph cache at this point. */ fz_try(ctx) fz_purge_glyph_cache(ctx); fz_catch(ctx) { /* Swallow error, but continue dropping */ } pdf_drop_js(ctx, doc->js); pdf_drop_xref_sections(ctx, doc); fz_free(ctx, doc->xref_index); pdf_drop_obj(ctx, doc->focus_obj); fz_drop_stream(ctx, doc->file); pdf_drop_crypt(ctx, doc->crypt); pdf_drop_obj(ctx, doc->linear_obj); if (doc->linear_page_refs) { for (i=0; i < doc->linear_page_count; i++) pdf_drop_obj(ctx, doc->linear_page_refs[i]); fz_free(ctx, doc->linear_page_refs); } fz_free(ctx, doc->hint_page); fz_free(ctx, doc->hint_shared_ref); fz_free(ctx, doc->hint_shared); fz_free(ctx, doc->hint_obj_offsets); for (i=0; i < doc->num_type3_fonts; i++) { fz_try(ctx) fz_decouple_type3_font(ctx, doc->type3_fonts[i], (void *)doc); fz_always(ctx) fz_drop_font(ctx, doc->type3_fonts[i]); fz_catch(ctx) { /* Swallow error, but continue dropping */ } } fz_free(ctx, doc->type3_fonts); pdf_drop_ocg(ctx, doc); pdf_drop_portfolio(ctx, doc); pdf_empty_store(ctx, doc); pdf_lexbuf_fin(ctx, &doc->lexbuf.base); pdf_drop_resource_tables(ctx, doc); fz_drop_colorspace(ctx, doc->oi); for (i = 0; i < doc->orphans_count; i++) pdf_drop_obj(ctx, doc->orphans[i]); fz_free(ctx, doc->orphans); fz_free(ctx, doc->rev_page_map); fz_defer_reap_end(ctx); }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,388
static void pdf_drop_xref_sections(fz_context *ctx, pdf_document *doc) { pdf_drop_xref_sections_imp(ctx, doc, doc->saved_xref_sections, doc->saved_num_xref_sections); pdf_drop_xref_sections_imp(ctx, doc, doc->xref_sections, doc->num_xref_sections); doc->saved_xref_sections = NULL; doc->saved_num_xref_sections = 0; doc->xref_sections = NULL; doc->num_xref_sections = 0; doc->num_incremental_sections = 0; }
Exec Code Overflow
0
static void pdf_drop_xref_sections(fz_context *ctx, pdf_document *doc) { pdf_drop_xref_sections_imp(ctx, doc, doc->saved_xref_sections, doc->saved_num_xref_sections); pdf_drop_xref_sections_imp(ctx, doc, doc->xref_sections, doc->num_xref_sections); doc->saved_xref_sections = NULL; doc->saved_num_xref_sections = 0; doc->xref_sections = NULL; doc->num_xref_sections = 0; doc->num_incremental_sections = 0; }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,389
static void pdf_drop_xref_sections_imp(fz_context *ctx, pdf_document *doc, pdf_xref *xref_sections, int num_xref_sections) { pdf_unsaved_sig *usig; int x, e; for (x = 0; x < num_xref_sections; x++) { pdf_xref *xref = &xref_sections[x]; pdf_xref_subsec *sub = xref->subsec; while (sub != NULL) { pdf_xref_subsec *next_sub = sub->next; for (e = 0; e < sub->len; e++) { pdf_xref_entry *entry = &sub->table[e]; if (entry->obj) { pdf_drop_obj(ctx, entry->obj); fz_drop_buffer(ctx, entry->stm_buf); } } fz_free(ctx, sub->table); fz_free(ctx, sub); sub = next_sub; } pdf_drop_obj(ctx, xref->pre_repair_trailer); pdf_drop_obj(ctx, xref->trailer); while ((usig = xref->unsaved_sigs) != NULL) { xref->unsaved_sigs = usig->next; pdf_drop_obj(ctx, usig->field); pdf_drop_signer(ctx, usig->signer); fz_free(ctx, usig); } } fz_free(ctx, xref_sections); }
Exec Code Overflow
0
static void pdf_drop_xref_sections_imp(fz_context *ctx, pdf_document *doc, pdf_xref *xref_sections, int num_xref_sections) { pdf_unsaved_sig *usig; int x, e; for (x = 0; x < num_xref_sections; x++) { pdf_xref *xref = &xref_sections[x]; pdf_xref_subsec *sub = xref->subsec; while (sub != NULL) { pdf_xref_subsec *next_sub = sub->next; for (e = 0; e < sub->len; e++) { pdf_xref_entry *entry = &sub->table[e]; if (entry->obj) { pdf_drop_obj(ctx, entry->obj); fz_drop_buffer(ctx, entry->stm_buf); } } fz_free(ctx, sub->table); fz_free(ctx, sub); sub = next_sub; } pdf_drop_obj(ctx, xref->pre_repair_trailer); pdf_drop_obj(ctx, xref->trailer); while ((usig = xref->unsaved_sigs) != NULL) { xref->unsaved_sigs = usig->next; pdf_drop_obj(ctx, usig->field); pdf_drop_signer(ctx, usig->signer); fz_free(ctx, usig); } } fz_free(ctx, xref_sections); }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,390
void pdf_ensure_solid_xref(fz_context *ctx, pdf_document *doc, int num) { if (doc->num_xref_sections == 0) pdf_populate_next_xref_level(ctx, doc); ensure_solid_xref(ctx, doc, num, doc->num_xref_sections-1); }
Exec Code Overflow
0
void pdf_ensure_solid_xref(fz_context *ctx, pdf_document *doc, int num) { if (doc->num_xref_sections == 0) pdf_populate_next_xref_level(ctx, doc); ensure_solid_xref(ctx, doc, num, doc->num_xref_sections-1); }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,391
pdf_xref_entry *pdf_get_populating_xref_entry(fz_context *ctx, pdf_document *doc, int num) { /* Return an entry within the xref currently being populated */ pdf_xref *xref; pdf_xref_subsec *sub; if (doc->num_xref_sections == 0) { doc->xref_sections = fz_malloc_struct(ctx, pdf_xref); doc->num_xref_sections = 1; } /* Prevent accidental heap underflow */ if (num < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "object number must not be negative (%d)", num); /* Return the pointer to the entry in the last section. */ xref = &doc->xref_sections[doc->num_xref_sections-1]; for (sub = xref->subsec; sub != NULL; sub = sub->next) { if (num >= sub->start && num < sub->start + sub->len) return &sub->table[num-sub->start]; } /* We've been asked for an object that's not in a subsec. */ ensure_solid_xref(ctx, doc, num+1, doc->num_xref_sections-1); xref = &doc->xref_sections[doc->num_xref_sections-1]; sub = xref->subsec; return &sub->table[num-sub->start]; }
Exec Code Overflow
0
pdf_xref_entry *pdf_get_populating_xref_entry(fz_context *ctx, pdf_document *doc, int num) { /* Return an entry within the xref currently being populated */ pdf_xref *xref; pdf_xref_subsec *sub; if (doc->num_xref_sections == 0) { doc->xref_sections = fz_malloc_struct(ctx, pdf_xref); doc->num_xref_sections = 1; } /* Prevent accidental heap underflow */ if (num < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "object number must not be negative (%d)", num); /* Return the pointer to the entry in the last section. */ xref = &doc->xref_sections[doc->num_xref_sections-1]; for (sub = xref->subsec; sub != NULL; sub = sub->next) { if (num >= sub->start && num < sub->start + sub->len) return &sub->table[num-sub->start]; } /* We've been asked for an object that's not in a subsec. */ ensure_solid_xref(ctx, doc, num+1, doc->num_xref_sections-1); xref = &doc->xref_sections[doc->num_xref_sections-1]; sub = xref->subsec; return &sub->table[num-sub->start]; }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,392
pdf_xref_entry *pdf_get_xref_entry(fz_context *ctx, pdf_document *doc, int i) { pdf_xref *xref = NULL; pdf_xref_subsec *sub; int j; if (i < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "Negative object number requested"); if (i <= doc->max_xref_len) j = doc->xref_index[i]; else j = 0; /* We may be accessing an earlier version of the document using xref_base * and j may be an index into a later xref section */ if (doc->xref_base > j) j = doc->xref_base; /* Find the first xref section where the entry is defined. */ for (; j < doc->num_xref_sections; j++) { xref = &doc->xref_sections[j]; if (i < xref->num_objects) { for (sub = xref->subsec; sub != NULL; sub = sub->next) { pdf_xref_entry *entry; if (i < sub->start || i >= sub->start + sub->len) continue; entry = &sub->table[i - sub->start]; if (entry->type) { /* Don't update xref_index if xref_base may have * influenced the value of j */ if (doc->xref_base == 0) doc->xref_index[i] = j; return entry; } } } } /* Didn't find the entry in any section. Return the entry from * the final section. */ doc->xref_index[i] = 0; if (xref == NULL || i < xref->num_objects) { xref = &doc->xref_sections[doc->xref_base]; for (sub = xref->subsec; sub != NULL; sub = sub->next) { if (i >= sub->start && i < sub->start + sub->len) return &sub->table[i - sub->start]; } } /* At this point, we solidify the xref. This ensures that we * can return a pointer. This is the only case where this function * might throw an exception, and it will never happen when we are * working within a 'solid' xref. */ ensure_solid_xref(ctx, doc, i+1, 0); xref = &doc->xref_sections[0]; sub = xref->subsec; return &sub->table[i - sub->start]; }
Exec Code Overflow
0
pdf_xref_entry *pdf_get_xref_entry(fz_context *ctx, pdf_document *doc, int i) { pdf_xref *xref = NULL; pdf_xref_subsec *sub; int j; if (i < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "Negative object number requested"); if (i <= doc->max_xref_len) j = doc->xref_index[i]; else j = 0; /* We may be accessing an earlier version of the document using xref_base * and j may be an index into a later xref section */ if (doc->xref_base > j) j = doc->xref_base; /* Find the first xref section where the entry is defined. */ for (; j < doc->num_xref_sections; j++) { xref = &doc->xref_sections[j]; if (i < xref->num_objects) { for (sub = xref->subsec; sub != NULL; sub = sub->next) { pdf_xref_entry *entry; if (i < sub->start || i >= sub->start + sub->len) continue; entry = &sub->table[i - sub->start]; if (entry->type) { /* Don't update xref_index if xref_base may have * influenced the value of j */ if (doc->xref_base == 0) doc->xref_index[i] = j; return entry; } } } } /* Didn't find the entry in any section. Return the entry from * the final section. */ doc->xref_index[i] = 0; if (xref == NULL || i < xref->num_objects) { xref = &doc->xref_sections[doc->xref_base]; for (sub = xref->subsec; sub != NULL; sub = sub->next) { if (i >= sub->start && i < sub->start + sub->len) return &sub->table[i - sub->start]; } } /* At this point, we solidify the xref. This ensures that we * can return a pointer. This is the only case where this function * might throw an exception, and it will never happen when we are * working within a 'solid' xref. */ ensure_solid_xref(ctx, doc, i+1, 0); xref = &doc->xref_sections[0]; sub = xref->subsec; return &sub->table[i - sub->start]; }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,393
pdf_keep_document(fz_context *ctx, pdf_document *doc) { return (pdf_document *)fz_keep_document(ctx, &doc->super); }
Exec Code Overflow
0
pdf_keep_document(fz_context *ctx, pdf_document *doc) { return (pdf_document *)fz_keep_document(ctx, &doc->super); }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,394
pdf_load_hinted_page(fz_context *ctx, pdf_document *doc, int pagenum) { if (!doc->hints_loaded || !doc->linear_page_refs) return; if (doc->linear_page_refs[pagenum]) return; fz_try(ctx) { int num = doc->hint_page[pagenum].number; pdf_obj *page = pdf_load_object(ctx, doc, num); if (pdf_name_eq(ctx, PDF_NAME_Page, pdf_dict_get(ctx, page, PDF_NAME_Type))) { /* We have found the page object! */ DEBUGMESS((ctx, "LoadHintedPage pagenum=%d num=%d", pagenum, num)); doc->linear_page_refs[pagenum] = pdf_new_indirect(ctx, doc, num, 0); } pdf_drop_obj(ctx, page); } fz_catch(ctx) { fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); /* Silently swallow the error and proceed as normal */ } }
Exec Code Overflow
0
pdf_load_hinted_page(fz_context *ctx, pdf_document *doc, int pagenum) { if (!doc->hints_loaded || !doc->linear_page_refs) return; if (doc->linear_page_refs[pagenum]) return; fz_try(ctx) { int num = doc->hint_page[pagenum].number; pdf_obj *page = pdf_load_object(ctx, doc, num); if (pdf_name_eq(ctx, PDF_NAME_Page, pdf_dict_get(ctx, page, PDF_NAME_Type))) { /* We have found the page object! */ DEBUGMESS((ctx, "LoadHintedPage pagenum=%d num=%d", pagenum, num)); doc->linear_page_refs[pagenum] = pdf_new_indirect(ctx, doc, num, 0); } pdf_drop_obj(ctx, page); } fz_catch(ctx) { fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); /* Silently swallow the error and proceed as normal */ } }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,395
pdf_load_object(fz_context *ctx, pdf_document *doc, int num) { pdf_xref_entry *entry = pdf_cache_object(ctx, doc, num); assert(entry->obj != NULL); return pdf_keep_obj(ctx, entry->obj); }
Exec Code Overflow
0
pdf_load_object(fz_context *ctx, pdf_document *doc, int num) { pdf_xref_entry *entry = pdf_cache_object(ctx, doc, num); assert(entry->obj != NULL); return pdf_keep_obj(ctx, entry->obj); }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,396
pdf_load_version(fz_context *ctx, pdf_document *doc) { char buf[20]; fz_seek(ctx, doc->file, 0, SEEK_SET); fz_read_line(ctx, doc->file, buf, sizeof buf); if (memcmp(buf, "%PDF-", 5) != 0) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot recognize version marker"); doc->version = 10 * (fz_atof(buf+5) + 0.05f); if (doc->version < 10 || doc->version > 17) if (doc->version != 20) fz_warn(ctx, "unknown PDF version: %d.%d", doc->version / 10, doc->version % 10); }
Exec Code Overflow
0
pdf_load_version(fz_context *ctx, pdf_document *doc) { char buf[20]; fz_seek(ctx, doc->file, 0, SEEK_SET); fz_read_line(ctx, doc->file, buf, sizeof buf); if (memcmp(buf, "%PDF-", 5) != 0) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot recognize version marker"); doc->version = 10 * (fz_atof(buf+5) + 0.05f); if (doc->version < 10 || doc->version > 17) if (doc->version != 20) fz_warn(ctx, "unknown PDF version: %d.%d", doc->version / 10, doc->version % 10); }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,397
pdf_load_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) { int i; int xref_len; pdf_xref_entry *entry; pdf_read_start_xref(ctx, doc); pdf_read_xref_sections(ctx, doc, doc->startxref, buf, 1); if (pdf_xref_len(ctx, doc) == 0) fz_throw(ctx, FZ_ERROR_GENERIC, "found xref was empty"); pdf_prime_xref_index(ctx, doc); entry = pdf_get_xref_entry(ctx, doc, 0); /* broken pdfs where first object is missing */ if (!entry->type) { entry->type = 'f'; entry->gen = 65535; entry->num = 0; } /* broken pdfs where first object is not free */ else if (entry->type != 'f') fz_warn(ctx, "first object in xref is not free"); /* broken pdfs where object offsets are out of range */ xref_len = pdf_xref_len(ctx, doc); for (i = 0; i < xref_len; i++) { entry = pdf_get_xref_entry(ctx, doc, i); if (entry->type == 'n') { /* Special case code: "0000000000 * n" means free, * according to some producers (inc Quartz) */ if (entry->ofs == 0) entry->type = 'f'; else if (entry->ofs <= 0 || entry->ofs >= doc->file_size) fz_throw(ctx, FZ_ERROR_GENERIC, "object offset out of range: %d (%d 0 R)", (int)entry->ofs, i); } if (entry->type == 'o') { /* Read this into a local variable here, because pdf_get_xref_entry * may solidify the xref, hence invalidating "entry", meaning we * need a stashed value for the throw. */ int64_t ofs = entry->ofs; if (ofs <= 0 || ofs >= xref_len || pdf_get_xref_entry(ctx, doc, ofs)->type != 'n') fz_throw(ctx, FZ_ERROR_GENERIC, "invalid reference to an objstm that does not exist: %d (%d 0 R)", (int)ofs, i); } } }
Exec Code Overflow
0
pdf_load_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) { int i; int xref_len; pdf_xref_entry *entry; pdf_read_start_xref(ctx, doc); pdf_read_xref_sections(ctx, doc, doc->startxref, buf, 1); if (pdf_xref_len(ctx, doc) == 0) fz_throw(ctx, FZ_ERROR_GENERIC, "found xref was empty"); pdf_prime_xref_index(ctx, doc); entry = pdf_get_xref_entry(ctx, doc, 0); /* broken pdfs where first object is missing */ if (!entry->type) { entry->type = 'f'; entry->gen = 65535; entry->num = 0; } /* broken pdfs where first object is not free */ else if (entry->type != 'f') fz_warn(ctx, "first object in xref is not free"); /* broken pdfs where object offsets are out of range */ xref_len = pdf_xref_len(ctx, doc); for (i = 0; i < xref_len; i++) { entry = pdf_get_xref_entry(ctx, doc, i); if (entry->type == 'n') { /* Special case code: "0000000000 * n" means free, * according to some producers (inc Quartz) */ if (entry->ofs == 0) entry->type = 'f'; else if (entry->ofs <= 0 || entry->ofs >= doc->file_size) fz_throw(ctx, FZ_ERROR_GENERIC, "object offset out of range: %d (%d 0 R)", (int)entry->ofs, i); } if (entry->type == 'o') { /* Read this into a local variable here, because pdf_get_xref_entry * may solidify the xref, hence invalidating "entry", meaning we * need a stashed value for the throw. */ int64_t ofs = entry->ofs; if (ofs <= 0 || ofs >= xref_len || pdf_get_xref_entry(ctx, doc, ofs)->type != 'n') fz_throw(ctx, FZ_ERROR_GENERIC, "invalid reference to an objstm that does not exist: %d (%d 0 R)", (int)ofs, i); } } }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,398
static void pdf_populate_next_xref_level(fz_context *ctx, pdf_document *doc) { pdf_xref *xref; doc->xref_sections = fz_resize_array(ctx, doc->xref_sections, doc->num_xref_sections + 1, sizeof(pdf_xref)); doc->num_xref_sections++; xref = &doc->xref_sections[doc->num_xref_sections - 1]; xref->subsec = NULL; xref->num_objects = 0; xref->trailer = NULL; xref->pre_repair_trailer = NULL; xref->unsaved_sigs = NULL; xref->unsaved_sigs_end = NULL; }
Exec Code Overflow
0
static void pdf_populate_next_xref_level(fz_context *ctx, pdf_document *doc) { pdf_xref *xref; doc->xref_sections = fz_resize_array(ctx, doc->xref_sections, doc->num_xref_sections + 1, sizeof(pdf_xref)); doc->num_xref_sections++; xref = &doc->xref_sections[doc->num_xref_sections - 1]; xref->subsec = NULL; xref->num_objects = 0; xref->trailer = NULL; xref->pre_repair_trailer = NULL; xref->unsaved_sigs = NULL; xref->unsaved_sigs_end = NULL; }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null
13,399
pdf_read_new_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) { fz_stream *stm = NULL; pdf_obj *trailer = NULL; pdf_obj *index = NULL; pdf_obj *obj = NULL; int gen, num = 0; int64_t ofs, stm_ofs; int size, w0, w1, w2; int t; fz_var(trailer); fz_var(stm); fz_try(ctx) { ofs = fz_tell(ctx, doc->file); trailer = pdf_parse_ind_obj(ctx, doc, doc->file, buf, &num, &gen, &stm_ofs, NULL); } fz_catch(ctx) { pdf_drop_obj(ctx, trailer); fz_rethrow(ctx); } fz_try(ctx) { pdf_xref_entry *entry; obj = pdf_dict_get(ctx, trailer, PDF_NAME_Size); if (!obj) fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream missing Size entry (%d 0 R)", num); size = pdf_to_int(ctx, obj); obj = pdf_dict_get(ctx, trailer, PDF_NAME_W); if (!obj) fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream missing W entry (%d R)", num); w0 = pdf_to_int(ctx, pdf_array_get(ctx, obj, 0)); w1 = pdf_to_int(ctx, pdf_array_get(ctx, obj, 1)); w2 = pdf_to_int(ctx, pdf_array_get(ctx, obj, 2)); if (w0 < 0) fz_warn(ctx, "xref stream objects have corrupt type"); if (w1 < 0) fz_warn(ctx, "xref stream objects have corrupt offset"); if (w2 < 0) fz_warn(ctx, "xref stream objects have corrupt generation"); w0 = w0 < 0 ? 0 : w0; w1 = w1 < 0 ? 0 : w1; w2 = w2 < 0 ? 0 : w2; index = pdf_dict_get(ctx, trailer, PDF_NAME_Index); stm = pdf_open_stream_with_offset(ctx, doc, num, trailer, stm_ofs); if (!index) { pdf_read_new_xref_section(ctx, doc, stm, 0, size, w0, w1, w2); } else { int n = pdf_array_len(ctx, index); for (t = 0; t < n; t += 2) { int i0 = pdf_to_int(ctx, pdf_array_get(ctx, index, t + 0)); int i1 = pdf_to_int(ctx, pdf_array_get(ctx, index, t + 1)); pdf_read_new_xref_section(ctx, doc, stm, i0, i1, w0, w1, w2); } } entry = pdf_get_populating_xref_entry(ctx, doc, num); entry->ofs = ofs; entry->gen = gen; entry->num = num; entry->stm_ofs = stm_ofs; pdf_drop_obj(ctx, entry->obj); entry->obj = pdf_keep_obj(ctx, trailer); entry->type = 'n'; } fz_always(ctx) { fz_drop_stream(ctx, stm); } fz_catch(ctx) { pdf_drop_obj(ctx, trailer); fz_rethrow(ctx); } return trailer; }
Exec Code Overflow
0
pdf_read_new_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) { fz_stream *stm = NULL; pdf_obj *trailer = NULL; pdf_obj *index = NULL; pdf_obj *obj = NULL; int gen, num = 0; int64_t ofs, stm_ofs; int size, w0, w1, w2; int t; fz_var(trailer); fz_var(stm); fz_try(ctx) { ofs = fz_tell(ctx, doc->file); trailer = pdf_parse_ind_obj(ctx, doc, doc->file, buf, &num, &gen, &stm_ofs, NULL); } fz_catch(ctx) { pdf_drop_obj(ctx, trailer); fz_rethrow(ctx); } fz_try(ctx) { pdf_xref_entry *entry; obj = pdf_dict_get(ctx, trailer, PDF_NAME_Size); if (!obj) fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream missing Size entry (%d 0 R)", num); size = pdf_to_int(ctx, obj); obj = pdf_dict_get(ctx, trailer, PDF_NAME_W); if (!obj) fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream missing W entry (%d R)", num); w0 = pdf_to_int(ctx, pdf_array_get(ctx, obj, 0)); w1 = pdf_to_int(ctx, pdf_array_get(ctx, obj, 1)); w2 = pdf_to_int(ctx, pdf_array_get(ctx, obj, 2)); if (w0 < 0) fz_warn(ctx, "xref stream objects have corrupt type"); if (w1 < 0) fz_warn(ctx, "xref stream objects have corrupt offset"); if (w2 < 0) fz_warn(ctx, "xref stream objects have corrupt generation"); w0 = w0 < 0 ? 0 : w0; w1 = w1 < 0 ? 0 : w1; w2 = w2 < 0 ? 0 : w2; index = pdf_dict_get(ctx, trailer, PDF_NAME_Index); stm = pdf_open_stream_with_offset(ctx, doc, num, trailer, stm_ofs); if (!index) { pdf_read_new_xref_section(ctx, doc, stm, 0, size, w0, w1, w2); } else { int n = pdf_array_len(ctx, index); for (t = 0; t < n; t += 2) { int i0 = pdf_to_int(ctx, pdf_array_get(ctx, index, t + 0)); int i1 = pdf_to_int(ctx, pdf_array_get(ctx, index, t + 1)); pdf_read_new_xref_section(ctx, doc, stm, i0, i1, w0, w1, w2); } } entry = pdf_get_populating_xref_entry(ctx, doc, num); entry->ofs = ofs; entry->gen = gen; entry->num = num; entry->stm_ofs = stm_ofs; pdf_drop_obj(ctx, entry->obj); entry->obj = pdf_keep_obj(ctx, trailer); entry->type = 'n'; } fz_always(ctx) { fz_drop_stream(ctx, stm); } fz_catch(ctx) { pdf_drop_obj(ctx, trailer); fz_rethrow(ctx); } return trailer; }
@@ -868,11 +868,12 @@ pdf_read_old_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) fz_seek(ctx, file, -(2 + (int)strlen(s)), SEEK_CUR); } - if (ofs < 0) - fz_throw(ctx, FZ_ERROR_GENERIC, "out of range object num in xref: %d", (int)ofs); - if (ofs > INT64_MAX - len) - fz_throw(ctx, FZ_ERROR_GENERIC, "xref section object numbers too big"); - + if (ofs < 0 || ofs > PDF_MAX_OBJECT_NUMBER + || len < 0 || len > PDF_MAX_OBJECT_NUMBER + || ofs + len - 1 > PDF_MAX_OBJECT_NUMBER) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); + } /* broken pdfs where size in trailer undershoots entries in xref sections */ if (ofs + len > xref_len) { @@ -933,10 +934,8 @@ pdf_read_new_xref_section(fz_context *ctx, pdf_document *doc, fz_stream *stm, in pdf_xref_entry *table; int i, n; - if (i0 < 0 || i1 < 0 || i0 > INT_MAX - i1) - fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream entry index"); - //if (i0 + i1 > pdf_xref_len(ctx, doc)) - // fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream has too many entries"); + if (i0 < 0 || i0 > PDF_MAX_OBJECT_NUMBER || i1 < 0 || i1 > PDF_MAX_OBJECT_NUMBER || i0 + i1 - 1 > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "xref subsection object numbers are out of range"); table = pdf_xref_find_subsection(ctx, doc, i0, i1); for (i = i0; i < i0 + i1; i++) @@ -2086,6 +2085,10 @@ pdf_create_object(fz_context *ctx, pdf_document *doc) /* TODO: reuse free object slots by properly linking free object chains in the ofs field */ pdf_xref_entry *entry; int num = pdf_xref_len(ctx, doc); + + if (num > PDF_MAX_OBJECT_NUMBER) + fz_throw(ctx, FZ_ERROR_GENERIC, "too many objects stored in pdf"); + entry = pdf_get_incremental_xref_entry(ctx, doc, num); entry->type = 'f'; entry->ofs = -1;
CWE-119
null
null