project
stringclasses
633 values
commit_id
stringlengths
7
81
target
int64
0
1
func
stringlengths
5
484k
cwe
stringclasses
131 values
big_vul_idx
float64
0
189k
idx
int64
0
522k
hash
stringlengths
34
39
size
float64
1
24k
message
stringlengths
0
11.5k
dataset
stringclasses
1 value
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
pam_conf_strnchr(char *sp, int c, intptr_t count) { while (count) { if (*sp == (char)c) return ((char *)sp); else { sp++; count--; } }; return (NULL); }
CWE-120
null
516,894
133488930156996075054650925118924869266
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
free_env(env_list *pam_env) { if (pam_env) { if (pam_env->name) free(pam_env->name); if (pam_env->value) free(pam_env->value); free(pam_env); } }
CWE-120
null
516,895
264325521445242598056721193706657130813
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
__pam_display_msg(pam_handle_t *pamh, int msg_style, int num_msg, char messages[PAM_MAX_NUM_MSG][PAM_MAX_MSG_SIZE], void *conv_apdp) { struct pam_response *ret_respp = NULL; int ret; ret = do_conv(pamh, msg_style, num_msg, messages, conv_apdp, &ret_respp); if (ret_respp != NULL) free_resp(num_msg, ret_respp); return (ret); }
CWE-120
null
516,896
123401369493495539318373301380310674513
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
pam_get_data(const pam_handle_t *pamh, const char *module_data_name, const void **data) { struct pam_module_data *psd; if (pamh == NULL || (pamh->pam_inmodule != WO_OK) || module_data_name == NULL) { pam_trace(PAM_DEBUG_DATA, "pam_get_data(%p:%s:%d)=%p", (void *)pamh, module_data_name ? module_data_name : "NULL", pamh->pam_inmodule, *data); return (PAM_SYSTEM_ERR); } for (psd = pamh->ssd; psd; psd = psd->next) { if (strcmp(psd->module_data_name, module_data_name) == 0) { *data = psd->data; pam_trace(PAM_DEBUG_DATA, "pam_get_data(%p:%s)=%p", (void *)pamh, module_data_name, *data); return (PAM_SUCCESS); } } pam_trace(PAM_DEBUG_DATA, "pam_get_data(%p:%s)=%s", (void *)pamh, module_data_name, "PAM_NO_MODULE_DATA"); return (PAM_NO_MODULE_DATA); }
CWE-120
null
516,897
268535636633002720267921045515980908667
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
read_pam_conf(pam_handle_t *pamh, char *config) { struct pam_fh *pam_fh; pamtab_t *pamentp; pamtab_t *tpament; char *service; int error; int i = pamh->include_depth; /* include depth */ /* * service types: * error (-1), "auth" (0), "account" (1), "session" (2), "password" (3) */ int service_found[PAM_NUM_MODULE_TYPES+1] = {0, 0, 0, 0, 0}; (void) pam_get_item(pamh, PAM_SERVICE, (void **)&service); if (service == NULL || *service == '\0') { __pam_log(LOG_AUTH | LOG_ERR, "No service name"); return (PAM_SYSTEM_ERR); } pamh->pam_conf_name[i] = strdup(config); pam_trace(PAM_DEBUG_CONF, "read_pam_conf[%d:%s](%p) open(%s)", i, pam_trace_cname(pamh), (void *)pamh, config); if (open_pam_conf(&pam_fh, pamh, config) == 0) { return (PAM_SYSTEM_ERR); } while ((error = get_pam_conf_entry(pam_fh, pamh, &pamentp)) == PAM_SUCCESS && pamentp) { /* See if entry is this service and valid */ if (verify_pam_conf(pamentp, service)) { pam_trace(PAM_DEBUG_CONF, "read_pam_conf[%d:%s](%p): bad entry error %s", i, pam_trace_cname(pamh), (void *)pamh, service); error = PAM_SYSTEM_ERR; free_pamconf(pamentp); goto out; } if (strcasecmp(pamentp->pam_service, service) == 0) { pam_trace(PAM_DEBUG_CONF, "read_pam_conf[%d:%s](%p): processing %s", i, pam_trace_cname(pamh), (void *)pamh, service); /* process first service entry */ if (service_found[pamentp->pam_type + 1] == 0) { /* purge "other" entries */ while ((tpament = pamh->pam_conf_info[i] [pamentp->pam_type]) != NULL) { pam_trace(PAM_DEBUG_CONF, "read_pam_conf(%p): purging " "\"other\"[%d:%s][%s]", (void *)pamh, i, pam_trace_cname(pamh), pam_snames[pamentp->pam_type]); pamh->pam_conf_info[i] [pamentp->pam_type] = tpament->next; free_pamconf(tpament); } /* add first service entry */ pam_trace(PAM_DEBUG_CONF, "read_pam_conf(%p): adding 1st " "%s[%d:%s][%s]", (void *)pamh, service, i, pam_trace_cname(pamh), pam_snames[pamentp->pam_type]); pamh->pam_conf_info[i][pamentp->pam_type] = pamentp; service_found[pamentp->pam_type + 1] = 1; } else { /* append more service entries */ pam_trace(PAM_DEBUG_CONF, "read_pam_conf(%p): adding more " "%s[%d:%s][%s]", (void *)pamh, service, i, pam_trace_cname(pamh), pam_snames[pamentp->pam_type]); tpament = pamh->pam_conf_info[i][pamentp->pam_type]; while (tpament->next != NULL) { tpament = tpament->next; } tpament->next = pamentp; } } else if (service_found[pamentp->pam_type + 1] == 0) { /* See if "other" entry available and valid */ if (verify_pam_conf(pamentp, "other")) { pam_trace(PAM_DEBUG_CONF, "read_pam_conf(%p): bad entry error %s " "\"other\"[%d:%s]", (void *)pamh, service, i, pam_trace_cname(pamh)); error = PAM_SYSTEM_ERR; free_pamconf(pamentp); goto out; } if (strcasecmp(pamentp->pam_service, "other") == 0) { pam_trace(PAM_DEBUG_CONF, "read_pam_conf(%p): processing " "\"other\"[%d:%s]", (void *)pamh, i, pam_trace_cname(pamh)); if ((tpament = pamh->pam_conf_info[i] [pamentp->pam_type]) == NULL) { /* add first "other" entry */ pam_trace(PAM_DEBUG_CONF, "read_pam_conf(%p): adding 1st " "other[%d:%s][%s]", (void *)pamh, i, pam_trace_cname(pamh), pam_snames[pamentp->pam_type]); pamh->pam_conf_info[i] [pamentp->pam_type] = pamentp; } else { /* append more "other" entries */ pam_trace(PAM_DEBUG_CONF, "read_pam_conf(%p): adding more " "other[%d:%s][%s]", (void *)pamh, i, pam_trace_cname(pamh), pam_snames[pamentp->pam_type]); while (tpament->next != NULL) { tpament = tpament->next; } tpament->next = pamentp; } } else { /* irrelevant entry */ free_pamconf(pamentp); } } else { /* irrelevant entry */ free_pamconf(pamentp); } } out: (void) close_pam_conf(pam_fh); if (error != PAM_SUCCESS) free_pam_conf_info(pamh); return (error); }
CWE-120
null
516,898
159860691484063931403172023682969494761
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
pam_start(const char *service, const char *user, const struct pam_conv *pam_conv, pam_handle_t **pamh) { int err; *pamh = calloc(1, sizeof (struct pam_handle)); pam_settrace(); pam_trace(PAM_DEBUG_DEFAULT, "pam_start(%s,%s,%p:%p) - debug = %x", service ? service : "NULL", user ? user : "NULL", (void *)pam_conv, (void *)*pamh, pam_debug); if (*pamh == NULL) return (PAM_BUF_ERR); (*pamh)->pam_inmodule = RO_OK; /* OK to set RO items */ if ((err = pam_set_item(*pamh, PAM_SERVICE, (void *)service)) != PAM_SUCCESS) { clean_up(*pamh); *pamh = NULL; return (err); } if ((err = pam_set_item(*pamh, PAM_USER, (void *)user)) != PAM_SUCCESS) { clean_up(*pamh); *pamh = NULL; return (err); } if ((err = pam_set_item(*pamh, PAM_CONV, (void *)pam_conv)) != PAM_SUCCESS) { clean_up(*pamh); *pamh = NULL; return (err); } (*pamh)->pam_inmodule = RW_OK; return (PAM_SUCCESS); }
CWE-120
null
516,899
65403438831766642312621739191769134622
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
pam_settrace() { void *defp; if ((defp = defopen_r(PAM_DEBUG)) != NULL) { char *arg; int code; int facility = LOG_AUTH; pam_debug = PAM_DEBUG_DEFAULT; log_priority = LOG_DEBUG; (void) defcntl_r(DC_SETFLAGS, DC_CASE, defp); if ((arg = defread_r(LOG_PRIORITY, defp)) != NULL) { code = (int)strtol(arg, NULL, 10); if ((code & ~LOG_PRIMASK) == 0) { log_priority = code; } } if ((arg = defread_r(LOG_FACILITY, defp)) != NULL) { code = (int)strtol(arg, NULL, 10); if (code < LOG_NFACILITIES) { facility = code << 3; } } if ((arg = defread_r(DEBUG_FLAGS, defp)) != NULL) { pam_debug = (int)strtol(arg, NULL, 0); } defclose_r(defp); log_priority |= facility; } }
CWE-120
null
516,900
93997367122845607810686998540541388222
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
(*func(pamtab_t *modulep, int ind))() { void *funcp; if ((funcp = modulep->function_ptr) == NULL) return (NULL); switch (ind) { case PAM_AUTHENTICATE: return (((struct auth_module *)funcp)->pam_sm_authenticate); case PAM_SETCRED: return (((struct auth_module *)funcp)->pam_sm_setcred); case PAM_ACCT_MGMT: return (((struct account_module *)funcp)->pam_sm_acct_mgmt); case PAM_OPEN_SESSION: return (((struct session_module *)funcp)->pam_sm_open_session); case PAM_CLOSE_SESSION: return (((struct session_module *)funcp)->pam_sm_close_session); case PAM_CHAUTHTOK: return (((struct password_module *)funcp)->pam_sm_chauthtok); } return (NULL); }
CWE-120
null
516,901
92548181948561497417503806607636520089
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
parse_user_name(char *user_input, char **ret_username) { register char *ptr; register int index = 0; char username[PAM_MAX_RESP_SIZE]; /* Set the default value for *ret_username */ *ret_username = NULL; /* * Set the initial value for username - this is a buffer holds * the user name. */ bzero((void *)username, PAM_MAX_RESP_SIZE); /* * The user_input is guaranteed to be terminated by a null character. */ ptr = user_input; /* Skip all the leading whitespaces if there are any. */ while ((*ptr == ' ') || (*ptr == '\t')) ptr++; if (*ptr == '\0') { /* * We should never get here since the user_input we got * in pam_get_user() is not all whitespaces nor just "\0". */ return (PAM_BUF_ERR); } /* * username will be the first string we get from user_input * - we skip leading whitespaces and ignore trailing whitespaces */ while (*ptr != '\0') { if ((*ptr == ' ') || (*ptr == '\t') || (index >= PAM_MAX_RESP_SIZE)) { break; } else { username[index] = *ptr; index++; ptr++; } } /* ret_username will be freed in pam_get_user(). */ if (index >= PAM_MAX_RESP_SIZE || (*ret_username = strdup(username)) == NULL) return (PAM_BUF_ERR); return (PAM_SUCCESS); }
CWE-120
null
516,902
24919518180499948984963995718864185618
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
pam_acct_mgmt(pam_handle_t *pamh, int flags) { int retval; retval = run_stack(pamh, flags, PAM_ACCOUNT_MODULE, PAM_ACCT_EXPIRED, PAM_ACCT_MGMT, "pam_acct_mgmt"); if (retval != PAM_SUCCESS && retval != PAM_NEW_AUTHTOK_REQD) { (void) pam_set_item(pamh, PAM_AUTHTOK, NULL); } return (retval); }
CWE-120
null
516,903
282435188224798696863156731658817344444
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
verify_pam_conf(pamtab_t *pam, char *service) { return ((pam->pam_service == (char *)NULL) || ((strcasecmp(pam->pam_service, service) == 0) && ((pam->pam_type == -1) || (pam->pam_flag == 0) || (pam->pam_err != PAM_SUCCESS) || (pam->module_path == (char *)NULL)))); }
CWE-120
null
516,904
124604916877037639789259781047628789679
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
load_modules(pam_handle_t *pamh, int type, char *function_name, pamtab_t *pam_entry) { void *mh; struct auth_module *authp; struct account_module *accountp; struct session_module *sessionp; struct password_module *passwdp; int loading_functions = 0; /* are we currently loading functions? */ pam_trace(PAM_DEBUG_MODULE, "load_modules[%d:%s](%p, %s)=%s:%s", pamh->include_depth, pam_trace_cname(pamh), (void *)pamh, function_name, pam_trace_fname(pam_entry->pam_flag), pam_entry->module_path); while (pam_entry != NULL) { pam_trace(PAM_DEBUG_DEFAULT, "while load_modules[%d:%s](%p, %s)=%s", pamh->include_depth, pam_trace_cname(pamh), (void *)pamh, function_name, pam_entry->module_path); if (pam_entry->pam_flag & PAM_INCLUDE) { pam_trace(PAM_DEBUG_DEFAULT, "done load_modules[%d:%s](%p, %s)=%s", pamh->include_depth, pam_trace_cname(pamh), (void *)pamh, function_name, pam_entry->module_path); return (PAM_SUCCESS); } switch (type) { case PAM_AUTH_MODULE: /* if the function has already been loaded, return */ authp = pam_entry->function_ptr; if (!loading_functions && (((strcmp(function_name, PAM_SM_AUTHENTICATE) == 0) && authp && authp->pam_sm_authenticate) || ((strcmp(function_name, PAM_SM_SETCRED) == 0) && authp && authp->pam_sm_setcred))) { return (PAM_SUCCESS); } /* function has not been loaded yet */ loading_functions = 1; if (authp == NULL) { authp = calloc(1, sizeof (struct auth_module)); if (authp == NULL) return (PAM_BUF_ERR); } /* if open_module fails, return error */ if ((mh = open_module(pamh, pam_entry->module_path)) == NULL) { __pam_log(LOG_AUTH | LOG_ERR, "load_modules[%d:%s]: can not open module " "%s", pamh->include_depth, pam_trace_cname(pamh), pam_entry->module_path); free(authp); return (PAM_OPEN_ERR); } /* load the authentication function */ if (strcmp(function_name, PAM_SM_AUTHENTICATE) == 0) { if (load_function(mh, PAM_SM_AUTHENTICATE, &authp->pam_sm_authenticate) != PAM_SUCCESS) { /* return error if dlsym fails */ free(authp); return (PAM_SYMBOL_ERR); } /* load the setcred function */ } else if (strcmp(function_name, PAM_SM_SETCRED) == 0) { if (load_function(mh, PAM_SM_SETCRED, &authp->pam_sm_setcred) != PAM_SUCCESS) { /* return error if dlsym fails */ free(authp); return (PAM_SYMBOL_ERR); } } pam_entry->function_ptr = authp; break; case PAM_ACCOUNT_MODULE: accountp = pam_entry->function_ptr; if (!loading_functions && (strcmp(function_name, PAM_SM_ACCT_MGMT) == 0) && accountp && accountp->pam_sm_acct_mgmt) { return (PAM_SUCCESS); } /* * If functions are added to the account module, * verify that one of the other functions hasn't * already loaded it. See PAM_AUTH_MODULE code. */ loading_functions = 1; accountp = calloc(1, sizeof (struct account_module)); if (accountp == NULL) return (PAM_BUF_ERR); /* if open_module fails, return error */ if ((mh = open_module(pamh, pam_entry->module_path)) == NULL) { __pam_log(LOG_AUTH | LOG_ERR, "load_modules[%d:%s]: can not open module " "%s", pamh->include_depth, pam_trace_cname(pamh), pam_entry->module_path); free(accountp); return (PAM_OPEN_ERR); } if (load_function(mh, PAM_SM_ACCT_MGMT, &accountp->pam_sm_acct_mgmt) != PAM_SUCCESS) { __pam_log(LOG_AUTH | LOG_ERR, "load_modules[%d:%s]: pam_sm_acct_mgmt() " "missing", pamh->include_depth, pam_trace_cname(pamh)); free(accountp); return (PAM_SYMBOL_ERR); } pam_entry->function_ptr = accountp; break; case PAM_SESSION_MODULE: sessionp = pam_entry->function_ptr; if (!loading_functions && (((strcmp(function_name, PAM_SM_OPEN_SESSION) == 0) && sessionp && sessionp->pam_sm_open_session) || ((strcmp(function_name, PAM_SM_CLOSE_SESSION) == 0) && sessionp && sessionp->pam_sm_close_session))) { return (PAM_SUCCESS); } loading_functions = 1; if (sessionp == NULL) { sessionp = calloc(1, sizeof (struct session_module)); if (sessionp == NULL) return (PAM_BUF_ERR); } /* if open_module fails, return error */ if ((mh = open_module(pamh, pam_entry->module_path)) == NULL) { __pam_log(LOG_AUTH | LOG_ERR, "load_modules[%d:%s]: can not open module " "%s", pamh->include_depth, pam_trace_cname(pamh), pam_entry->module_path); free(sessionp); return (PAM_OPEN_ERR); } if ((strcmp(function_name, PAM_SM_OPEN_SESSION) == 0) && load_function(mh, PAM_SM_OPEN_SESSION, &sessionp->pam_sm_open_session) != PAM_SUCCESS) { free(sessionp); return (PAM_SYMBOL_ERR); } else if ((strcmp(function_name, PAM_SM_CLOSE_SESSION) == 0) && load_function(mh, PAM_SM_CLOSE_SESSION, &sessionp->pam_sm_close_session) != PAM_SUCCESS) { free(sessionp); return (PAM_SYMBOL_ERR); } pam_entry->function_ptr = sessionp; break; case PAM_PASSWORD_MODULE: passwdp = pam_entry->function_ptr; if (!loading_functions && (strcmp(function_name, PAM_SM_CHAUTHTOK) == 0) && passwdp && passwdp->pam_sm_chauthtok) { return (PAM_SUCCESS); } /* * If functions are added to the password module, * verify that one of the other functions hasn't * already loaded it. See PAM_AUTH_MODULE code. */ loading_functions = 1; passwdp = calloc(1, sizeof (struct password_module)); if (passwdp == NULL) return (PAM_BUF_ERR); /* if open_module fails, continue */ if ((mh = open_module(pamh, pam_entry->module_path)) == NULL) { __pam_log(LOG_AUTH | LOG_ERR, "load_modules[%d:%s]: can not open module " "%s", pamh->include_depth, pam_trace_cname(pamh), pam_entry->module_path); free(passwdp); return (PAM_OPEN_ERR); } if (load_function(mh, PAM_SM_CHAUTHTOK, &passwdp->pam_sm_chauthtok) != PAM_SUCCESS) { free(passwdp); return (PAM_SYMBOL_ERR); } pam_entry->function_ptr = passwdp; break; default: pam_trace(PAM_DEBUG_DEFAULT, "load_modules[%d:%s](%p, %s): unsupported type %d", pamh->include_depth, pam_trace_cname(pamh), (void *)pamh, function_name, type); break; } pam_entry = pam_entry->next; } /* while */ pam_trace(PAM_DEBUG_MODULE, "load_modules[%d:%s](%p, %s)=done", pamh->include_depth, pam_trace_cname(pamh), (void *)pamh, function_name); return (PAM_SUCCESS); }
CWE-120
null
516,905
299237372030835770675673548602868081972
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
pam_chauthtok(pam_handle_t *pamh, int flags) { int retval; /* do not let apps use PAM_PRELIM_CHECK or PAM_UPDATE_AUTHTOK */ if (flags & (PAM_PRELIM_CHECK | PAM_UPDATE_AUTHTOK)) { pam_trace(PAM_DEBUG_DEFAULT, "pam_chauthtok(%p, %x): %s", (void *)pamh, flags, pam_strerror(pamh, PAM_SYMBOL_ERR)); return (PAM_SYMBOL_ERR); } /* 1st pass: PRELIM CHECK */ retval = run_stack(pamh, flags | PAM_PRELIM_CHECK, PAM_PASSWORD_MODULE, PAM_AUTHTOK_ERR, PAM_CHAUTHTOK, "pam_chauthtok-prelim"); if (retval == PAM_TRY_AGAIN) return (retval); if (retval != PAM_SUCCESS) { (void) pam_set_item(pamh, PAM_AUTHTOK, NULL); return (retval); } /* 2nd pass: UPDATE AUTHTOK */ retval = run_stack(pamh, flags | PAM_UPDATE_AUTHTOK, PAM_PASSWORD_MODULE, PAM_AUTHTOK_ERR, PAM_CHAUTHTOK, "pam_chauthtok-update"); if (retval != PAM_SUCCESS) (void) pam_set_item(pamh, PAM_AUTHTOK, NULL); return (retval); }
CWE-120
null
516,906
294366604834182914102793423908722410535
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
pam_get_user(pam_handle_t *pamh, char **user, const char *prompt_override) { int status; char *prompt = NULL; char *real_username; struct pam_response *ret_resp = NULL; char messages[PAM_MAX_NUM_MSG][PAM_MAX_MSG_SIZE]; pam_trace(PAM_DEBUG_DEFAULT, "pam_get_user(%p, %p, %s)", (void *)pamh, (void *)*user, prompt_override ? prompt_override : "NULL"); if (pamh == NULL) return (PAM_SYSTEM_ERR); if ((status = pam_get_item(pamh, PAM_USER, (void **)user)) != PAM_SUCCESS) { return (status); } /* if the user is set, return it */ if (*user != NULL && *user[0] != '\0') { return (PAM_SUCCESS); } /* * if the module is requesting a special prompt, use it. * else use PAM_USER_PROMPT. */ if (prompt_override != NULL) { prompt = (char *)prompt_override; } else { status = pam_get_item(pamh, PAM_USER_PROMPT, (void**)&prompt); if (status != PAM_SUCCESS) { return (status); } } /* if the prompt is not set, use default */ if (prompt == NULL || prompt[0] == '\0') { prompt = dgettext(TEXT_DOMAIN, "Please enter user name: "); } /* prompt for the user */ (void) strncpy(messages[0], prompt, sizeof (messages[0])); for (;;) { int state = WHITESPACE; status = do_conv(pamh, PAM_PROMPT_ECHO_ON, 1, messages, NULL, &ret_resp); if (status != PAM_SUCCESS) { return (status); } if (ret_resp->resp && ret_resp->resp[0] != '\0') { int len = strlen(ret_resp->resp); int i; for (i = 0; i < len; i++) { if ((ret_resp->resp[i] != ' ') && (ret_resp->resp[i] != '\t')) { state = USERNAME; break; } } if (state == USERNAME) break; } /* essentially empty response, try again */ free_resp(1, ret_resp); ret_resp = NULL; } /* set PAM_USER */ /* Parse the user input to get the user name. */ status = parse_user_name(ret_resp->resp, &real_username); if (status != PAM_SUCCESS) { if (real_username != NULL) free(real_username); free_resp(1, ret_resp); return (status); } status = pam_set_item(pamh, PAM_USER, real_username); free(real_username); free_resp(1, ret_resp); if (status != PAM_SUCCESS) { return (status); } /* * finally, get PAM_USER. We have to call pam_get_item to get * the value of user because pam_set_item mallocs the memory. */ status = pam_get_item(pamh, PAM_USER, (void**)user); return (status); }
CWE-120
null
516,907
44808901514672199476936248173865708820
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
pam_close_session(pam_handle_t *pamh, int flags) { int retval; retval = run_stack(pamh, flags, PAM_SESSION_MODULE, PAM_SESSION_ERR, PAM_CLOSE_SESSION, "pam_close_session"); if (retval != PAM_SUCCESS) (void) pam_set_item(pamh, PAM_AUTHTOK, NULL); return (retval); }
CWE-120
null
516,908
201235999279960207612220811313965208288
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
pam_set_item(pam_handle_t *pamh, int item_type, const void *item) { struct pam_item *pip; int size; char iname_buf[PAM_MAX_MSG_SIZE]; if (((pam_debug & PAM_DEBUG_ITEM) == 0) || (pamh == NULL)) { pam_trace(PAM_DEBUG_DEFAULT, "pam_set_item(%p:%s)", (void *)pamh, pam_trace_iname(item_type, iname_buf)); } if (pamh == NULL) return (PAM_SYSTEM_ERR); /* check read only items */ if ((item_type == PAM_SERVICE) && (pamh->pam_inmodule != RO_OK)) return (PAM_PERM_DENIED); /* * Check that item_type is within valid range */ if (item_type <= 0 || item_type >= PAM_MAX_ITEMS) return (PAM_SYMBOL_ERR); pip = &(pamh->ps_item[item_type]); switch (item_type) { case PAM_AUTHTOK: case PAM_OLDAUTHTOK: if (pip->pi_addr != NULL) (void) memset(pip->pi_addr, 0, pip->pi_size); /*FALLTHROUGH*/ case PAM_SERVICE: case PAM_USER: case PAM_TTY: case PAM_RHOST: case PAM_RUSER: case PAM_USER_PROMPT: case PAM_RESOURCE: case PAM_AUSER: if (pip->pi_addr != NULL) { free(pip->pi_addr); } if (item == NULL) { pip->pi_addr = NULL; pip->pi_size = 0; } else { pip->pi_addr = strdup((char *)item); if (pip->pi_addr == NULL) { pip->pi_size = 0; return (PAM_BUF_ERR); } pip->pi_size = strlen(pip->pi_addr); } break; case PAM_CONV: if (pip->pi_addr != NULL) free(pip->pi_addr); size = sizeof (struct pam_conv); if ((pip->pi_addr = calloc(1, size)) == NULL) return (PAM_BUF_ERR); if (item != NULL) (void) memcpy(pip->pi_addr, item, (unsigned int) size); else (void) memset(pip->pi_addr, 0, size); pip->pi_size = size; break; case PAM_REPOSITORY: if (pip->pi_addr != NULL) { pam_repository_t *auth_rep; auth_rep = (pam_repository_t *)pip->pi_addr; if (auth_rep->type != NULL) free(auth_rep->type); if (auth_rep->scope != NULL) free(auth_rep->scope); free(auth_rep); } if (item != NULL) { pam_repository_t *s, *d; size = sizeof (struct pam_repository); pip->pi_addr = calloc(1, size); if (pip->pi_addr == NULL) return (PAM_BUF_ERR); s = (struct pam_repository *)item; d = (struct pam_repository *)pip->pi_addr; d->type = strdup(s->type); if (d->type == NULL) return (PAM_BUF_ERR); d->scope = malloc(s->scope_len); if (d->scope == NULL) return (PAM_BUF_ERR); (void) memcpy(d->scope, s->scope, s->scope_len); d->scope_len = s->scope_len; } pip->pi_size = size; break; default: return (PAM_SYMBOL_ERR); } switch (item_type) { case PAM_CONV: pam_trace(PAM_DEBUG_ITEM, "pam_set_item(%p:%s)=%p", (void *)pamh, pam_trace_iname(item_type, iname_buf), item ? (void *)((struct pam_conv *)item)->conv : (void *)0); break; case PAM_REPOSITORY: pam_trace(PAM_DEBUG_ITEM, "pam_set_item(%p:%s)=%s", (void *)pamh, pam_trace_iname(item_type, iname_buf), item ? (((struct pam_repository *)item)->type ? ((struct pam_repository *)item)->type : "NULL") : "NULL"); break; case PAM_AUTHTOK: case PAM_OLDAUTHTOK: #ifdef DEBUG if (pam_debug & PAM_DEBUG_AUTHTOK) pam_trace(PAM_DEBUG_ITEM, "pam_set_item(%p:%s)=%s", (void *)pamh, pam_trace_iname(item_type, iname_buf), item ? (char *)item : "NULL"); else #endif /* DEBUG */ pam_trace(PAM_DEBUG_ITEM, "pam_set_item(%p:%s)=%s", (void *)pamh, pam_trace_iname(item_type, iname_buf), item ? "********" : "NULL"); break; default: pam_trace(PAM_DEBUG_ITEM, "pam_set_item(%p:%s)=%s", (void *)pamh, pam_trace_iname(item_type, iname_buf), item ? (char *)item : "NULL"); } return (PAM_SUCCESS); }
CWE-120
null
516,909
161336774362369428605149908741245131848
null
null
other
illumos-gate
1d276e0b382cf066dae93640746d8b4c54d15452
0
run_stack(pam_handle_t *pamh, int flags, int type, int def_err, int ind, char *function_name) { int err = PAM_SYSTEM_ERR; /* preset */ int optional_error = 0; int required_error = 0; int success = 0; pamtab_t *modulep; int (*sm_func)(); if (pamh == NULL) return (PAM_SYSTEM_ERR); /* read initial entries from pam.conf */ if ((err = read_pam_conf(pamh, PAM_CONFIG)) != PAM_SUCCESS) { return (err); } if ((modulep = pamh->pam_conf_info[pamh->include_depth][type]) == NULL) { __pam_log(LOG_AUTH | LOG_ERR, "%s no initial module present", pam_trace_cname(pamh)); goto exit_return; } pamh->pam_inmodule = WO_OK; /* OK to get AUTHTOK */ include: pam_trace(PAM_DEBUG_MODULE, "[%d:%s]:run_stack:%s(%p, %x): %s", pamh->include_depth, pam_trace_cname(pamh), function_name, (void *)pamh, flags, modulep ? modulep->module_path : "NULL"); while (modulep != NULL) { if (modulep->pam_flag & PAM_INCLUDE) { /* save the return location */ pamh->pam_conf_modulep[pamh->include_depth] = modulep->next; pam_trace(PAM_DEBUG_MODULE, "setting for include[%d:%p]", pamh->include_depth, (void *)modulep->next); if (pamh->include_depth++ >= PAM_MAX_INCLUDE) { __pam_log(LOG_AUTH | LOG_ERR, "run_stack: includes too deep %d " "found trying to include %s from %s, %d " "allowed", pamh->include_depth, modulep->module_path, pamh->pam_conf_name [PAM_MAX_INCLUDE] == NULL ? "NULL" : pamh->pam_conf_name[PAM_MAX_INCLUDE], PAM_MAX_INCLUDE); goto exit_return; } if ((err = read_pam_conf(pamh, modulep->module_path)) != PAM_SUCCESS) { __pam_log(LOG_AUTH | LOG_ERR, "run_stack[%d:%s]: can't read included " "conf %s", pamh->include_depth, pam_trace_cname(pamh), modulep->module_path); goto exit_return; } if ((modulep = pamh->pam_conf_info [pamh->include_depth][type]) == NULL) { __pam_log(LOG_AUTH | LOG_ERR, "run_stack[%d:%s]: no include module " "present %s", pamh->include_depth, pam_trace_cname(pamh), function_name); goto exit_return; } if (modulep->pam_flag & PAM_INCLUDE) { /* first line another include */ goto include; } pam_trace(PAM_DEBUG_DEFAULT, "include[%d:%s]" "(%p, %s)=%s", pamh->include_depth, pam_trace_cname(pamh), (void *)pamh, function_name, modulep->module_path); if ((err = load_modules(pamh, type, sm_name(ind), pamh->pam_conf_info [pamh->include_depth][type])) != PAM_SUCCESS) { pam_trace(PAM_DEBUG_DEFAULT, "[%d:%s]:%s(%p, %x): load_modules failed", pamh->include_depth, pam_trace_cname(pamh), function_name, (void *)pamh, flags); goto exit_return; } if ((modulep = pamh->pam_conf_info [pamh->include_depth][type]) == NULL) { __pam_log(LOG_AUTH | LOG_ERR, "%s no initial module present", pam_trace_cname(pamh)); goto exit_return; } } else if ((err = load_modules(pamh, type, sm_name(ind), modulep)) != PAM_SUCCESS) { pam_trace(PAM_DEBUG_DEFAULT, "[%d:%s]:%s(%p, %x): load_modules failed", pamh->include_depth, pam_trace_cname(pamh), function_name, (void *)pamh, flags); goto exit_return; } /* PAM_INCLUDE */ sm_func = func(modulep, ind); if (sm_func) { err = sm_func(pamh, flags, modulep->module_argc, (const char **)modulep->module_argv); pam_trace(PAM_DEBUG_MODULE, "[%d:%s]:%s(%p, %x): %s returned %s", pamh->include_depth, pam_trace_cname(pamh), function_name, (void *)pamh, flags, modulep->module_path, pam_strerror(pamh, err)); switch (err) { case PAM_IGNORE: /* do nothing */ break; case PAM_SUCCESS: if ((modulep->pam_flag & PAM_SUFFI_BIND) && !required_error) { pamh->pam_inmodule = RW_OK; pam_trace(PAM_DEBUG_MODULE, "[%d:%s]:%s(%p, %x): %s: success", pamh->include_depth, pam_trace_cname(pamh), function_name, (void *)pamh, flags, (modulep->pam_flag & PAM_BINDING) ? PAM_BINDING_NAME : PAM_SUFFICIENT_NAME); goto exit_return; } success = 1; break; case PAM_TRY_AGAIN: /* * We need to return immediately, and * we shouldn't reset the AUTHTOK item * since it is not an error per-se. */ pamh->pam_inmodule = RW_OK; pam_trace(PAM_DEBUG_MODULE, "[%d:%s]:%s(%p, %x): TRY_AGAIN: %s", pamh->include_depth, pam_trace_cname(pamh), function_name, (void *)pamh, flags, pam_strerror(pamh, required_error ? required_error : err)); err = required_error ? required_error : err; goto exit_return; default: if (modulep->pam_flag & PAM_REQUISITE) { pamh->pam_inmodule = RW_OK; pam_trace(PAM_DEBUG_MODULE, "[%d:%s]:%s(%p, %x): requisite: %s", pamh->include_depth, pam_trace_cname(pamh), function_name, (void *)pamh, flags, pam_strerror(pamh, required_error ? required_error : err)); err = required_error ? required_error : err; goto exit_return; } else if (modulep->pam_flag & PAM_REQRD_BIND) { if (!required_error) required_error = err; } else { if (!optional_error) optional_error = err; } pam_trace(PAM_DEBUG_DEFAULT, "[%d:%s]:%s(%p, %x): error %s", pamh->include_depth, pam_trace_cname(pamh), function_name, (void *)pamh, flags, pam_strerror(pamh, err)); break; } } modulep = modulep->next; } pam_trace(PAM_DEBUG_MODULE, "[%d:%s]:stack_end:%s(%p, %x): %s %s: %s", pamh->include_depth, pam_trace_cname(pamh), function_name, (void *)pamh, flags, pamh->include_depth ? "included" : "final", required_error ? "required" : success ? "success" : optional_error ? "optional" : "default", pam_strerror(pamh, required_error ? required_error : success ? PAM_SUCCESS : optional_error ? optional_error : def_err)); if (pamh->include_depth > 0) { free_pam_conf_info(pamh); pamh->include_depth--; /* continue at next entry */ modulep = pamh->pam_conf_modulep[pamh->include_depth]; pam_trace(PAM_DEBUG_MODULE, "looping for include[%d:%p]", pamh->include_depth, (void *)modulep); goto include; } free_pam_conf_info(pamh); pamh->pam_inmodule = RW_OK; if (required_error != 0) return (required_error); else if (success != 0) return (PAM_SUCCESS); else if (optional_error != 0) return (optional_error); else return (def_err); exit_return: /* * All done at whatever depth we're at. * Go back to not having read /etc/pam.conf */ while (pamh->include_depth > 0) { free_pam_conf_info(pamh); pamh->include_depth--; } free_pam_conf_info(pamh); pamh->pam_inmodule = RW_OK; return (err); }
CWE-120
null
516,910
101778658728391175357215817477565634940
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_iopt_flush_instructions (xd3_stream *stream, int ignore) { int ret, i; usize_t tpos = 0; usize_t delta_size, recon_size; xd3_config config; uint8_t target[TESTBUFSIZE]; uint8_t delta[TESTBUFSIZE]; uint8_t recon[TESTBUFSIZE]; xd3_free_stream (stream); xd3_init_config (& config, 0); config.smatch_cfg = XD3_SMATCH_SOFT; config.smatcher_soft.large_look = 16; config.smatcher_soft.large_step = 16; config.smatcher_soft.small_look = 4; config.smatcher_soft.small_chain = 128; config.smatcher_soft.small_lchain = 16; config.smatcher_soft.max_lazy = 8; config.smatcher_soft.long_enough = 128; if ((ret = xd3_config_stream (stream, & config))) { return ret; } for (i = 1; i < 250; i++) { target[tpos++] = i; target[tpos++] = i+1; target[tpos++] = i+2; target[tpos++] = i+3; target[tpos++] = 0; } for (i = 1; i < 253; i++) { target[tpos++] = i; } if ((ret = xd3_encode_stream (stream, target, tpos, delta, & delta_size, sizeof (delta)))) { return ret; } xd3_free_stream(stream); if ((ret = xd3_config_stream (stream, & config))) { return ret; } if ((ret = xd3_decode_stream (stream, delta, delta_size, recon, & recon_size, sizeof (recon)))) { return ret; } CHECK(tpos == recon_size); CHECK(memcmp(target, recon, recon_size) == 0); return 0; }
CWE-119
null
516,914
45563604304831547235763270554029774745
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_write_output (xd3_stream* stream, main_file *ofile) { int ret; if (option_no_output) { return 0; } if (stream->avail_out > 0 && (ret = main_file_write (ofile, stream->next_out, stream->avail_out, "write failed"))) { return ret; } return 0; }
CWE-119
null
516,915
76996847423930435483656402788872207385
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_file_cleanup (main_file *xfile) { XD3_ASSERT (xfile != NULL); if (main_file_isopen (xfile)) { main_file_close (xfile); } if (xfile->snprintf_buf != NULL) { main_free(xfile->snprintf_buf); xfile->snprintf_buf = NULL; } if (xfile->filename_copy != NULL) { main_free(xfile->filename_copy); xfile->filename_copy = NULL; } }
CWE-119
null
516,916
50699445649277997570155838134578949358
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_help (void) { main_version(); /* Note: update wiki when command-line features change */ XPR(NTR "usage: xdelta3 [command/options] [input [output]]\n"); XPR(NTR "make patch:\n"); XPR(NTR "\n"); XPR(NTR " xdelta3.exe -e -s old_file new_file delta_file\n"); XPR(NTR "\n"); XPR(NTR "apply patch:\n"); XPR(NTR "\n"); XPR(NTR " xdelta3.exe -d -s old_file delta_file decoded_new_file\n"); XPR(NTR "\n"); XPR(NTR "special command names:\n"); XPR(NTR " config prints xdelta3 configuration\n"); XPR(NTR " decode decompress the input\n"); XPR(NTR " encode compress the input%s\n", XD3_ENCODER ? "" : " [Not compiled]"); #if REGRESSION_TEST XPR(NTR " test run the builtin tests\n"); #endif #if VCDIFF_TOOLS XPR(NTR "special commands for VCDIFF inputs:\n"); XPR(NTR " printdelta print information about the entire delta\n"); XPR(NTR " printhdr print information about the first window\n"); XPR(NTR " printhdrs print information about all windows\n"); XPR(NTR " recode encode with new application/secondary settings\n"); XPR(NTR " merge merge VCDIFF inputs (see below)\n"); #endif XPR(NTR "merge patches:\n"); XPR(NTR "\n"); XPR(NTR " xdelta3 merge -m 1.vcdiff -m 2.vcdiff 3.vcdiff merged.vcdiff\n"); XPR(NTR "\n"); XPR(NTR "standard options:\n"); XPR(NTR " -0 .. -9 compression level\n"); XPR(NTR " -c use stdout\n"); XPR(NTR " -d decompress\n"); XPR(NTR " -e compress%s\n", XD3_ENCODER ? "" : " [Not compiled]"); XPR(NTR " -f force (overwrite, ignore trailing garbage)\n"); #if EXTERNAL_COMPRESSION XPR(NTR " -F force the external-compression subprocess\n"); #endif XPR(NTR " -h show help\n"); XPR(NTR " -q be quiet\n"); XPR(NTR " -v be verbose (max 2)\n"); XPR(NTR " -V show version\n"); XPR(NTR "memory options:\n"); XPR(NTR " -B bytes source window size\n"); XPR(NTR " -W bytes input window size\n"); XPR(NTR " -P size compression duplicates window\n"); XPR(NTR " -I size instruction buffer size (0 = unlimited)\n"); XPR(NTR "compression options:\n"); XPR(NTR " -s source source file to copy from (if any)\n"); XPR(NTR " -S [djw|fgk] enable/disable secondary compression\n"); XPR(NTR " -N disable small string-matching compression\n"); XPR(NTR " -D disable external decompression (encode/decode)\n"); XPR(NTR " -R disable external recompression (decode)\n"); XPR(NTR " -n disable checksum (encode/decode)\n"); XPR(NTR " -C soft config (encode, undocumented)\n"); XPR(NTR " -A [apphead] disable/provide application header (encode)\n"); XPR(NTR " -J disable output (check/compute only)\n"); XPR(NTR " -T use alternate code table (test)\n"); XPR(NTR " -m arguments for \"merge\"\n"); XPR(NTR "the XDELTA environment variable may contain extra args:\n"); XPR(NTR " XDELTA=\"-s source-x.y.tar.gz\" \\\n"); XPR(NTR " tar --use-compress-program=xdelta3 \\\n"); XPR(NTR " -cf target-x.z.tar.gz.vcdiff target-x.y\n"); return EXIT_FAILURE; }
CWE-119
null
516,917
241658374624968095055525607583493473846
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_copy_to (const char *from, const char *to) { char buf[TESTBUFSIZE]; int ret; snprintf_func (buf, TESTBUFSIZE, "cp -f %s %s", from, to); if ((ret = system (buf)) != 0) { return XD3_INTERNAL; } return 0; }
CWE-119
null
516,918
53877640528557319302233407883044696302
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_print_vcdiff_file (main_file *xfile, main_file *file, const char *type) { int ret; /* Used by above macros */ if (file->filename) { VC(UT "XDELTA filename (%s): %s\n", type, file->filename)VE; } if (file->compressor) { VC(UT "XDELTA ext comp (%s): %s\n", type, file->compressor->recomp_cmdname)VE; } return 0; }
CWE-119
null
516,919
307970522138139816337652959886944768131
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_recode_command2 (xd3_stream *stream, int has_source, int variant, int change) { int has_adler32 = (variant & 0x1) != 0; int has_apphead = (variant & 0x2) != 0; int has_secondary = (variant & 0x4) != 0; int change_adler32 = (change & 0x1) != 0; int change_apphead = (change & 0x2) != 0; int change_secondary = (change & 0x4) != 0; int recoded_adler32 = change_adler32 ? !has_adler32 : has_adler32; int recoded_apphead = change_apphead ? !has_apphead : has_apphead; int recoded_secondary = change_secondary ? !has_secondary : has_secondary; char ecmd[TESTBUFSIZE], recmd[TESTBUFSIZE], dcmd[TESTBUFSIZE]; xoff_t tsize, ssize; int ret; test_setup (); if ((ret = test_make_inputs (stream, has_source ? & ssize : NULL, & tsize))) { return ret; } /* First encode */ snprintf_func (ecmd, TESTBUFSIZE, "%s %s -f %s %s %s %s %s %s %s", program_name, test_softcfg_str, has_adler32 ? "" : "-n ", has_apphead ? "-A=encode_apphead " : "-A= ", has_secondary ? "-S djw " : "-S none ", has_source ? "-s " : "", has_source ? TEST_SOURCE_FILE : "", TEST_TARGET_FILE, TEST_DELTA_FILE); if ((ret = system (ecmd)) != 0) { XPR(NT "encode command: %s\n", ecmd); stream->msg = "encode cmd failed"; return XD3_INTERNAL; } /* Now recode */ snprintf_func (recmd, TESTBUFSIZE, "%s recode %s -f %s %s %s %s %s", program_name, test_softcfg_str, recoded_adler32 ? "" : "-n ", !change_apphead ? "" : (recoded_apphead ? "-A=recode_apphead " : "-A= "), recoded_secondary ? "-S djw " : "-S none ", TEST_DELTA_FILE, TEST_COPY_FILE); if ((ret = system (recmd)) != 0) { XPR(NT "recode command: %s\n", recmd); stream->msg = "recode cmd failed"; return XD3_INTERNAL; } /* Check recode changes. */ if ((ret = check_vcdiff_header (stream, TEST_COPY_FILE, "VCDIFF window indicator", "VCD_SOURCE", has_source))) { return ret; } if ((ret = check_vcdiff_header (stream, TEST_COPY_FILE, "VCDIFF header indicator", "VCD_SECONDARY", recoded_secondary))) { return ret; } if ((ret = check_vcdiff_header (stream, TEST_COPY_FILE, "VCDIFF window indicator", "VCD_ADLER32", /* Recode can't generate an adler32 * checksum, it can only preserve it or * remove it. */ has_adler32 && recoded_adler32))) { return ret; } if (!change_apphead) { if ((ret = check_vcdiff_header (stream, TEST_COPY_FILE, "VCDIFF header indicator", "VCD_APPHEADER", has_apphead))) { return ret; } if ((ret = check_vcdiff_header (stream, TEST_COPY_FILE, "VCDIFF application header", "encode_apphead", has_apphead))) { return ret; } } else { if ((ret = check_vcdiff_header (stream, TEST_COPY_FILE, "VCDIFF header indicator", "VCD_APPHEADER", recoded_apphead))) { return ret; } if (recoded_apphead && (ret = check_vcdiff_header (stream, TEST_COPY_FILE, "VCDIFF application header", "recode_apphead", 1))) { return ret; } } /* Now decode */ snprintf_func (dcmd, TESTBUFSIZE, "%s -fd %s %s %s %s ", program_name, has_source ? "-s " : "", has_source ? TEST_SOURCE_FILE : "", TEST_COPY_FILE, TEST_RECON_FILE); if ((ret = system (dcmd)) != 0) { XPR(NT "decode command: %s\n", dcmd); stream->msg = "decode cmd failed"; return XD3_INTERNAL; } /* Now compare. */ if ((ret = test_compare_files (TEST_TARGET_FILE, TEST_RECON_FILE))) { return ret; } return 0; }
CWE-119
null
516,920
263786761600529194296119057890862627266
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
mt_exp_rand (uint32_t mean, uint32_t max_value) { double mean_d = mean; double erand = log (1.0 / (mt_random (&static_mtrand) / (double)UINT32_MAX)); uint32_t x = (uint32_t) (mean_d * erand + 0.5); return min (x, max_value); }
CWE-119
null
516,921
303088693210086447271976686948802873996
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_recompress_output (main_file *ofile) { pid_t recomp_id; /* One subproc. */ int pipefd[2]; /* One pipe. */ int output_fd = -1; int ret; const main_extcomp *recomp = ofile->compressor; pipefd[0] = pipefd[1] = -1; if (pipe (pipefd)) { XPR(NT "pipe failed: %s\n", xd3_mainerror (ret = get_errno ())); goto pipe_cleanup; } if ((recomp_id = fork ()) < 0) { XPR(NT "fork failed: %s\n", xd3_mainerror (ret = get_errno ())); goto pipe_cleanup; } /* The child runs the recompression process: */ if (recomp_id == 0) { if (option_verbose > 2) { XPR(NT "external recompression pid %d\n", getpid ()); } /* Setup pipes: write to the output file, read from the pipe. */ if (dup2 (XFNO (ofile), STDOUT_FILENO) < 0 || dup2 (pipefd[PIPE_READ_FD], STDIN_FILENO) < 0 || close (pipefd[PIPE_READ_FD]) || close (pipefd[PIPE_WRITE_FD]) || execlp (recomp->recomp_cmdname, recomp->recomp_cmdname, recomp->recomp_options, option_force2 ? "-f" : NULL, NULL)) { XPR(NT "child process %s failed to execute: %s\n", recomp->recomp_cmdname, xd3_mainerror (get_errno ())); } _exit (127); } XD3_ASSERT(num_subprocs < MAX_SUBPROCS); ext_subprocs[num_subprocs++] = recomp_id; /* The parent closes both pipes after duplicating the output-fd for * writing to the compression pipe. */ output_fd = dup (pipefd[PIPE_WRITE_FD]); if (output_fd < 0 || main_file_close (ofile) || close (pipefd[PIPE_READ_FD]) || close (pipefd[PIPE_WRITE_FD])) { XPR(NT "close failed: %s\n", xd3_mainerror (ret = get_errno ())); goto pipe_cleanup; } #if XD3_STDIO /* Note: fdopen() acquires the fd, closes it when finished. */ if ((ofile->file = fdopen (output_fd, "w")) == NULL) { XPR(NT "fdopen failed: %s\n", xd3_mainerror (ret = get_errno ())); goto pipe_cleanup; } #elif XD3_POSIX ofile->file = output_fd; #endif /* Now the output file will be compressed. */ return 0; pipe_cleanup: close (output_fd); close (pipefd[PIPE_READ_FD]); close (pipefd[PIPE_WRITE_FD]); return ret; }
CWE-119
null
516,922
51184370624998754138104179835592489235
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_read_integer_error (xd3_stream *stream, usize_t trunto, const char *msg) { uint64_t eval = 1ULL << 34; uint32_t rval; xd3_output *buf = NULL; const uint8_t *max; const uint8_t *inp; int ret; buf = xd3_alloc_output (stream, buf); if ((ret = xd3_emit_uint64_t (stream, & buf, eval))) { goto fail; } again: inp = buf->base; max = buf->base + buf->next - trunto; if ((ret = xd3_read_uint32_t (stream, & inp, max, & rval)) != XD3_INVALID_INPUT || !MSG_IS (msg)) { ret = XD3_INTERNAL; } else if (trunto && trunto < buf->next) { trunto += 1; goto again; } else { ret = 0; } fail: xd3_free_output (stream, buf); return ret; }
CWE-119
null
516,923
61302260275740623886454209835339733035
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_file_write (main_file *ofile, uint8_t *buf, usize_t size, const char *msg) { int ret = 0; #if XD3_STDIO usize_t result; result = fwrite (buf, 1, size, ofile->file); if (result != size) { ret = get_errno (); } #elif XD3_POSIX ret = xd3_posix_io (ofile->file, buf, size, (xd3_posix_func*) &write, NULL); #elif XD3_WIN32 ret = xd3_win32_io (ofile->file, buf, size, 0, NULL); #endif if (ret) { XPR(NT "%s: %s: %s\n", msg, ofile->filename, xd3_mainerror (ret)); } else { if (option_verbose > 5) { XPR(NT "write %s: %u bytes\n", ofile->filename, size); } ofile->nwrite += size; } return ret; }
CWE-119
null
516,924
287320975643872275904784993166719888454
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
static int do_fail (xd3_stream *stream, const char *buf) { int ret; ret = system (buf); if (! WIFEXITED (ret) || WEXITSTATUS (ret) != 1) { stream->msg = "command should have not succeeded"; XPR(NT "command was %s\n", buf); return XD3_INTERNAL; } return 0; }
CWE-119
null
516,925
224815963893685768451486316463905835131
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_address_cache (xd3_stream *stream, int unused) { int ret; usize_t i; usize_t offset; usize_t *addrs; uint8_t *big_buf, *buf_max; const uint8_t *buf; xd3_output *outp; uint8_t *modes; int mode_counts[16]; stream->acache.s_near = stream->code_table_desc->near_modes; stream->acache.s_same = stream->code_table_desc->same_modes; if ((ret = xd3_encode_init_partial (stream))) { return ret; } addrs = (usize_t*) xd3_alloc (stream, sizeof (usize_t), ADDR_CACHE_ROUNDS); modes = (uint8_t*) xd3_alloc (stream, sizeof (uint8_t), ADDR_CACHE_ROUNDS); memset (mode_counts, 0, sizeof (mode_counts)); memset (modes, 0, ADDR_CACHE_ROUNDS); addrs[0] = 0; mt_init (& static_mtrand, 0x9f73f7fc); /* First pass: encode addresses */ xd3_init_cache (& stream->acache); for (offset = 1; offset < ADDR_CACHE_ROUNDS; offset += 1) { double p; usize_t addr; usize_t prev_i; usize_t nearby; p = (mt_random (&static_mtrand) / (double)USIZE_T_MAX); prev_i = mt_random (&static_mtrand) % offset; nearby = (mt_random (&static_mtrand) % 256) % offset; nearby = max (1U, nearby); if (p < 0.1) { addr = addrs[offset-nearby]; } else if (p < 0.4) { addr = min (addrs[prev_i] + nearby, offset-1); } else { addr = prev_i; } if ((ret = xd3_encode_address (stream, addr, offset, & modes[offset]))) { return ret; } addrs[offset] = addr; mode_counts[modes[offset]] += 1; } /* Copy addresses into a contiguous buffer. */ big_buf = (uint8_t*) xd3_alloc (stream, xd3_sizeof_output (ADDR_HEAD (stream)), 1); for (offset = 0, outp = ADDR_HEAD (stream); outp != NULL; offset += outp->next, outp = outp->next_page) { memcpy (big_buf + offset, outp->base, outp->next); } buf_max = big_buf + offset; buf = big_buf; /* Second pass: decode addresses */ xd3_init_cache (& stream->acache); for (offset = 1; offset < ADDR_CACHE_ROUNDS; offset += 1) { uint32_t addr; if ((ret = xd3_decode_address (stream, offset, modes[offset], & buf, buf_max, & addr))) { return ret; } if (addr != addrs[offset]) { stream->msg = "incorrect decoded address"; return XD3_INTERNAL; } } /* Check that every byte, mode was used. */ if (buf != buf_max) { stream->msg = "address bytes not used"; return XD3_INTERNAL; } for (i = 0; i < (2 + stream->acache.s_same + stream->acache.s_near); i += 1) { if (mode_counts[i] == 0) { stream->msg = "address mode not used"; return XD3_INTERNAL; } } xd3_free (stream, modes); xd3_free (stream, addrs); xd3_free (stream, big_buf); return 0; }
CWE-119
null
516,926
283895242530154231716958330213740720047
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_file_open (main_file *xfile, const char* name, int mode) { int ret = 0; xfile->mode = mode; XD3_ASSERT (name != NULL); XD3_ASSERT (! main_file_isopen (xfile)); if (name[0] == 0) { XPR(NT "invalid file name: empty string\n"); return XD3_INVALID; } #if XD3_STDIO xfile->file = fopen (name, XOPEN_STDIO); ret = (xfile->file == NULL) ? get_errno () : 0; #elif XD3_POSIX /* TODO: Should retry this call if interrupted, similar to read/write */ if ((ret = open (name, XOPEN_POSIX, XOPEN_MODE)) < 0) { ret = get_errno (); } else { xfile->file = ret; ret = 0; } #elif XD3_WIN32 xfile->file = CreateFile(name, (mode == XO_READ) ? GENERIC_READ : GENERIC_WRITE, FILE_SHARE_READ, NULL, (mode == XO_READ) ? OPEN_EXISTING : (option_force ? CREATE_ALWAYS : CREATE_NEW), FILE_ATTRIBUTE_NORMAL, NULL); if (xfile->file == INVALID_HANDLE_VALUE) { ret = get_errno (); } #endif if (ret) { XF_ERROR ("open", name, ret); } else { xfile->realname = name; xfile->nread = 0; } return ret; }
CWE-119
null
516,927
162854778730886026578675599525011726646
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_waitpid_check(pid_t pid) { int status; int ret = 0; if (waitpid (pid, & status, 0) < 0) { ret = get_errno (); XPR(NT "external compression [pid %d] wait: %s\n", pid, xd3_mainerror (ret)); } else if (! WIFEXITED (status)) { // SIGPIPE will be delivered to the child process whenever it // writes data after this process closes the pipe, // happens if xdelta does not require access to the entire // source file. Considered normal. if (! WIFSIGNALED (status) || WTERMSIG (status) != SIGPIPE) { ret = ECHILD; XPR(NT "external compression [pid %d] signal %d\n", pid, WIFSIGNALED (status) ? WTERMSIG (status) : WSTOPSIG (status)); } else if (option_verbose) { XPR(NT "external compression sigpipe\n"); } } else if (WEXITSTATUS (status) != 0) { ret = ECHILD; if (option_verbose > 1) { /* Presumably, the error was printed by the subprocess. */ XPR(NT "external compression [pid %d] exit %d\n", pid, WEXITSTATUS (status)); } } return ret; }
CWE-119
null
516,928
147526116109999219049711013954473894618
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
setup_environment (int argc, char **argv, int *argc_out, char ***argv_out, char ***argv_free, char **env_free) { int n, i, i0; char *p, *v = getenv("XDELTA"); if (v == NULL) { (*argc_out) = argc; (*argv_out) = argv; (*argv_free) = NULL; (*env_free) = NULL; return; } (*env_free) = (char*) main_malloc((usize_t) strlen(v) + 1); strcpy(*env_free, v); /* Space needed for extra args, at least # of spaces */ n = argc + 1; for (p = *env_free; *p != 0; ) { if (*p++ == ' ') { n++; } } (*argv_free) = (char**) main_malloc(sizeof(char*) * (n + 1)); (*argv_out) = (*argv_free); (*argv_out)[0] = argv[0]; (*argv_out)[n] = NULL; i = 1; for (p = *env_free; *p != 0; ) { (*argv_out)[i++] = p; while (*p != ' ' && *p != 0) { p++; } while (*p == ' ') { *p++ = 0; } } for (i0 = 1; i0 < argc; i0++) { (*argv_out)[i++] = argv[i0]; } /* Counting spaces is an upper bound, argv stays NULL terminated. */ (*argc_out) = i; while (i <= n) { (*argv_out)[i++] = NULL; } }
CWE-119
null
516,929
126462088103621171140217225340470583460
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_compress_text (xd3_stream *stream, uint8_t *encoded, usize_t *encoded_size) { int ret; xd3_config cfg; int oflags = stream->flags; int flags = stream->flags | XD3_FLUSH; xd3_free_stream (stream); xd3_init_config (& cfg, flags); /* This configuration is fixed so that the "expected non-error" the counts in * decompress_single_bit_errors are too. See test_coftcfg_str. */ cfg.smatch_cfg = XD3_SMATCH_SOFT; cfg.smatcher_soft.name = "test"; cfg.smatcher_soft.large_look = 64; /* no source, not used */ cfg.smatcher_soft.large_step = 64; /* no source, not used */ cfg.smatcher_soft.small_look = 4; cfg.smatcher_soft.small_chain = 128; cfg.smatcher_soft.small_lchain = 16; cfg.smatcher_soft.max_lazy = 8; cfg.smatcher_soft.long_enough = 128; xd3_config_stream (stream, & cfg); (*encoded_size) = 0; xd3_set_appheader (stream, test_apphead, (usize_t) strlen ((char*) test_apphead)); if ((ret = xd3_encode_stream (stream, test_text, sizeof (test_text), encoded, encoded_size, 4*sizeof (test_text)))) { goto fail; } if ((ret = xd3_close_stream (stream))) { goto fail; } fail: xd3_free_stream (stream); xd3_init_config (& cfg, oflags); xd3_config_stream (stream, & cfg); return ret; }
CWE-119
null
516,930
154409636281385518966848746448087227706
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
sec_dist_func2 (xd3_stream *stream, xd3_output *data) { int i, ret; for (i = 0; i < ALPHABET_SIZE; i += 1) { if ((ret = xd3_emit_byte (stream, & data, i%(ALPHABET_SIZE/2)))) { return ret; } } return 0; }
CWE-119
null
516,931
14879267251952251165010708224649387272
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
sec_dist_func10 (xd3_stream *stream, xd3_output *data) { int i, j, ret; for (i = 0; i < ALPHABET_SIZE; i += 1) { for (j = 0; j <= (i*i); j += 1) { if ((ret = xd3_emit_byte (stream, & data, i))) { return ret; } } } return 0; }
CWE-119
null
516,932
272882183312366045410562505165284931164
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_streaming (xd3_stream *in_stream, uint8_t *encbuf, uint8_t *decbuf, uint8_t *delbuf, usize_t megs) { xd3_stream estream, dstream; int ret; usize_t i, delsize, decsize; xd3_config cfg; xd3_init_config (& cfg, in_stream->flags); cfg.flags |= XD3_COMPLEVEL_6; if ((ret = xd3_config_stream (& estream, & cfg)) || (ret = xd3_config_stream (& dstream, & cfg))) { goto fail; } for (i = 0; i < megs; i += 1) { ((usize_t*) encbuf)[0] = i; if ((i % 200) == 199) { DOT (); } if ((ret = xd3_process_stream (1, & estream, xd3_encode_input, 0, encbuf, 1 << 20, delbuf, & delsize, 1 << 20))) { in_stream->msg = estream.msg; goto fail; } if ((ret = xd3_process_stream (0, & dstream, xd3_decode_input, 0, delbuf, delsize, decbuf, & decsize, 1 << 20))) { in_stream->msg = dstream.msg; goto fail; } if (decsize != 1 << 20 || memcmp (encbuf, decbuf, 1 << 20) != 0) { in_stream->msg = "wrong result"; ret = XD3_INTERNAL; goto fail; } } if ((ret = xd3_close_stream (& estream)) || (ret = xd3_close_stream (& dstream))) { goto fail; } fail: xd3_free_stream (& estream); xd3_free_stream (& dstream); return ret; }
CWE-119
null
516,933
291308776231589670348866114343552122016
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
sec_dist_func7 (xd3_stream *stream, xd3_output *data) { int i, ret, x; for (i = 0; i < ALPHABET_SIZE*200; i += 1) { x = mt_random (&static_mtrand) % ALPHABET_SIZE; if ((ret = xd3_emit_byte (stream, & data, x))) { return ret; } } return 0; }
CWE-119
null
516,934
168138156731726969439763192427261913554
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
get_millisecs_now (void) { #ifndef _WIN32 struct timeval tv; gettimeofday (& tv, NULL); return (tv.tv_sec) * 1000L + (tv.tv_usec) / 1000; #else SYSTEMTIME st; FILETIME ft; __int64 *pi = (__int64*)&ft; GetLocalTime(&st); SystemTimeToFileTime(&st, &ft); return (long)((*pi) / 10000); #endif }
CWE-119
null
516,935
286547076285337279577314787029626205990
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_file_init (main_file *xfile) { memset (xfile, 0, sizeof (*xfile)); #if XD3_POSIX xfile->file = -1; #endif #if XD3_WIN32 xfile->file = INVALID_HANDLE_VALUE; #endif }
CWE-119
null
516,936
127119701381858874185821742953296257858
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_cleanup (void) { #if 1 test_unlink (TEST_TARGET_FILE); test_unlink (TEST_SOURCE_FILE); test_unlink (TEST_DELTA_FILE); test_unlink (TEST_RECON_FILE); test_unlink (TEST_RECON2_FILE); test_unlink (TEST_COPY_FILE); test_unlink (TEST_NOPERM_FILE); #endif }
CWE-119
null
516,937
338471516742594537014203447098478374455
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
sec_dist_func1 (xd3_stream *stream, xd3_output *data) { int i, ret; for (i = 0; i < 100; i += 1) { if ((ret = xd3_emit_byte (stream, & data, 13))) { return ret; } } return 0; }
CWE-119
null
516,938
93846126401889900162008739388839690508
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_print_window (xd3_stream* stream, main_file *xfile) { int ret; usize_t size = 0; VC(UT " Offset Code Type1 Size1 @Addr1 + Type2 Size2 @Addr2\n")VE; while (stream->inst_sect.buf < stream->inst_sect.buf_max) { usize_t code = stream->inst_sect.buf[0]; const uint8_t *addr_before = stream->addr_sect.buf; const uint8_t *inst_before = stream->inst_sect.buf; usize_t addr_bytes; usize_t inst_bytes; usize_t size_before = size; if ((ret = xd3_decode_instruction (stream))) { XPR(NT "instruction decode error at %"Q"u: %s\n", stream->dec_winstart + size, stream->msg); return ret; } addr_bytes = (usize_t)(stream->addr_sect.buf - addr_before); inst_bytes = (usize_t)(stream->inst_sect.buf - inst_before); VC(UT " %06"Q"u %03u %s %6u", stream->dec_winstart + size, option_print_cpymode ? code : 0, xd3_rtype_to_string ((xd3_rtype) stream->dec_current1.type, option_print_cpymode), stream->dec_current1.size)VE; if (stream->dec_current1.type != XD3_NOOP) { if (stream->dec_current1.type >= XD3_CPY) { if (stream->dec_current1.addr >= stream->dec_cpylen) { VC(UT " T@%-6u", stream->dec_current1.addr - stream->dec_cpylen)VE; } else { VC(UT " S@%-6"Q"u", stream->dec_cpyoff + stream->dec_current1.addr)VE; } } else { VC(UT " ")VE; } size += stream->dec_current1.size; } if (stream->dec_current2.type != XD3_NOOP) { VC(UT " %s %6u", xd3_rtype_to_string ((xd3_rtype) stream->dec_current2.type, option_print_cpymode), stream->dec_current2.size)VE; if (stream->dec_current2.type >= XD3_CPY) { if (stream->dec_current2.addr >= stream->dec_cpylen) { VC(UT " T@%-6u", stream->dec_current2.addr - stream->dec_cpylen)VE; } else { VC(UT " S@%-6"Q"u", stream->dec_cpyoff + stream->dec_current2.addr)VE; } } size += stream->dec_current2.size; } VC(UT "\n")VE; if (option_verbose && addr_bytes + inst_bytes >= (size - size_before) && (stream->dec_current1.type >= XD3_CPY || stream->dec_current2.type >= XD3_CPY)) { VC(UT " %06"Q"u (inefficiency) %u encoded as %u bytes\n", stream->dec_winstart + size_before, size - size_before, addr_bytes + inst_bytes)VE; } } if (stream->dec_tgtlen != size && (stream->flags & XD3_SKIP_WINDOW) == 0) { XPR(NT "target window size inconsistency"); return XD3_INTERNAL; } if (stream->dec_position != stream->dec_maxpos) { XPR(NT "target window position inconsistency"); return XD3_INTERNAL; } if (stream->addr_sect.buf != stream->addr_sect.buf_max) { XPR(NT "address section inconsistency"); return XD3_INTERNAL; } return 0; }
CWE-119
null
516,939
75074642522375867066880530435130123269
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_pipe_copier (uint8_t *pipe_buf, usize_t pipe_bufsize, size_t nread, main_file *ifile, int outfd) { int ret; xoff_t skipped = 0; /* Prevent SIGPIPE signals, allow EPIPE return values instead. This * is safe to comment-out, except that the -F flag will not work * properly (the parent would need to treat WTERMSIG(status) == * SIGPIPE). */ struct sigaction sa; sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, NULL); for (;;) { /* force_drain will be set when option_force and EPIPE cause us * to skip data. This is reset each time through the loop, so * the break condition below works. */ int force_drain = 0; if (nread > 0 && (ret = main_pipe_write (outfd, pipe_buf, nread))) { if (ret == EPIPE) { /* This causes the loop to continue reading until nread * == 0. */ skipped += nread; force_drain = 1; } else { XPR(NT "pipe write failed: %s\n", xd3_mainerror (ret)); return ret; } } if (nread < pipe_bufsize && !force_drain) { break; } if ((ret = main_file_read (ifile, pipe_buf, pipe_bufsize, & nread, "pipe read failed")) < 0) { return ret; } } if (option_verbose && skipped != 0) { XPR(NT "skipping %"Q"u bytes in %s\n", skipped, ifile->filename); } return 0; }
CWE-119
null
516,940
109507829899647866871746464080641925256
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_atoux (const char* arg, xoff_t *xo, xoff_t low, xoff_t high, char which) { xoff_t x; int ret; if ((ret = main_strtoxoff (arg, & x, which))) { return ret; } if (x < low) { XPR(NT "-%c: minimum value: %"Q"u\n", which, low); return EXIT_FAILURE; } if (high != 0 && x > high) { XPR(NT "-%c: maximum value: %"Q"u\n", which, high); return EXIT_FAILURE; } (*xo) = x; return 0; }
CWE-119
null
516,941
112535729836874876346633950589609549285
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_read_primary_input (main_file *file, uint8_t *buf, size_t size, size_t *nread) { #if EXTERNAL_COMPRESSION if (option_decompress_inputs && file->flags & RD_FIRST) { file->flags &= ~RD_FIRST; return main_secondary_decompress_check (file, buf, size, nread); } #endif return main_file_read (file, buf, size, nread, "input read failed"); }
CWE-119
null
516,942
253843503834371529788747938713376946829
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_usize_t_overflow (xd3_stream *stream, int unused) { if (USIZE_T_OVERFLOW (USIZE_T_MAX, 0)) { goto fail; } if (USIZE_T_OVERFLOW (0, USIZE_T_MAX)) { goto fail; } if (USIZE_T_OVERFLOW (USIZE_T_MAX / 2, USIZE_T_MAX / 2)) { goto fail; } if (USIZE_T_OVERFLOW (USIZE_T_MAX / 2, USIZE_T_MAX / 2 + 1)) { goto fail; } if (! USIZE_T_OVERFLOW (USIZE_T_MAX, 1)) { goto fail; } if (! USIZE_T_OVERFLOW (1, USIZE_T_MAX)) { goto fail; } if (! USIZE_T_OVERFLOW (USIZE_T_MAX / 2 + 1, USIZE_T_MAX / 2 + 1)) { goto fail; } return 0; fail: stream->msg = "incorrect overflow computation"; return XD3_INTERNAL; }
CWE-119
null
516,943
122107308972578063605479159803126638965
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_file_size (const char* file, xoff_t *size) { struct stat sbuf; int ret; (*size) = 0; if (stat (file, & sbuf) < 0) { ret = get_errno (); XPR(NT "stat failed: %s: %s\n", file, strerror (ret)); return ret; } if (! S_ISREG (sbuf.st_mode)) { ret = XD3_INTERNAL; XPR(NT "not a regular file: %s: %s\n", file, strerror (ret)); return ret; } (*size) = sbuf.st_size; return 0; }
CWE-119
null
516,944
307645008834026111574873240575440119356
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_compressed_stream_overflow (xd3_stream *stream, int ignore) { int ret; int i; uint8_t *buf; if ((buf = (uint8_t*) malloc (TWO_MEGS_AND_DELTA)) == NULL) { return ENOMEM; } memset (buf, 0, TWO_MEGS_AND_DELTA); for (i = 0; i < (2 << 20); i += 256) { int j; int off = mt_random(& static_mtrand) % 10; for (j = 0; j < 256; j++) { buf[i + j] = j + off; } } /* Test overflow of a 32-bit file offset. */ if (SIZEOF_XOFF_T == 4) { ret = test_streaming (stream, buf, buf + (1 << 20), buf + (2 << 20), (1 << 12) + 1); if (ret == XD3_INVALID_INPUT && MSG_IS ("decoder file offset overflow")) { ret = 0; } else { XPR(NT XD3_LIB_ERRMSG (stream, ret)); stream->msg = "expected overflow condition"; ret = XD3_INTERNAL; goto fail; } } /* Test transfer of exactly 32bits worth of data. */ if ((ret = test_streaming (stream, buf, buf + (1 << 20), buf + (2 << 20), 1 << 12))) { goto fail; } fail: free (buf); return ret; }
CWE-119
null
516,945
247604659987552587877674552210440636839
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_file_exists (main_file *xfile) { struct stat sbuf; return stat (xfile->filename, & sbuf) == 0 && S_ISREG (sbuf.st_mode); }
CWE-119
null
516,946
35266604426184918252516551501023280126
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_appheader (xd3_stream *stream, int ignore) { int i; int ret; char buf[TESTBUFSIZE]; char bogus[TESTBUFSIZE]; xoff_t ssize, tsize; test_setup (); if ((ret = test_make_inputs (stream, &ssize, &tsize))) { return ret; } snprintf_func (buf, TESTBUFSIZE, "%s -q -f -e -s %s %s %s", program_name, TEST_SOURCE_FILE, TEST_TARGET_FILE, TEST_DELTA_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } if ((ret = test_copy_to (program_name, TEST_RECON2_FILE))) { return ret; } snprintf_func (buf, TESTBUFSIZE, "chmod 0700 %s", TEST_RECON2_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } if ((ret = test_save_copy (TEST_TARGET_FILE))) { return ret; } if ((ret = test_copy_to (TEST_SOURCE_FILE, TEST_TARGET_FILE))) { return ret; } if ((ret = test_compare_files (TEST_TARGET_FILE, TEST_COPY_FILE)) == 0) { return XD3_INVALID; // I.e., files are different! } // Test that the target file is restored. snprintf_func (buf, TESTBUFSIZE, "(cd /tmp && %s -q -f -d %s)", TEST_RECON2_FILE, TEST_DELTA_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } if ((ret = test_compare_files (TEST_TARGET_FILE, TEST_COPY_FILE)) != 0) { return ret; } // Test a malicious string w/ entries > 4 in the appheader by having // the encoder write it: for (i = 0; i < TESTBUFSIZE / 4; ++i) { bogus[2*i] = 'G'; bogus[2*i+1] = '/'; } bogus[TESTBUFSIZE/2-1] = 0; snprintf_func (buf, TESTBUFSIZE, "%s -q -f -A=%s -e -s %s %s %s", program_name, bogus, TEST_SOURCE_FILE, TEST_TARGET_FILE, TEST_DELTA_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } // Then read it: snprintf_func (buf, TESTBUFSIZE, "(cd /tmp && %s -q -f -d %s)", TEST_RECON2_FILE, TEST_DELTA_FILE); if ((ret = do_cmd (stream, buf)) == 0) { return XD3_INVALID; // Impossible } if (!WIFEXITED(ret)) { return XD3_INVALID; // Must have crashed! } return 0; }
CWE-119
null
516,947
261563666099016907326748075556653488714
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
static void DOT (void) { XPR(NTR "."); }
CWE-119
null
516,948
106756572669403096643934744870312950158
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_malloc (size_t size) { void *r = main_malloc1 (size); if (r) { IF_DEBUG (main_mallocs += 1); } return r; }
CWE-119
null
516,949
99895257517160862529159044658203547754
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_make_inputs (xd3_stream *stream, xoff_t *ss_out, xoff_t *ts_out) { usize_t ts = (mt_random (&static_mtrand) % TEST_FILE_MEAN) + TEST_FILE_MEAN / 2; usize_t ss = (mt_random (&static_mtrand) % TEST_FILE_MEAN) + TEST_FILE_MEAN / 2; uint8_t *buf = (uint8_t*) malloc (ts + ss), *sbuf = buf, *tbuf = buf + ss; usize_t sadd = 0, sadd_max = (usize_t)(ss * TEST_ADD_RATIO); FILE *tf = NULL, *sf = NULL; usize_t i, j; int ret; if (buf == NULL) { return ENOMEM; } if ((tf = fopen (TEST_TARGET_FILE, "w")) == NULL || (ss_out != NULL && (sf = fopen (TEST_SOURCE_FILE, "w")) == NULL)) { stream->msg = "write failed"; ret = get_errno (); goto failure; } if (ss_out != NULL) { for (i = 0; i < ss; ) { sbuf[i++] = (uint8_t) mt_random (&static_mtrand); } } /* Then modify the data to produce copies, everything not copied is * an add. The following logic produces the TEST_ADD_RATIO. The * variable SADD contains the number of adds so far, which should * not exceed SADD_MAX. */ /* XPR(NT "ss = %u ts = %u\n", ss, ts); */ for (i = 0; i < ts; ) { usize_t left = ts - i; usize_t next = mt_exp_rand ((uint32_t) TEST_ADD_MEAN, (uint32_t) TEST_ADD_MAX); usize_t add_left = sadd_max - sadd; double add_prob = (left == 0) ? 0 : (add_left / (double) left); int do_copy; next = min (left, next); do_copy = (next > add_left || (mt_random (&static_mtrand) / \ (double)USIZE_T_MAX) >= add_prob); if (ss_out == NULL) { do_copy &= (i > 0); } else { do_copy &= (ss - next) > 0; } if (do_copy) { /* Copy */ size_t offset = mt_random (&static_mtrand) % ((ss_out == NULL) ? i : (ss - next)); /* XPR(NT "[%u] copy %u at %u ", i, next, offset); */ for (j = 0; j < next; j += 1) { char c = ((ss_out == NULL) ? tbuf : sbuf)[offset + j]; /* XPR(NT "%x%x", (c >> 4) & 0xf, c & 0xf); */ tbuf[i++] = c; } /* XPR(NT "\n"); */ } else { /* Add */ /* XPR(NT "[%u] add %u ", i, next); */ for (j = 0; j < next; j += 1) { char c = (char) mt_random (&static_mtrand); /* XPR(NT "%x%x", (c >> 4) & 0xf, c & 0xf); */ tbuf[i++] = c; } /* XPR(NT "\n"); */ sadd += next; } } /* XPR(NT "sadd = %u max = %u\n", sadd, sadd_max); */ if ((fwrite (tbuf, 1, ts, tf) != ts) || (ss_out != NULL && (fwrite (sbuf, 1, ss, sf) != ss))) { stream->msg = "write failed"; ret = get_errno (); goto failure; } if ((ret = fclose (tf)) || (ss_out != NULL && (ret = fclose (sf)))) { stream->msg = "close failed"; ret = get_errno (); goto failure; } if (ts_out) { (*ts_out) = ts; } if (ss_out) { (*ss_out) = ss; } failure: free (buf); return ret; }
CWE-119
null
516,950
15841120587608600351085890955614086746
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_print_func (xd3_stream* stream, main_file *xfile) { int ret; if (option_no_output) { return 0; } if (xfile->snprintf_buf == NULL) { if ((xfile->snprintf_buf = (uint8_t*)main_malloc(SNPRINTF_BUFSIZE)) == NULL) { return ENOMEM; } } if (stream->dec_winstart == 0) { VC(UT "VCDIFF version: 0\n")VE; VC(UT "VCDIFF header size: %d\n", stream->dec_hdrsize)VE; VC(UT "VCDIFF header indicator: ")VE; if ((stream->dec_hdr_ind & VCD_SECONDARY) != 0) VC(UT "VCD_SECONDARY ")VE; if ((stream->dec_hdr_ind & VCD_CODETABLE) != 0) VC(UT "VCD_CODETABLE ")VE; if ((stream->dec_hdr_ind & VCD_APPHEADER) != 0) VC(UT "VCD_APPHEADER ")VE; if (stream->dec_hdr_ind == 0) VC(UT "none")VE; VC(UT "\n")VE; IF_SEC(VC(UT "VCDIFF secondary compressor: %s\n", stream->sec_type ? stream->sec_type->name : "none")VE); IF_NSEC(VC(UT "VCDIFF secondary compressor: unsupported\n")VE); if (stream->dec_hdr_ind & VCD_APPHEADER) { uint8_t *apphead; usize_t appheadsz; ret = xd3_get_appheader (stream, & apphead, & appheadsz); if (ret == 0 && appheadsz > 0) { int sq = option_quiet; main_file i, o, s; XD3_ASSERT (apphead != NULL); VC(UT "VCDIFF application header: ")VE; if ((ret = main_file_write (xfile, apphead, appheadsz, "print")) != 0) { return ret; } VC(UT "\n")VE; main_file_init (& i); main_file_init (& o); main_file_init (& s); option_quiet = 1; main_get_appheader (stream, &i, & o, & s); option_quiet = sq; if ((ret = main_print_vcdiff_file (xfile, & o, "output"))) { return ret; } if ((ret = main_print_vcdiff_file (xfile, & s, "source"))) { return ret; } main_file_cleanup (& i); main_file_cleanup (& o); main_file_cleanup (& s); } } } else { VC(UT "\n")VE; } VC(UT "VCDIFF window number: %"Q"u\n", stream->current_window)VE; VC(UT "VCDIFF window indicator: ")VE; if ((stream->dec_win_ind & VCD_SOURCE) != 0) VC(UT "VCD_SOURCE ")VE; if ((stream->dec_win_ind & VCD_TARGET) != 0) VC(UT "VCD_TARGET ")VE; if ((stream->dec_win_ind & VCD_ADLER32) != 0) VC(UT "VCD_ADLER32 ")VE; if (stream->dec_win_ind == 0) VC(UT "none")VE; VC(UT "\n")VE; if ((stream->dec_win_ind & VCD_ADLER32) != 0) { VC(UT "VCDIFF adler32 checksum: %08X\n", (usize_t)stream->dec_adler32)VE; } if (stream->dec_del_ind != 0) { VC(UT "VCDIFF delta indicator: ")VE; if ((stream->dec_del_ind & VCD_DATACOMP) != 0) VC(UT "VCD_DATACOMP ")VE; if ((stream->dec_del_ind & VCD_INSTCOMP) != 0) VC(UT "VCD_INSTCOMP ")VE; if ((stream->dec_del_ind & VCD_ADDRCOMP) != 0) VC(UT "VCD_ADDRCOMP ")VE; if (stream->dec_del_ind == 0) VC(UT "none")VE; VC(UT "\n")VE; } if (stream->dec_winstart != 0) { VC(UT "VCDIFF window at offset: %"Q"u\n", stream->dec_winstart)VE; } if (SRCORTGT (stream->dec_win_ind)) { VC(UT "VCDIFF copy window length: %u\n", (usize_t)stream->dec_cpylen)VE; VC(UT "VCDIFF copy window offset: %"Q"u\n", stream->dec_cpyoff)VE; } VC(UT "VCDIFF delta encoding length: %u\n", (usize_t)stream->dec_enclen)VE; VC(UT "VCDIFF target window length: %u\n", (usize_t)stream->dec_tgtlen)VE; VC(UT "VCDIFF data section length: %u\n", (usize_t)stream->data_sect.size)VE; VC(UT "VCDIFF inst section length: %u\n", (usize_t)stream->inst_sect.size)VE; VC(UT "VCDIFF addr section length: %u\n", (usize_t)stream->addr_sect.size)VE; ret = 0; if ((stream->flags & XD3_JUST_HDR) != 0) { /* Print a header -- finished! */ ret = PRINTHDR_SPECIAL; } else if ((stream->flags & XD3_SKIP_WINDOW) == 0) { ret = main_print_window (stream, xfile); } return ret; }
CWE-119
null
516,951
170770935162704199335323940516547428499
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
sec_dist_func8 (xd3_stream *stream, xd3_output *data) { int i, ret; for (i = 0; i < ALPHABET_SIZE*5; i += 1) { if ((ret = xd3_emit_byte (stream, & data, 0))) { return ret; } if ((ret = xd3_emit_byte (stream, & data, 64))) { return ret; } if ((ret = xd3_emit_byte (stream, & data, 128))) { return ret; } if ((ret = xd3_emit_byte (stream, & data, 255))) { return ret; } } return 0; }
CWE-119
null
516,952
62801925485527333913537274275956832674
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_file_read (main_file *ifile, uint8_t *buf, size_t size, size_t *nread, const char *msg) { int ret = 0; #if XD3_STDIO size_t result; result = fread (buf, 1, size, ifile->file); if (result < size && ferror (ifile->file)) { ret = get_errno (); } else { *nread = result; } #elif XD3_POSIX ret = xd3_posix_io (ifile->file, buf, size, (xd3_posix_func*) &read, nread); #elif XD3_WIN32 ret = xd3_win32_io (ifile->file, buf, size, 1 /* is_read */, nread); #endif if (ret) { XPR(NT "%s: %s: %s\n", msg, ifile->filename, xd3_mainerror (ret)); } else { if (option_verbose > 4) { XPR(NT "read %s: %zu bytes\n", ifile->filename, (*nread)); } ifile->nread += (*nread); } return ret; }
CWE-119
null
516,953
293503998614582273513486337646087985536
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_in_memory (xd3_stream *stream, int ignore) { // test_text is 256 bytes uint8_t ibuf[sizeof(test_text)]; uint8_t dbuf[sizeof(test_text)]; uint8_t obuf[sizeof(test_text)]; usize_t size = sizeof(test_text); usize_t dsize, osize; int r1, r2; int eflags = SECONDARY_DJW ? XD3_SEC_DJW : 0; memcpy(ibuf, test_text, size); memset(ibuf + 128, 0, 16); r1 = xd3_encode_memory(ibuf, size, test_text, size, dbuf, &dsize, size, eflags); r2 = xd3_decode_memory(dbuf, dsize, test_text, size, obuf, &osize, size, 0); if (r1 != 0 || r2 != 0 || dsize >= (size/2) || dsize < 1 || osize != size) { stream->msg = "encode/decode size error"; return XD3_INTERNAL; } if (memcmp(obuf, ibuf, size) != 0) { stream->msg = "encode/decode data error"; return XD3_INTERNAL; } return 0; }
CWE-119
null
516,954
64170183370831382283974386803703882428
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_save_copy (const char *origname) { return test_copy_to(origname, TEST_COPY_FILE); }
CWE-119
null
516,955
157536747949358296425639360693028776148
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
xd3_win32_io (HANDLE file, uint8_t *buf, size_t size, int is_read, size_t *nread) { int ret = 0; size_t nproc = 0; while (nproc < size) { DWORD nproc2 = 0; /* hmm */ DWORD nremain = size - nproc; if ((is_read ? ReadFile (file, buf + nproc, nremain, &nproc2, NULL) : WriteFile (file, buf + nproc, nremain, &nproc2, NULL)) == 0) { ret = get_errno(); if (ret != ERROR_HANDLE_EOF && ret != ERROR_BROKEN_PIPE) { return ret; } /* By falling through here, we'll break this loop in the * read case in case of eof or broken pipe. */ } nproc += nproc2; if (nread != NULL && nproc2 == 0) { break; } } if (nread != NULL) { (*nread) = nproc; } return 0; }
CWE-119
null
516,956
115599959210649200380822219185699148206
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_recode_func (xd3_stream* stream, main_file *ofile) { int ret; xd3_source decode_source; XD3_ASSERT(stream->dec_state == DEC_FINISH); XD3_ASSERT(recode_stream->enc_state == ENC_INIT || recode_stream->enc_state == ENC_INPUT); // Copy partial decoder output to partial encoder inputs if ((ret = main_recode_copy (recode_stream, DATA_HEAD(recode_stream), &stream->data_sect)) || (ret = main_recode_copy (recode_stream, INST_HEAD(recode_stream), &stream->inst_sect)) || (ret = main_recode_copy (recode_stream, ADDR_HEAD(recode_stream), &stream->addr_sect))) { return ret; } // This jumps to xd3_emit_hdr() recode_stream->enc_state = ENC_FLUSH; recode_stream->avail_in = stream->dec_tgtlen; if (SRCORTGT (stream->dec_win_ind)) { recode_stream->src = & decode_source; decode_source.srclen = stream->dec_cpylen; decode_source.srcbase = stream->dec_cpyoff; } if (option_use_checksum && (stream->dec_win_ind & VCD_ADLER32) != 0) { recode_stream->flags |= XD3_ADLER32_RECODE; recode_stream->recode_adler32 = stream->dec_adler32; } if (option_use_appheader != 0 && option_appheader != NULL) { xd3_set_appheader (recode_stream, option_appheader, (usize_t) strlen ((char*) option_appheader)); } else if (option_use_appheader != 0 && option_appheader == NULL) { if (stream->dec_appheader != NULL) { xd3_set_appheader (recode_stream, stream->dec_appheader, stream->dec_appheadsz); } } // Output loop for (;;) { switch((ret = xd3_encode_input (recode_stream))) { case XD3_INPUT: { /* finished recoding one window */ stream->total_out = recode_stream->total_out; return 0; } case XD3_OUTPUT: { /* main_file_write below */ break; } case XD3_GOTHEADER: case XD3_WINSTART: case XD3_WINFINISH: { /* ignore */ continue; } case XD3_GETSRCBLK: case 0: { return XD3_INTERNAL; } default: return ret; } if ((ret = main_write_output (recode_stream, ofile))) { return ret; } xd3_consume_output (recode_stream); } }
CWE-119
null
516,957
230855490935287337933580828688980900901
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_input (xd3_cmd cmd, main_file *ifile, main_file *ofile, main_file *sfile) { int ret; xd3_stream stream; size_t nread = 0; usize_t winsize; int stream_flags = 0; xd3_config config; xd3_source source; xoff_t last_total_in = 0; xoff_t last_total_out = 0; long start_time; int stdout_only = 0; int (*input_func) (xd3_stream*); int (*output_func) (xd3_stream*, main_file *); memset (& stream, 0, sizeof (stream)); memset (& source, 0, sizeof (source)); memset (& config, 0, sizeof (config)); config.alloc = main_alloc; config.freef = main_free1; config.iopt_size = option_iopt_size; config.sprevsz = option_sprevsz; do_src_fifo = 0; start_time = get_millisecs_now (); if (option_use_checksum) { stream_flags |= XD3_ADLER32; } /* main_input setup. */ switch ((int) cmd) { #if VCDIFF_TOOLS if (1) { case CMD_PRINTHDR: stream_flags |= XD3_JUST_HDR; } else if (1) { case CMD_PRINTHDRS: stream_flags |= XD3_SKIP_WINDOW; } else { case CMD_PRINTDELTA: stream_flags |= XD3_SKIP_EMIT; } ifile->flags |= RD_NONEXTERNAL; input_func = xd3_decode_input; output_func = main_print_func; stream_flags |= XD3_ADLER32_NOVER; stdout_only = 1; break; case CMD_RECODE: case CMD_MERGE: case CMD_MERGE_ARG: /* No source will be read */ stream_flags |= XD3_ADLER32_NOVER | XD3_SKIP_EMIT; ifile->flags |= RD_NONEXTERNAL; input_func = xd3_decode_input; if ((ret = main_init_recode_stream ())) { return EXIT_FAILURE; } if (cmd == CMD_RECODE) { output_func = main_recode_func; } else { output_func = main_merge_func; } break; #endif /* VCDIFF_TOOLS */ #if XD3_ENCODER case CMD_ENCODE: do_src_fifo = 1; input_func = xd3_encode_input; output_func = main_write_output; if (option_no_compress) { stream_flags |= XD3_NOCOMPRESS; } if (option_use_altcodetable) { stream_flags |= XD3_ALT_CODE_TABLE; } if (option_smatch_config) { const char *s = option_smatch_config; char *e; int values[XD3_SOFTCFG_VARCNT]; int got; config.smatch_cfg = XD3_SMATCH_SOFT; for (got = 0; got < XD3_SOFTCFG_VARCNT; got += 1, s = e + 1) { values[got] = strtol (s, &e, 10); if ((values[got] < 0) || (e == s) || (got < XD3_SOFTCFG_VARCNT-1 && *e == 0) || (got == XD3_SOFTCFG_VARCNT-1 && *e != 0)) { XPR(NT "invalid string match specifier (-C) %d: %s\n", got, s); return EXIT_FAILURE; } } config.smatcher_soft.large_look = values[0]; config.smatcher_soft.large_step = values[1]; config.smatcher_soft.small_look = values[2]; config.smatcher_soft.small_chain = values[3]; config.smatcher_soft.small_lchain = values[4]; config.smatcher_soft.max_lazy = values[5]; config.smatcher_soft.long_enough = values[6]; } else { if (option_verbose > 2) { XPR(NT "compression level: %d\n", option_level); } if (option_level == 0) { stream_flags |= XD3_NOCOMPRESS; config.smatch_cfg = XD3_SMATCH_FASTEST; } else if (option_level == 1) { config.smatch_cfg = XD3_SMATCH_FASTEST; } else if (option_level == 2) { config.smatch_cfg = XD3_SMATCH_FASTER; } else if (option_level <= 5) { config.smatch_cfg = XD3_SMATCH_FAST; } else if (option_level == 6) { config.smatch_cfg = XD3_SMATCH_DEFAULT; } else { config.smatch_cfg = XD3_SMATCH_SLOW; } } break; #endif case CMD_DECODE: if (option_use_checksum == 0) { stream_flags |= XD3_ADLER32_NOVER; } ifile->flags |= RD_NONEXTERNAL; input_func = xd3_decode_input; output_func = main_write_output; break; default: XPR(NT "internal error\n"); return EXIT_FAILURE; } main_bsize = winsize = main_get_winsize (ifile); if ((main_bdata = (uint8_t*) main_bufalloc (winsize)) == NULL) { return EXIT_FAILURE; } config.winsize = winsize; config.getblk = main_getblk_func; config.flags = stream_flags; if ((ret = main_set_secondary_flags (&config)) || (ret = xd3_config_stream (& stream, & config))) { XPR(NT XD3_LIB_ERRMSG (& stream, ret)); return EXIT_FAILURE; } #if VCDIFF_TOOLS if ((cmd == CMD_MERGE || cmd == CMD_MERGE_ARG) && (ret = xd3_whole_state_init (& stream))) { XPR(NT XD3_LIB_ERRMSG (& stream, ret)); return EXIT_FAILURE; } #endif if (cmd != CMD_DECODE) { /* When not decoding, set source now. The decoder delays this * step until XD3_GOTHEADER. */ if (sfile && sfile->filename != NULL) { if ((ret = main_set_source (& stream, cmd, sfile, & source))) { return EXIT_FAILURE; } XD3_ASSERT(stream.src != NULL); } } if (cmd == CMD_PRINTHDR || cmd == CMD_PRINTHDRS || cmd == CMD_PRINTDELTA || cmd == CMD_RECODE) { if (sfile->filename == NULL) { allow_fake_source = 1; sfile->filename = "<placeholder>"; main_set_source (& stream, cmd, sfile, & source); } } /* This times each window. */ get_millisecs_since (); /* Main input loop. */ do { xoff_t input_offset; xoff_t input_remain; usize_t try_read; input_offset = ifile->nread; input_remain = XOFF_T_MAX - input_offset; try_read = (usize_t) min ((xoff_t) config.winsize, input_remain); if ((ret = main_read_primary_input (ifile, main_bdata, try_read, & nread))) { return EXIT_FAILURE; } /* If we've reached EOF tell the stream to flush. */ if (nread < try_read) { stream.flags |= XD3_FLUSH; } #if XD3_ENCODER /* After the first main_read_primary_input completes, we know * all the information needed to encode the application * header. */ if (cmd == CMD_ENCODE && (ret = main_set_appheader (& stream, ifile, sfile))) { return EXIT_FAILURE; } #endif xd3_avail_input (& stream, main_bdata, nread); /* If we read zero bytes after encoding at least one window... */ if (nread == 0 && stream.current_window > 0) { break; } again: ret = input_func (& stream); switch (ret) { case XD3_INPUT: continue; case XD3_GOTHEADER: { XD3_ASSERT (stream.current_window == 0); /* Need to process the appheader as soon as possible. It may * contain a suggested default filename/decompression routine for * the ofile, and it may contain default/decompression routine for * the sources. */ if (cmd == CMD_DECODE) { /* May need to set the sfile->filename if none was given. */ main_get_appheader (& stream, ifile, ofile, sfile); /* Now open the source file. */ if ((sfile->filename != NULL) && (ret = main_set_source (& stream, cmd, sfile, & source))) { return EXIT_FAILURE; } } } /* FALLTHROUGH */ case XD3_WINSTART: { /* e.g., set or unset XD3_SKIP_WINDOW. */ goto again; } case XD3_OUTPUT: { /* Defer opening the output file until the stream produces its * first output for both encoder and decoder, this way we * delay long enough for the decoder to receive the * application header. (Or longer if there are skipped * windows, but I can't think of any reason not to delay * open.) */ if (ofile != NULL && ! main_file_isopen (ofile) && (ret = main_open_output (& stream, ofile)) != 0) { return EXIT_FAILURE; } if ((ret = output_func (& stream, ofile)) && (ret != PRINTHDR_SPECIAL)) { return EXIT_FAILURE; } if (ret == PRINTHDR_SPECIAL) { xd3_abort_stream (& stream); ret = EXIT_SUCCESS; goto done; } ret = 0; xd3_consume_output (& stream); goto again; } case XD3_WINFINISH: { if (IS_ENCODE (cmd) || cmd == CMD_DECODE || cmd == CMD_RECODE) { if (! option_quiet && IS_ENCODE (cmd) && main_file_isopen (sfile)) { /* Warn when no source copies are found */ if (option_verbose && ! xd3_encoder_used_source (& stream)) { XPR(NT "warning: input window %"Q"u..%"Q"u has " "no source copies\n", stream.current_window * winsize, (stream.current_window+1) * winsize); XD3_ASSERT (stream.src != NULL); } /* Limited i-buffer size affects source copies * when the sourcewin is decided early. */ if (option_verbose > 1 && stream.srcwin_decided_early && stream.i_slots_used > stream.iopt_size) { XPR(NT "warning: input position %"Q"u overflowed " "instruction buffer, needed %u (vs. %u), " "consider changing -I\n", stream.current_window * winsize, stream.i_slots_used, stream.iopt_size); } } if (option_verbose) { shortbuf rrateavg, wrateavg, tm; shortbuf rdb, wdb; shortbuf trdb, twdb; shortbuf srcpos; long millis = get_millisecs_since (); usize_t this_read = (usize_t)(stream.total_in - last_total_in); usize_t this_write = (usize_t)(stream.total_out - last_total_out); last_total_in = stream.total_in; last_total_out = stream.total_out; if (option_verbose > 1) { XPR(NT "%"Q"u: in %s (%s): out %s (%s): " "total in %s: out %s: %s: srcpos %s\n", stream.current_window, main_format_bcnt (this_read, &rdb), main_format_rate (this_read, millis, &rrateavg), main_format_bcnt (this_write, &wdb), main_format_rate (this_write, millis, &wrateavg), main_format_bcnt (stream.total_in, &trdb), main_format_bcnt (stream.total_out, &twdb), main_format_millis (millis, &tm), main_format_bcnt (sfile->source_position, &srcpos)); } else { XPR(NT "%"Q"u: in %s: out %s: total in %s: " "out %s: %s\n", stream.current_window, main_format_bcnt (this_read, &rdb), main_format_bcnt (this_write, &wdb), main_format_bcnt (stream.total_in, &trdb), main_format_bcnt (stream.total_out, &twdb), main_format_millis (millis, &tm)); } } } goto again; } default: /* input_func() error */ XPR(NT XD3_LIB_ERRMSG (& stream, ret)); if (! option_quiet && ret == XD3_INVALID_INPUT) { XPR(NT "normally this indicates that the source file is incorrect\n"); XPR(NT "please verify the source file with sha1sum or equivalent\n"); } return EXIT_FAILURE; } } while (nread == config.winsize); done: /* Close the inputs. (ifile must be open, sfile may be open) */ main_file_close (ifile); if (sfile != NULL) { main_file_close (sfile); } #if VCDIFF_TOOLS if (cmd == CMD_MERGE && (ret = main_merge_output (& stream, ofile))) { return EXIT_FAILURE; } if (cmd == CMD_MERGE_ARG) { xd3_swap_whole_state (& stream.whole_target, & recode_stream->whole_target); } #endif /* VCDIFF_TOOLS */ /* If output file is not open yet because of delayed-open, it means * we never encountered a window in the delta, but it could have had * a VCDIFF header? TODO: solve this elsewhere. For now, it prints * "nothing to output" below, but the check doesn't happen in case * of option_no_output. */ if (! option_no_output && ofile != NULL) { if (!stdout_only && ! main_file_isopen (ofile)) { XPR(NT "nothing to output: %s\n", ifile->filename); return EXIT_FAILURE; } /* Have to close the output before calling * main_external_compression_finish, or else it hangs. */ if (main_file_close (ofile) != 0) { return EXIT_FAILURE; } } #if EXTERNAL_COMPRESSION if ((ret = main_external_compression_finish ())) { XPR(NT "external compression commands failed\n"); return EXIT_FAILURE; } #endif if ((ret = xd3_close_stream (& stream))) { XPR(NT XD3_LIB_ERRMSG (& stream, ret)); return EXIT_FAILURE; } #if XD3_ENCODER if (option_verbose > 1 && cmd == CMD_ENCODE) { XPR(NT "scanner configuration: %s\n", stream.smatcher.name); XPR(NT "target hash table size: %u\n", stream.small_hash.size); if (sfile != NULL && sfile->filename != NULL) { XPR(NT "source hash table size: %u\n", stream.large_hash.size); } } if (option_verbose > 2 && cmd == CMD_ENCODE) { XPR(NT "source copies: %"Q"u (%"Q"u bytes)\n", stream.n_scpy, stream.l_scpy); XPR(NT "target copies: %"Q"u (%"Q"u bytes)\n", stream.n_tcpy, stream.l_tcpy); XPR(NT "adds: %"Q"u (%"Q"u bytes)\n", stream.n_add, stream.l_add); XPR(NT "runs: %"Q"u (%"Q"u bytes)\n", stream.n_run, stream.l_run); } #endif xd3_free_stream (& stream); if (option_verbose) { shortbuf tm; long end_time = get_millisecs_now (); xoff_t nwrite = ofile != NULL ? ofile->nwrite : 0; XPR(NT "finished in %s; input %"Q"u output %"Q"u bytes (%0.2f%%)\n", main_format_millis (end_time - start_time, &tm), ifile->nread, nwrite, 100.0 * nwrite / ifile->nread); } return EXIT_SUCCESS; }
CWE-119
null
516,958
4172377301797425673661048747795120200
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
get_millisecs_since (void) { static long last = 0; long now = get_millisecs_now(); long diff = now - last; last = now; return diff; }
CWE-119
null
516,959
196310832266200097696683591346652515273
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_encode_decode_uint64_t (xd3_stream *stream, int unused) { TEST_ENCODE_DECODE_INTEGER(uint64_t,1ULL,UINT64_MAX); }
CWE-119
null
516,960
122620265264574364342526464074056369322
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_version (void) { /* $Format: " XPR(NTR \"Xdelta version $Xdelta3Version$, Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, Joshua MacDonald\\n\");" $ */ XPR(NTR "Xdelta version 3.0.8, Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Joshua MacDonald\n"); XPR(NTR "Xdelta comes with ABSOLUTELY NO WARRANTY.\n"); XPR(NTR "This is free software, and you are welcome to redistribute it\n"); XPR(NTR "under certain conditions; see \"COPYING\" for details.\n"); return EXIT_SUCCESS; }
CWE-119
null
516,961
84912480372611492810042339795562464099
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_recode_copy (xd3_stream* stream, xd3_output* output, xd3_desect* input) { int ret; XD3_ASSERT(output != NULL); XD3_ASSERT(output->next_page == NULL); if ((ret = xd3_decode_allocate (recode_stream, input->size, &output->base, &output->avail))) { XPR(NT XD3_LIB_ERRMSG (stream, ret)); return ret; } memcpy (output->base, /* Note: decoder advances buf, so get base of buffer with * buf_max - size */ input->buf_max - input->size, input->size); output->next = input->size; return 0; }
CWE-119
null
516,962
99578448493282537949561963231157653352
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_decode_integer_overflow (xd3_stream *stream, int unused) { return test_read_integer_error (stream, 0, "overflow in read_intger"); }
CWE-119
null
516,963
298113288453035646909193265254986049181
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_identical_behavior (xd3_stream *stream, int ignore) { #define IDB_TGTSZ 10000 /* Not a power of two b/c of hard-coded expectations below. */ #define IDB_BLKSZ 512 #define IDB_WINSZ 1000 #define IDB_DELSZ 1000 #define IDB_WINCNT (IDB_TGTSZ / IDB_WINSZ) int ret, i; uint8_t buf[IDB_TGTSZ]; uint8_t del[IDB_DELSZ]; uint8_t rec[IDB_TGTSZ]; xd3_source source; int nextencwin = 0; int winstarts = 0, winfinishes = 0; usize_t delpos = 0, recsize; xd3_config config; memset(&source, 0, sizeof(source)); for (i = 0; i < IDB_TGTSZ; i += 1) { buf[i] = (uint8_t) mt_random (&static_mtrand); } stream->winsize = IDB_WINSZ; source.blksize = IDB_BLKSZ; source.name = ""; source.curblk = NULL; source.curblkno = 0; if ((ret = xd3_set_source (stream, & source))) { goto fail; } /* Compute an delta between identical source and targets. */ for (;;) { ret = xd3_encode_input (stream); if (ret == XD3_INPUT) { xd3_avail_input (stream, buf + (IDB_WINSZ * nextencwin), IDB_WINSZ); nextencwin += 1; continue; } if (ret == XD3_GETSRCBLK) { source.curblkno = source.getblkno; source.onblk = IDB_BLKSZ; source.curblk = buf + source.getblkno * IDB_BLKSZ; continue; } if (ret == XD3_WINSTART) { winstarts++; continue; } if (ret == XD3_WINFINISH) { winfinishes++; if (winfinishes == IDB_WINCNT) { break; } continue; } if (ret != XD3_OUTPUT) { goto fail; } CHECK(delpos + stream->avail_out <= IDB_DELSZ); memcpy (del + delpos, stream->next_out, stream->avail_out); delpos += stream->avail_out; xd3_consume_output (stream); } CHECK(winfinishes == IDB_WINCNT); CHECK(winstarts == IDB_WINCNT); CHECK(nextencwin == IDB_WINCNT); /* Reset. */ memset(&source, 0, sizeof(source)); source.blksize = IDB_TGTSZ; source.onblk = IDB_TGTSZ; source.curblk = buf; source.curblkno = 0; if ((ret = xd3_close_stream (stream))) { goto fail; } xd3_free_stream (stream); xd3_init_config (& config, 0); if ((ret = xd3_config_stream (stream, & config))) { goto fail; } if ((ret = xd3_set_source_and_size (stream, & source, IDB_TGTSZ))) { goto fail; } /* Decode. */ if ((ret = xd3_decode_stream (stream, del, delpos, rec, & recsize, IDB_TGTSZ))) { goto fail; } /* Check result size and data. */ if (recsize != IDB_TGTSZ) { stream->msg = "wrong size reconstruction"; goto fail; } if (memcmp (rec, buf, IDB_TGTSZ) != 0) { stream->msg = "wrong data reconstruction"; goto fail; } /* Check that there was one copy per window. */ IF_DEBUG (if (stream->n_scpy != IDB_WINCNT || stream->n_add != 0 || stream->n_run != 0) { stream->msg = "wrong copy count"; goto fail; }); /* Check that no checksums were computed because the initial match was presumed. */ IF_DEBUG (if (stream->large_ckcnt != 0) { stream->msg = "wrong checksum behavior"; goto fail; }); ret = 0; fail: return ret; }
CWE-119
null
516,964
207334356551039998488338204028418880140
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_decode_integer_end_of_input (xd3_stream *stream, int unused) { return test_read_integer_error (stream, 1, "end-of-input in read_integer"); }
CWE-119
null
516,965
88052269115220652080104658571700197444
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_random_numbers (xd3_stream *stream, int ignore) { usize_t i; usize_t sum = 0; usize_t mean = 50; usize_t n_rounds = 1000000; double average, error; double allowed_error = 0.1; mt_init (& static_mtrand, 0x9f73f7fe); for (i = 0; i < n_rounds; i += 1) { sum += mt_exp_rand (mean, USIZE_T_MAX); } average = (double) sum / (double) n_rounds; error = average - (double) mean; if (error < allowed_error && error > -allowed_error) { return 0; } /*XPR(NT "error is %f\n", error);*/ stream->msg = "random distribution looks broken"; return XD3_INTERNAL; }
CWE-119
null
516,966
59503340586481903864887854462009367132
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
int main (int argc, char **argv) #endif { static const char *flags = "0123456789cdefhnqvDFJNORTVs:m:B:C:E:I:L:O:M:P:W:A::S::"; xd3_cmd cmd; main_file ifile; main_file ofile; main_file sfile; main_merge_list merge_order; main_merge *merge; int my_optind; const char *my_optarg; const char *my_optstr; const char *sfilename; int env_argc; char **env_argv; char **free_argv; /* malloc() in setup_environment() */ char *free_value; /* malloc() in setup_environment() */ int ret; #ifdef _WIN32 GetStartupInfo(&winStartupInfo); setvbuf(stderr, NULL, _IONBF, 0); /* Do not buffer stderr */ #endif main_file_init (& ifile); main_file_init (& ofile); main_file_init (& sfile); main_merge_list_init (& merge_order); reset_defaults(); free_argv = NULL; free_value = NULL; setup_environment(argc, argv, &env_argc, &env_argv, &free_argv, &free_value); cmd = CMD_NONE; sfilename = NULL; my_optind = 1; argv = env_argv; argc = env_argc; program_name = env_argv[0]; takearg: my_optarg = NULL; my_optstr = argv[my_optind]; /* This doesn't use getopt() because it makes trouble for -P & python which * reenter main() and thus care about freeing all memory. I never had much * trust for getopt anyway, it's too opaque. This implements a fairly * standard non-long-option getopt with support for named operations (e.g., * "xdelta3 [encode|decode|printhdr...] < in > out"). */ if (my_optstr) { if (*my_optstr == '-') { my_optstr += 1; } else if (cmd == CMD_NONE) { goto nonflag; } else { my_optstr = NULL; } } while (my_optstr) { const char *s; my_optarg = NULL; if ((ret = *my_optstr++) == 0) { my_optind += 1; goto takearg; } /* Option handling: first check for one ':' following the option in * flags, then check for two. The syntax allows: * * 1. -Afoo defines optarg="foo" * 2. -A foo defines optarg="foo" * 3. -A "" defines optarg="" (allows empty-string) * 4. -A [EOA or -moreargs] error (mandatory case) * 5. -A [EOA -moreargs] defines optarg=NULL (optional case) * 6. -A=foo defines optarg="foo" * 7. -A= defines optarg="" (mandatory case) * 8. -A= defines optarg=NULL (optional case) * * See tests in test_command_line_arguments(). */ s = strchr (flags, ret); if (s && s[1] && s[1] == ':') { int option = s[2] && s[2] == ':'; /* Case 1, set optarg to the remaining characters. */ my_optarg = my_optstr; my_optstr = ""; /* Case 2-5 */ if (*my_optarg == 0) { /* Condition 4-5 */ int have_arg = (my_optind < (argc - 1) && *argv[my_optind+1] != '-'); if (! have_arg) { if (! option) { /* Case 4 */ XPR(NT "-%c: requires an argument\n", ret); ret = EXIT_FAILURE; goto cleanup; } /* Case 5. */ my_optarg = NULL; } else { /* Case 2-3. */ my_optarg = argv[++my_optind]; } } /* Case 6-8. */ else if (*my_optarg == '=') { /* Remove the = in all cases. */ my_optarg += 1; if (option && *my_optarg == 0) { /* Case 8. */ my_optarg = NULL; } } } switch (ret) { /* case: if no '-' was found, maybe check for a command name. */ nonflag: if (strcmp (my_optstr, "decode") == 0) { cmd = CMD_DECODE; } else if (strcmp (my_optstr, "encode") == 0) { #if XD3_ENCODER cmd = CMD_ENCODE; #else XPR(NT "encoder support not compiled\n"); return EXIT_FAILURE; #endif } else if (strcmp (my_optstr, "config") == 0) { cmd = CMD_CONFIG; } #if REGRESSION_TEST else if (strcmp (my_optstr, "test") == 0) { cmd = CMD_TEST; } #endif #if VCDIFF_TOOLS else if (strcmp (my_optstr, "printhdr") == 0) { cmd = CMD_PRINTHDR; } else if (strcmp (my_optstr, "printhdrs") == 0) { cmd = CMD_PRINTHDRS; } else if (strcmp (my_optstr, "printdelta") == 0) { cmd = CMD_PRINTDELTA; } else if (strcmp (my_optstr, "recode") == 0) { cmd = CMD_RECODE; } else if (strcmp (my_optstr, "merge") == 0) { cmd = CMD_MERGE; } #endif /* If no option was found and still no command, let the default * command be encode. The remaining args are treated as * filenames. */ if (cmd == CMD_NONE) { cmd = CMD_DEFAULT; my_optstr = NULL; break; } else { /* But if we find a command name, continue the getopt loop. */ my_optind += 1; goto takearg; } /* gzip-like options */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': option_level = ret - '0'; break; case 'f': option_force = 1; break; case 'F': #if EXTERNAL_COMPRESSION option_force2 = 1; #else XPR(NT "warning: -F option ignored, " "external compression support was not compiled\n"); break; #endif case 'v': option_verbose += 1; option_quiet = 0; break; case 'q': option_quiet = 1; option_verbose = 0; break; case 'c': option_stdout = 1; break; case 'd': if (cmd == CMD_NONE) { cmd = CMD_DECODE; } else { ret = main_help (); goto exit; } break; case 'e': #if XD3_ENCODER if (cmd == CMD_NONE) { cmd = CMD_ENCODE; } else { ret = main_help (); goto exit; } break; #else XPR(NT "encoder support not compiled\n"); return EXIT_FAILURE; #endif case 'n': option_use_checksum = 0; break; case 'N': option_no_compress = 1; break; case 'T': option_use_altcodetable = 1; break; case 'C': option_smatch_config = my_optarg; break; case 'J': option_no_output = 1; break; case 'S': if (my_optarg == NULL) { option_use_secondary = 1; option_secondary = "none"; } else { option_use_secondary = 1; option_secondary = my_optarg; } break; case 'A': if (my_optarg == NULL) { option_use_appheader = 0; } else { option_appheader = (uint8_t*) my_optarg; } break; case 'B': { xoff_t bsize; if ((ret = main_atoux (my_optarg, & bsize, XD3_MINSRCWINSZ, XD3_MAXSRCWINSZ, 'B'))) { goto exit; } option_srcwinsz = bsize; break; } case 'I': if ((ret = main_atou (my_optarg, & option_iopt_size, 0, 0, 'I'))) { goto exit; } break; case 'P': if ((ret = main_atou (my_optarg, & option_sprevsz, 0, 0, 'P'))) { goto exit; } break; case 'W': if ((ret = main_atou (my_optarg, & option_winsize, XD3_ALLOCSIZE, XD3_HARDMAXWINSIZE, 'W'))) { goto exit; } break; case 'D': #if EXTERNAL_COMPRESSION == 0 if (option_verbose > 0) { XPR(NT "warning: -D option ignored, " "external compression support was not compiled\n"); } #else option_decompress_inputs = 0; #endif break; case 'R': #if EXTERNAL_COMPRESSION == 0 if (option_verbose > 0) { XPR(NT "warning: -R option ignored, " "external compression support was not compiled\n"); } #else option_recompress_outputs = 0; #endif break; case 's': if (sfilename != NULL) { XPR(NT "specify only one source file\n"); goto cleanup; } sfilename = my_optarg; break; case 'm': if ((merge = (main_merge*) main_malloc (sizeof (main_merge))) == NULL) { goto cleanup; } main_merge_list_push_back (& merge_order, merge); merge->filename = my_optarg; break; case 'V': ret = main_version (); goto exit; default: ret = main_help (); goto exit; } } option_source_filename = sfilename; /* In case there were no arguments, set the default command. */ if (cmd == CMD_NONE) { cmd = CMD_DEFAULT; } argc -= my_optind; argv += my_optind; /* There may be up to two more arguments. */ if (argc > 2) { XPR(NT "too many filenames: %s ...\n", argv[2]); goto cleanup; } ifile.flags = RD_FIRST | RD_MAININPUT; sfile.flags = RD_FIRST; sfile.filename = option_source_filename; /* The infile takes the next argument, if there is one. But if not, infile * is set to stdin. */ if (argc > 0) { ifile.filename = argv[0]; if ((ret = main_file_open (& ifile, ifile.filename, XO_READ))) { goto cleanup; } } else { XSTDIN_XF (& ifile); } /* The ofile takes the following argument, if there is one. But if not, it * is left NULL until the application header is processed. It will be set * in main_open_output. */ if (argc > 1) { /* Check for conflicting arguments. */ if (option_stdout && ! option_quiet) { XPR(NT "warning: -c option overrides output filename: %s\n", argv[1]); } if (! option_stdout) { ofile.filename = argv[1]; } } #if VCDIFF_TOOLS if (cmd == CMD_MERGE && (ret = main_merge_arguments (&merge_order))) { goto cleanup; } #endif /* VCDIFF_TOOLS */ switch (cmd) { case CMD_PRINTHDR: case CMD_PRINTHDRS: case CMD_PRINTDELTA: #if XD3_ENCODER case CMD_ENCODE: case CMD_RECODE: case CMD_MERGE: #endif case CMD_DECODE: ret = main_input (cmd, & ifile, & ofile, & sfile); break; #if REGRESSION_TEST case CMD_TEST: main_config (); ret = xd3_selftest (); break; #endif case CMD_CONFIG: ret = main_config (); break; default: ret = main_help (); break; } if (0) { cleanup: ret = EXIT_FAILURE; exit: (void)0; } #if EXTERNAL_COMPRESSION main_external_compression_cleanup (); #endif main_file_cleanup (& ifile); main_file_cleanup (& ofile); main_file_cleanup (& sfile); while (! main_merge_list_empty (& merge_order)) { merge = main_merge_list_pop_front (& merge_order); main_free (merge); } main_free (free_argv); main_free (free_value); main_cleanup (); fflush (stdout); fflush (stderr); return ret; }
CWE-119
null
516,967
26169038614337292396646293692460322030
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_cleanup (void) { if (appheader_used != NULL && appheader_used != option_appheader) { main_free (appheader_used); appheader_used = NULL; } main_buffree (main_bdata); main_bdata = NULL; main_bsize = 0; main_lru_cleanup(); if (recode_stream != NULL) { xd3_free_stream (recode_stream); main_free (recode_stream); recode_stream = NULL; } if (merge_stream != NULL) { xd3_free_stream (merge_stream); main_free (merge_stream); merge_stream = NULL; } XD3_ASSERT (main_mallocs == 0); }
CWE-119
null
516,968
53122537938574038363490332500400512186
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_decompress_text (xd3_stream *stream, uint8_t *enc, usize_t enc_size, usize_t test_desize) { xd3_config cfg; char decoded[sizeof (test_text)]; uint8_t *apphead; usize_t apphead_size; usize_t decoded_size; const char *msg; int ret; usize_t pos = 0; int flags = stream->flags; usize_t take; input: /* Test decoding test_desize input bytes at a time */ take = min (enc_size - pos, test_desize); CHECK(take > 0); xd3_avail_input (stream, enc + pos, take); again: ret = xd3_decode_input (stream); pos += take; take = 0; switch (ret) { case XD3_OUTPUT: break; case XD3_WINSTART: case XD3_GOTHEADER: goto again; case XD3_INPUT: if (pos < enc_size) { goto input; } /* else fallthrough */ case XD3_WINFINISH: default: goto fail; } CHECK(ret == XD3_OUTPUT); CHECK(pos == enc_size); if (stream->avail_out != sizeof (test_text)) { stream->msg = "incorrect output size"; ret = XD3_INTERNAL; goto fail; } decoded_size = stream->avail_out; memcpy (decoded, stream->next_out, stream->avail_out); xd3_consume_output (stream); if ((ret = xd3_get_appheader (stream, & apphead, & apphead_size))) { goto fail; } if (apphead_size != strlen ((char*) test_apphead) || memcmp (apphead, test_apphead, strlen ((char*) test_apphead)) != 0) { stream->msg = "incorrect appheader"; ret = XD3_INTERNAL; goto fail; } if ((ret = xd3_decode_input (stream)) != XD3_WINFINISH || (ret = xd3_close_stream (stream)) != 0) { goto fail; } if (decoded_size != sizeof (test_text) || memcmp (decoded, test_text, sizeof (test_text)) != 0) { stream->msg = "incorrect output text"; ret = EIO; } fail: msg = stream->msg; xd3_free_stream (stream); xd3_init_config (& cfg, flags); xd3_config_stream (stream, & cfg); stream->msg = msg; return ret; }
CWE-119
null
516,969
139720720268570328083084962196009213430
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_recode_command (xd3_stream *stream, int ignore) { /* Things to test: * - with and without a source file (recode does not change) * * (recode may or may not change -- 8 variations) * - with and without adler32 * - with and without app header * - with and without secondary */ int has_source; int variant; int change; int ret; for (has_source = 0; has_source < 2; has_source++) { for (variant = 0; variant < 8; variant++) { for (change = 0; change < 8; change++) { if ((ret = test_recode_command2 (stream, has_source, variant, change))) { return ret; } } DOT (); } } return 0; }
CWE-119
null
516,970
90109695439033127236234835235912563969
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_set_secondary_flags (xd3_config *config) { int ret; if (option_use_secondary) { /* The default secondary compressor is DJW, if it's compiled. */ if (option_secondary == NULL) { if (SECONDARY_DJW) { config->flags |= XD3_SEC_DJW; } } else { if (strcmp (option_secondary, "fgk") == 0 && SECONDARY_FGK) { config->flags |= XD3_SEC_FGK; } else if (strcmp (option_secondary, "lzma") == 0 && SECONDARY_LZMA) { config->flags |= XD3_SEC_LZMA; } else if (strncmp (option_secondary, "djw", 3) == 0 && SECONDARY_DJW) { usize_t level = XD3_DEFAULT_SECONDARY_LEVEL; config->flags |= XD3_SEC_DJW; if (strlen (option_secondary) > 3 && (ret = main_atou (option_secondary + 3, &level, 0, 9, 'S')) != 0 && !option_quiet) { return XD3_INVALID; } /* XD3_SEC_NOXXXX flags disable secondary compression on * a per-section basis. For djw, ngroups=1 indicates * minimum work, ngroups=0 uses default settings, which * is > 1 groups by default. */ if (level < 1) { config->flags |= XD3_SEC_NODATA; } if (level < 7) { config->sec_data.ngroups = 1; } else { config->sec_data.ngroups = 0; } if (level < 3) { config->flags |= XD3_SEC_NOINST; } if (level < 8) { config->sec_inst.ngroups = 1; } else { config->sec_inst.ngroups = 0; } if (level < 5) { config->flags |= XD3_SEC_NOADDR; } if (level < 9) { config->sec_addr.ngroups = 1; } else { config->sec_addr.ngroups = 0; } } else if (strcmp (option_secondary, "none") == 0 && SECONDARY_DJW) { /* No secondary */ } else { if (!option_quiet) { XPR(NT "unrecognized secondary compressor type: %s\n", option_secondary); return XD3_INVALID; } } } } return 0; }
CWE-119
null
516,971
217523143854664585388291946143839554306
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_secondary_decompress_check (main_file *file, uint8_t *input_buf, size_t input_size, size_t *nread) { int ret; usize_t i; usize_t try_read = min (input_size, XD3_ALLOCSIZE); size_t check_nread = 0; uint8_t check_buf[XD3_ALLOCSIZE]; /* TODO: stack limit */ const main_extcomp *decompressor = NULL; if ((ret = main_file_read (file, check_buf, try_read, & check_nread, "input read failed"))) { return ret; } if (file->flags & RD_DECOMPSET) { /* This allows the application header to override the magic * number, for whatever reason. */ decompressor = file->compressor; } else { for (i = 0; i < SIZEOF_ARRAY (extcomp_types); i += 1) { const main_extcomp *decomp = & extcomp_types[i]; if (check_nread > decomp->magic_size) { /* The following expr checks if we are trying to read a * VCDIFF input, in which case do not treat it as * "secondary" decompression. */ int skip_this_type = (decomp->flags & RD_NONEXTERNAL) && (file->flags & RD_NONEXTERNAL); if (skip_this_type) { continue; } if (memcmp (check_buf, decomp->magic, decomp->magic_size) == 0) { decompressor = decomp; break; } } } } if (decompressor != NULL) { if (! option_quiet) { XPR(NT "externally compressed input: %s %s%s < %s\n", decompressor->decomp_cmdname, decompressor->decomp_options, (option_force2 ? " -f" : ""), file->filename); if (file->flags & RD_MAININPUT) { XPR(NT "WARNING: the encoder is automatically decompressing the input file;\n"); XPR(NT "WARNING: the decoder will automatically recompress the output file;\n"); XPR(NT "WARNING: this may result in different compressed data and checksums\n"); XPR(NT "WARNING: despite being identical data; if this is an issue, use -D\n"); XPR(NT "WARNING: to avoid decompression and/or use -R to avoid recompression\n"); XPR(NT "WARNING: and/or manually decompress the input file; if you know the\n"); XPR(NT "WARNING: compression settings that will produce identical output\n"); XPR(NT "WARNING: you may set those flags using the environment (e.g., GZIP=-9)\n"); } } file->size_known = 0; return main_input_decompress_setup (decompressor, file, input_buf, input_size, check_buf, XD3_ALLOCSIZE, check_nread, nread); } /* Now read the rest of the input block. */ (*nread) = 0; if (check_nread == try_read) { ret = main_file_read (file, input_buf + try_read, input_size - try_read, nread, "input read failed"); } memcpy (input_buf, check_buf, check_nread); (*nread) += check_nread; return 0; }
CWE-119
null
516,972
270772098718946329566568558440289027508
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_encode_decode_uint32_t (xd3_stream *stream, int unused) { TEST_ENCODE_DECODE_INTEGER(uint32_t,1U,UINT32_MAX); }
CWE-119
null
516,973
242915521384696349114342754854677053331
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_file_isopen (main_file *xfile) { #if XD3_STDIO return xfile->file != NULL; #elif XD3_POSIX return xfile->file != -1; #elif XD3_WIN32 return xfile->file != INVALID_HANDLE_VALUE; #endif }
CWE-119
null
516,974
316313536617344838859050268663328863789
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_encode_code_table (xd3_stream *stream, int ignore) { int ret; const uint8_t *comp_data; usize_t comp_size; if ((ret = xd3_compute_alternate_table_encoding (stream, & comp_data, & comp_size))) { return ret; } stream->acache.s_near = __alternate_code_table_desc.near_modes; stream->acache.s_same = __alternate_code_table_desc.same_modes; if ((ret = xd3_apply_table_encoding (stream, comp_data, comp_size))) { return ret; } if (memcmp (stream->code_table, xd3_alternate_code_table (), sizeof (xd3_dinst) * 256) != 0) { stream->msg = "wrong code table reconstruction"; return XD3_INTERNAL; } return 0; }
CWE-119
null
516,975
37163802571622726960159663033035493202
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
void main_buffree (void *ptr) { #if XD3_WIN32 VirtualFree(ptr, 0, MEM_RELEASE); #else main_free1(NULL, ptr); #endif }
CWE-119
null
516,976
227681862203312427183478256819413649252
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
sec_dist_func9 (xd3_stream *stream, xd3_output *data) { int i, ret; int ramp = 0; int rcount = 0; int prom = 0; int pcount = 0; /* 200 was long enough to trigger it--only when stricter checking * that counted all blocks was turned on, but it seems I deleted * this code. (missing fgk_free_block on line 398). */ for (i = 0; i < ALPHABET_SIZE*200; i += 1) { repeat: if (ramp < ALPHABET_SIZE) { /* Initially Nth symbol has (N+1) frequency */ if (rcount <= ramp) { rcount += 1; if ((ret = xd3_emit_byte (stream, & data, ramp))) { return ret; } continue; } ramp += 1; rcount = 0; goto repeat; } /* Thereafter, promote least freq to max freq */ if (pcount == ALPHABET_SIZE) { pcount = 0; prom = (prom + 1) % ALPHABET_SIZE; } pcount += 1; if ((ret = xd3_emit_byte (stream, & data, prom))) { return ret; } } return 0; }
CWE-119
null
516,977
135439571931389446124757591728286516084
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_format_rate (xoff_t bytes, long millis, shortbuf *buf) { xoff_t r = (xoff_t)(1.0 * bytes / (1.0 * millis / 1000.0)); static shortbuf lbuf; main_format_bcnt (r, &lbuf); short_sprintf (*buf, "%s/s", lbuf.buf); return buf->buf; }
CWE-119
null
516,978
45014718879996159989141171443121082769
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
check_vcdiff_header (xd3_stream *stream, const char *input, const char *line_start, const char *matches, int yes_or_no) { int ret; char vcmd[TESTBUFSIZE], gcmd[TESTBUFSIZE]; snprintf_func (vcmd, TESTBUFSIZE, "%s printhdr -f %s %s", program_name, input, TEST_RECON2_FILE); if ((ret = system (vcmd)) != 0) { XPR(NT "printhdr command: %s\n", vcmd); stream->msg = "printhdr cmd failed"; return XD3_INTERNAL; } snprintf_func (gcmd, TESTBUFSIZE, "grep \"%s.*%s.*\" %s > /dev/null", line_start, matches, TEST_RECON2_FILE); if (yes_or_no) { if ((ret = do_cmd (stream, gcmd))) { XPR(NT "%s\n", gcmd); return ret; } } else { if ((ret = do_fail (stream, gcmd))) { XPR(NT "%s\n", gcmd); return ret; } } return 0; }
CWE-119
null
516,979
202532517293920961055822445566688164224
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_strtoxoff (const char* s, xoff_t *xo, char which) { char *e; xoff_t x; XD3_ASSERT(s && *s != 0); { /* Should check LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX? */ #if SIZEOF_XOFF_T == 4 long xx = strtol (s, &e, 0); #else long long xx = strtoll (s, &e, 0); #endif if (xx < 0) { XPR(NT "-%c: negative integer: %s\n", which, s); return EXIT_FAILURE; } x = xx; } if (*e != 0) { XPR(NT "-%c: invalid integer: %s\n", which, s); return EXIT_FAILURE; } (*xo) = x; return 0; }
CWE-119
null
516,980
191206620803046045540021924765244126317
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
xd3_posix_io (int fd, uint8_t *buf, size_t size, xd3_posix_func *func, size_t *nread) { int ret; size_t nproc = 0; while (nproc < size) { size_t tryread = min(size - nproc, 1U << 30); ssize_t result = (*func) (fd, buf + nproc, tryread); if (result < 0) { ret = get_errno (); if (ret != EAGAIN && ret != EINTR) { return ret; } continue; } if (nread != NULL && result == 0) { break; } nproc += result; } if (nread != NULL) { (*nread) = nproc; } return 0; }
CWE-119
null
516,981
222798449677428690490059815953081884835
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
uint32_t mt_random (mtrand *mt) { uint32_t y; unsigned long mag01[2]; mag01[0] = 0; mag01[1] = MATRIX_A; if (mt->mt_index_ >= MT_LEN) { int kk; for (kk = 0; kk < MT_LEN - MT_IA; kk++) { y = (mt->mt_buffer_[kk] & UPPER_MASK) | (mt->mt_buffer_[kk + 1] & LOWER_MASK); mt->mt_buffer_[kk] = mt->mt_buffer_[kk + MT_IA] ^ (y >> 1) ^ mag01[y & 0x1UL]; } for (;kk < MT_LEN - 1; kk++) { y = (mt->mt_buffer_[kk] & UPPER_MASK) | (mt->mt_buffer_[kk + 1] & LOWER_MASK); mt->mt_buffer_[kk] = mt->mt_buffer_[kk + (MT_IA - MT_LEN)] ^ (y >> 1) ^ mag01[y & 0x1UL]; } y = (mt->mt_buffer_[MT_LEN - 1] & UPPER_MASK) | (mt->mt_buffer_[0] & LOWER_MASK); mt->mt_buffer_[MT_LEN - 1] = mt->mt_buffer_[MT_IA - 1] ^ (y >> 1) ^ mag01[y & 0x1UL]; mt->mt_index_ = 0; } y = mt->mt_buffer_[mt->mt_index_++]; y ^= (y >> 11); y ^= (y << 7) & 0x9d2c5680UL; y ^= (y << 15) & 0xefc60000UL; y ^= (y >> 18); return y; }
CWE-119
null
516,982
176399244289827693731057953374115007171
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_command_line_arguments (xd3_stream *stream, int ignore) { int i, ret; static const char* cmdpairs[] = { /* standard input, output */ "%s %s -A < %s > %s", "%s -d < %s > %s", "%s %s -A -e < %s > %s", "%s -d < %s > %s", "%s %s -A= encode < %s > %s", "%s decode < %s > %s", "%s %s -A -q encode < %s > %s", "%s -qdq < %s > %s", /* file input, standard output */ "%s %s -A= %s > %s", "%s -d %s > %s", "%s %s -A -e %s > %s", "%s -d %s > %s", "%s %s encode -A= %s > %s", "%s decode %s > %s", /* file input, output */ "%s %s -A= %s %s", "%s -d %s %s", "%s %s -A -e %s %s", "%s -d %s %s", "%s %s -A= encode %s %s", "%s decode %s %s", /* option placement */ "%s %s -A -f %s %s", "%s -f -d %s %s", "%s %s -e -A= %s %s", "%s -d -f %s %s", "%s %s -f encode -A= %s %s", "%s -f decode -f %s %s", }; char ecmd[TESTBUFSIZE], dcmd[TESTBUFSIZE]; int pairs = SIZEOF_ARRAY (cmdpairs) / 2; xoff_t tsize; xoff_t dsize; double ratio; mt_init (& static_mtrand, 0x9f73f7fc); for (i = 0; i < pairs; i += 1) { test_setup (); if ((ret = test_make_inputs (stream, NULL, & tsize))) { return ret; } snprintf_func (ecmd, TESTBUFSIZE, cmdpairs[2*i], program_name, test_softcfg_str, TEST_TARGET_FILE, TEST_DELTA_FILE); snprintf_func (dcmd, TESTBUFSIZE, cmdpairs[2*i+1], program_name, TEST_DELTA_FILE, TEST_RECON_FILE); /* Encode and decode. */ if ((ret = system (ecmd)) != 0) { XPR(NT "encode command: %s\n", ecmd); stream->msg = "encode cmd failed"; return XD3_INTERNAL; } if ((ret = system (dcmd)) != 0) { XPR(NT "decode command: %s\n", dcmd); stream->msg = "decode cmd failed"; return XD3_INTERNAL; } /* Compare the target file. */ if ((ret = test_compare_files (TEST_TARGET_FILE, TEST_RECON_FILE))) { return ret; } if ((ret = test_file_size (TEST_DELTA_FILE, & dsize))) { return ret; } ratio = (double) dsize / (double) tsize; /* Check that it is not too small, not too large. */ if (ratio >= TEST_ADD_RATIO + TEST_EPSILON) { XPR(NT "test encode with size ratio %.4f, " "expected < %.4f (%"Q"u, %"Q"u)\n", ratio, TEST_ADD_RATIO + TEST_EPSILON, dsize, tsize); stream->msg = "strange encoding"; return XD3_INTERNAL; } if (ratio <= TEST_ADD_RATIO * (1.0 - 2 * TEST_EPSILON)) { XPR(NT "test encode with size ratio %.4f, " "expected > %.4f\n", ratio, TEST_ADD_RATIO - TEST_EPSILON); stream->msg = "strange encoding"; return XD3_INTERNAL; } /* Also check that test_compare_files works. The delta and original should * not be identical. */ if ((ret = test_compare_files (TEST_DELTA_FILE, TEST_TARGET_FILE)) == 0) { stream->msg = "broken test_compare_files"; return XD3_INTERNAL; } test_cleanup (); DOT (); } return 0; }
CWE-119
null
516,983
149007564217400256682269973586374857801
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_ident_compressor (const char *ident) { usize_t i; for (i = 0; i < SIZEOF_ARRAY (extcomp_types); i += 1) { if (strcmp (extcomp_types[i].ident, ident) == 0) { return & extcomp_types[i]; } } return NULL; }
CWE-119
null
516,984
247309301225780511651599625881568132501
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_input_decompress_setup (const main_extcomp *decomp, main_file *ifile, uint8_t *input_buf, usize_t input_bufsize, uint8_t *pipe_buf, usize_t pipe_bufsize, usize_t pipe_avail, size_t *nread) { /* The two pipes: input and output file descriptors. */ int outpipefd[2], inpipefd[2]; int input_fd = -1; /* The resulting input_fd (output of decompression). */ pid_t decomp_id, copier_id; /* The two subprocs. */ int ret; outpipefd[0] = outpipefd[1] = -1; inpipefd[0] = inpipefd[1] = -1; if (pipe (outpipefd) || pipe (inpipefd)) { XPR(NT "pipe failed: %s\n", xd3_mainerror (ret = get_errno ())); goto pipe_cleanup; } if ((decomp_id = fork ()) < 0) { XPR(NT "fork failed: %s\n", xd3_mainerror (ret = get_errno ())); goto pipe_cleanup; } /* The first child runs the decompression process: */ if (decomp_id == 0) { if (option_verbose > 2) { XPR(NT "external decompression pid %d\n", getpid ()); } /* Setup pipes: write to the outpipe, read from the inpipe. */ if (dup2 (outpipefd[PIPE_WRITE_FD], STDOUT_FILENO) < 0 || dup2 (inpipefd[PIPE_READ_FD], STDIN_FILENO) < 0 || close (outpipefd[PIPE_READ_FD]) || close (outpipefd[PIPE_WRITE_FD]) || close (inpipefd[PIPE_READ_FD]) || close (inpipefd[PIPE_WRITE_FD]) || execlp (decomp->decomp_cmdname, decomp->decomp_cmdname, decomp->decomp_options, option_force2 ? "-f" : NULL, NULL)) { XPR(NT "child process %s failed to execute: %s\n", decomp->decomp_cmdname, xd3_mainerror (get_errno ())); } _exit (127); } XD3_ASSERT(num_subprocs < MAX_SUBPROCS); ext_subprocs[num_subprocs++] = decomp_id; if ((copier_id = fork ()) < 0) { XPR(NT "fork failed: %s\n", xd3_mainerror (ret = get_errno ())); goto pipe_cleanup; } /* The second child runs the copier process: */ if (copier_id == 0) { int exitval = 0; if (option_verbose > 2) { XPR(NT "child pipe-copier pid %d\n", getpid ()); } if (close (inpipefd[PIPE_READ_FD]) || close (outpipefd[PIPE_READ_FD]) || close (outpipefd[PIPE_WRITE_FD]) || main_pipe_copier (pipe_buf, pipe_bufsize, pipe_avail, ifile, inpipefd[PIPE_WRITE_FD]) || close (inpipefd[PIPE_WRITE_FD])) { XPR(NT "child copier process failed: %s\n", xd3_mainerror (get_errno ())); exitval = 1; } _exit (exitval); } XD3_ASSERT(num_subprocs < MAX_SUBPROCS); ext_subprocs[num_subprocs++] = copier_id; /* The parent closes both pipes after duplicating the output of * compression. */ input_fd = dup (outpipefd[PIPE_READ_FD]); if (input_fd < 0 || main_file_close (ifile) || close (outpipefd[PIPE_READ_FD]) || close (outpipefd[PIPE_WRITE_FD]) || close (inpipefd[PIPE_READ_FD]) || close (inpipefd[PIPE_WRITE_FD])) { XPR(NT "dup/close failed: %s\n", xd3_mainerror (ret = get_errno ())); goto pipe_cleanup; } #if XD3_STDIO /* Note: fdopen() acquires the fd, closes it when finished. */ if ((ifile->file = fdopen (input_fd, "r")) == NULL) { XPR(NT "fdopen failed: %s\n", xd3_mainerror (ret = get_errno ())); goto pipe_cleanup; } #elif XD3_POSIX ifile->file = input_fd; #endif ifile->compressor = decomp; /* Now the input file is decompressed. */ return main_file_read (ifile, input_buf, input_bufsize, nread, "input decompression failed"); pipe_cleanup: close (input_fd); close (outpipefd[PIPE_READ_FD]); close (outpipefd[PIPE_WRITE_FD]); close (inpipefd[PIPE_READ_FD]); close (inpipefd[PIPE_WRITE_FD]); return ret; }
CWE-119
null
516,985
207144299162958451053213587602525267645
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_externally_compressed_io (xd3_stream *stream, int ignore) { usize_t i; int ret; char buf[TESTBUFSIZE]; mt_init (& static_mtrand, 0x9f73f7fc); if ((ret = test_make_inputs (stream, NULL, NULL))) { return ret; } for (i = 0; i < SIZEOF_ARRAY (extcomp_types); i += 1) { main_extcomp *ext = & extcomp_types[i]; /* Test for the existence of the external command first, if not skip. */ snprintf_func (buf, TESTBUFSIZE, "%s %s < /dev/null > /dev/null", ext->recomp_cmdname, ext->recomp_options); if ((ret = system (buf)) != 0) { XPR(NT "%s=0", ext->recomp_cmdname); continue; } if ((ret = test_compressed_pipe (stream, ext, buf, "-cfq", "-dcfq", 1, "compression failed: identity pipe")) || (ret = test_compressed_pipe (stream, ext, buf, "-cfq", "-Rdcfq", 0, "compression failed: without recompression")) || (ret = test_compressed_pipe (stream, ext, buf, "-Dcfq", "-Rdcfq", 1, "compression failed: without decompression"))) { return ret; } } return 0; }
CWE-119
null
516,986
19530670255586203989391334504220286860
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_free1 (void *opaque, void *ptr) { free (ptr); }
CWE-119
null
516,987
102592390276130212461458364896017921326
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_no_output (xd3_stream *stream, int ignore) { int ret; char buf[TESTBUFSIZE]; test_setup (); snprintf_func (buf, TESTBUFSIZE, "touch %s && chmod 0000 %s", TEST_NOPERM_FILE, TEST_NOPERM_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } if ((ret = test_make_inputs (stream, NULL, NULL))) { return ret; } /* Try no_output encode w/out unwritable output file */ snprintf_func (buf, TESTBUFSIZE, "%s -q -f -e %s %s", program_name, TEST_TARGET_FILE, TEST_NOPERM_FILE); if ((ret = do_fail (stream, buf))) { return ret; } snprintf_func (buf, TESTBUFSIZE, "%s -J -e %s %s", program_name, TEST_TARGET_FILE, TEST_NOPERM_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } /* Now really write the delta to test decode no-output */ snprintf_func (buf, TESTBUFSIZE, "%s -e %s %s", program_name, TEST_TARGET_FILE, TEST_DELTA_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } snprintf_func (buf, TESTBUFSIZE, "%s -q -f -d %s %s", program_name, TEST_DELTA_FILE, TEST_NOPERM_FILE); if ((ret = do_fail (stream, buf))) { return ret; } snprintf_func (buf, TESTBUFSIZE, "%s -J -d %s %s", program_name, TEST_DELTA_FILE, TEST_NOPERM_FILE); if ((ret = do_cmd (stream, buf))) { return ret; } test_cleanup (); return 0; }
CWE-119
null
516,988
137420505775174060064962704611284556711
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_merge_func (xd3_stream* stream, main_file *no_write) { int ret; if ((ret = xd3_whole_append_window (stream))) { return ret; } return 0; }
CWE-119
null
516,989
115516123813308321255171399388161549562
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_unlink (char* file) { int ret; if ((ret = unlink (file)) != 0 && errno != ENOENT) { XPR(NT "unlink %s failed: %s\n", file, strerror(ret)); } }
CWE-119
null
516,990
293261053231389884195718156600769939050
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
sec_dist_func11 (xd3_stream *stream, xd3_output *data) { int sum0 = 0; int sum1 = 1; int i, j, ret; for (i = 0; i < 33; ++i) { for (j = 0; j < (sum0 + sum1); ++j) { if ((ret = xd3_emit_byte (stream, & data, i))) { return ret; } } sum0 = sum1; sum1 = j; } return 0; }
CWE-119
null
516,991
172363366897591769184849886864057170046
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
test_choose_instruction (xd3_stream *stream, int ignore) { int i; stream->code_table = (*stream->code_table_func) (); for (i = 0; i < 256; i += 1) { const xd3_dinst *d = stream->code_table + i; xd3_rinst prev, inst; CHECK(d->type1 > 0); memset (& prev, 0, sizeof (prev)); memset (& inst, 0, sizeof (inst)); if (d->type2 == 0) { inst.type = d->type1; if ((inst.size = d->size1) == 0) { inst.size = TESTBUFSIZE; } XD3_CHOOSE_INSTRUCTION (stream, NULL, & inst); if (inst.code2 != 0 || inst.code1 != i) { stream->msg = "wrong single instruction"; return XD3_INTERNAL; } } else { prev.type = d->type1; prev.size = d->size1; inst.type = d->type2; inst.size = d->size2; XD3_CHOOSE_INSTRUCTION (stream, & prev, & inst); if (prev.code2 != i) { stream->msg = "wrong double instruction"; return XD3_INTERNAL; } } } return 0; }
CWE-119
null
516,992
2889271563474897674284785470879434321
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_apphead_string (const char* x) { const char *y; if (x == NULL) { return ""; } if (strcmp (x, "/dev/stdin") == 0 || strcmp (x, "/dev/stdout") == 0 || strcmp (x, "/dev/stderr") == 0) { return "-"; } // TODO: this is not portable return (y = strrchr (x, '/')) == NULL ? x : y + 1; }
CWE-119
null
516,993
319615824837794372939391340048400389015
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_atou (const char* arg, usize_t *uo, usize_t low, usize_t high, char which) { int ret; xoff_t xo; if ((ret = main_atoux (arg, &xo, low, high, which))) { return ret; } *uo = (usize_t)xo; return 0; }
CWE-119
null
516,994
15112830216974808852423472285205651704
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_open_output (xd3_stream *stream, main_file *ofile) { int ret; if (option_no_output) { return 0; } if (ofile->filename == NULL) { XSTDOUT_XF (ofile); if (option_verbose > 1) { XPR(NT "using standard output: %s\n", ofile->filename); } } else { /* Stat the file to check for overwrite. */ if (option_force == 0 && main_file_exists (ofile)) { if (!option_quiet) { XPR(NT "to overwrite output file specify -f: %s\n", ofile->filename); } return EEXIST; } if ((ret = main_file_open (ofile, ofile->filename, XO_WRITE))) { return ret; } if (option_verbose > 1) { XPR(NT "output %s\n", ofile->filename); } } #if EXTERNAL_COMPRESSION /* Do output recompression. */ if (ofile->compressor != NULL && option_recompress_outputs == 1) { if (! option_quiet) { XPR(NT "externally compressed output: %s %s%s > %s\n", ofile->compressor->recomp_cmdname, ofile->compressor->recomp_options, (option_force2 ? " -f" : ""), ofile->filename); } if ((ret = main_recompress_output (ofile))) { return ret; } } #endif return 0; }
CWE-119
null
516,995
175458052488550852688260020610331821347
null
null
other
xdelta-devel
ef93ff74203e030073b898c05e8b4860b5d09ef2
0
main_merge_output (xd3_stream *stream, main_file *ofile) { int ret; usize_t inst_pos = 0; xoff_t output_pos = 0; xd3_source recode_source; usize_t window_num = 0; int at_least_once = 0; /* merge_stream is set if there were arguments. this stream's input * needs to be applied to the merge_stream source. */ if ((merge_stream != NULL) && (ret = xd3_merge_input_output (stream, & merge_stream->whole_target))) { XPR(NT XD3_LIB_ERRMSG (stream, ret)); return ret; } if (option_use_appheader != 0 && option_appheader != NULL) { xd3_set_appheader (recode_stream, option_appheader, (usize_t) strlen ((char*) option_appheader)); } /* Enter the ENC_INPUT state and bypass the next_in == NULL test * and (leftover) input buffering logic. */ XD3_ASSERT(recode_stream->enc_state == ENC_INIT); recode_stream->enc_state = ENC_INPUT; recode_stream->next_in = main_bdata; recode_stream->flags |= XD3_FLUSH; /* This encodes the entire target. */ while (inst_pos < stream->whole_target.instlen || !at_least_once) { xoff_t window_start = output_pos; int window_srcset = 0; xoff_t window_srcmin = 0; xoff_t window_srcmax = 0; usize_t window_pos = 0; usize_t window_size; /* at_least_once ensures that we encode at least one window, * which handles the 0-byte case. */ at_least_once = 1; XD3_ASSERT (recode_stream->enc_state == ENC_INPUT); if ((ret = xd3_encode_input (recode_stream)) != XD3_WINSTART) { XPR(NT "invalid merge state: %s\n", xd3_mainerror (ret)); return XD3_INVALID; } /* Window sizes must match from the input to the output, so that * target copies are in-range (and so that checksums carry * over). */ XD3_ASSERT (window_num < stream->whole_target.wininfolen); window_size = stream->whole_target.wininfo[window_num].length; /* Output position should also match. */ if (output_pos != stream->whole_target.wininfo[window_num].offset) { XPR(NT "internal merge error: offset mismatch\n"); return XD3_INVALID; } if (option_use_checksum && (stream->dec_win_ind & VCD_ADLER32) != 0) { recode_stream->flags |= XD3_ADLER32_RECODE; recode_stream->recode_adler32 = stream->whole_target.wininfo[window_num].adler32; } window_num++; if (main_bsize < window_size) { main_buffree (main_bdata); main_bdata = NULL; main_bsize = 0; if ((main_bdata = (uint8_t*) main_bufalloc (window_size)) == NULL) { return ENOMEM; } main_bsize = window_size; } /* This encodes a single target window. */ while (window_pos < window_size && inst_pos < stream->whole_target.instlen) { xd3_winst *inst = &stream->whole_target.inst[inst_pos]; usize_t take = min(inst->size, window_size - window_pos); xoff_t addr; switch (inst->type) { case XD3_RUN: if ((ret = xd3_emit_run (recode_stream, window_pos, take, &stream->whole_target.adds[inst->addr]))) { return ret; } break; case XD3_ADD: /* Adds are implicit, put them into the input buffer. */ memcpy (main_bdata + window_pos, stream->whole_target.adds + inst->addr, take); break; default: /* XD3_COPY + copy mode */ if (inst->mode != 0) { if (window_srcset) { window_srcmin = min(window_srcmin, inst->addr); window_srcmax = max(window_srcmax, inst->addr + take); } else { window_srcset = 1; window_srcmin = inst->addr; window_srcmax = inst->addr + take; } addr = inst->addr; } else { XD3_ASSERT (inst->addr >= window_start); addr = inst->addr - window_start; } IF_DEBUG2 (XPR(NTR "[merge copy] winpos %u take %u addr %"Q"u mode %u\n", window_pos, take, addr, inst->mode)); if ((ret = xd3_found_match (recode_stream, window_pos, take, addr, inst->mode != 0))) { return ret; } break; } window_pos += take; output_pos += take; if (take == inst->size) { inst_pos += 1; } else { /* Modify the instruction for the next pass. */ if (inst->type != XD3_RUN) { inst->addr += take; } inst->size -= take; } } xd3_avail_input (recode_stream, main_bdata, window_pos); recode_stream->enc_state = ENC_INSTR; if (window_srcset) { recode_stream->srcwin_decided = 1; recode_stream->src = &recode_source; recode_source.srclen = (usize_t)(window_srcmax - window_srcmin); recode_source.srcbase = window_srcmin; recode_stream->taroff = recode_source.srclen; XD3_ASSERT (recode_source.srclen != 0); } else { recode_stream->srcwin_decided = 0; recode_stream->src = NULL; recode_stream->taroff = 0; } for (;;) { switch ((ret = xd3_encode_input (recode_stream))) { case XD3_INPUT: { goto done_window; } case XD3_OUTPUT: { /* main_file_write below */ break; } case XD3_GOTHEADER: case XD3_WINSTART: case XD3_WINFINISH: { /* ignore */ continue; } case XD3_GETSRCBLK: case 0: { return XD3_INTERNAL; } default: return ret; } if ((ret = main_write_output(recode_stream, ofile))) { return ret; } xd3_consume_output (recode_stream); } done_window: (void) 0; } return 0; }
CWE-119
null
516,996
134480406771728313196954483571160040817
null
null
other