--- scrollkeeper-0.3.14.orig/cl/src/get-cl.c 2003-12-06 04:58:42 +0300 +++ scrollkeeper-0.3.14.orig/cl/src/get-cl.c 2007-06-28 17:07:14 +0400 @@ -101,7 +101,7 @@ */ static char *get_next_free_temp_file_path(char outputprefs) { - char path[PATHLEN], *filename, *user_name, user_dir[PATHLEN]; + char path[PATH_MAX], *filename, *user_name, user_dir[PATH_MAX]; int i, num, fd; struct stat buf; time_t prev; @@ -122,12 +122,12 @@ sk_message (outputprefs, SKOUT_DEFAULT, SKOUT_QUIET, "scrollkeeper-get-cl", _("Unable to determine username.")); exit (EXIT_FAILURE); } - snprintf (user_dir, PATHLEN, "/tmp/scrollkeeper-%s", user_name); + snprintf (user_dir, PATH_MAX, "/tmp/scrollkeeper-%s", user_name); free (user_name); make_local_tmpdir (user_dir, outputprefs); for(i = 0; i < 5; i++) { - snprintf(path, PATHLEN, "%s/contents.%d", user_dir, i); + snprintf(path, PATH_MAX, "%s/contents.%d", user_dir, i); if (stat(path, &buf) == -1) { if (errno == ENOENT) { /* this is an empty slot so use it */ @@ -162,9 +162,9 @@ num = 0; } - filename = malloc(sizeof(char)*PATHLEN); + filename = malloc(sizeof(char)*PATH_MAX); check_ptr(filename, "scrollkeeper-get-cl"); - snprintf(filename, PATHLEN, "%s/contents.%d", user_dir, num); + snprintf(filename, PATH_MAX, "%s/contents.%d", user_dir, num); unlink(filename); @@ -193,7 +193,7 @@ int main(int argc, char **argv) { FILE *config_fid; - char scrollkeeper_dir[PATHLEN], *locale; + char scrollkeeper_dir[PATH_MAX], *locale; char *base_name, *path; xmlDocPtr merged_tree; char outputprefs=0; --- scrollkeeper-0.3.14.orig/cl/src/scrollkeeper-install.c 2003-09-02 15:58:56 +0400 +++ scrollkeeper-0.3.14.orig/cl/src/scrollkeeper-install.c 2007-06-28 17:07:14 +0400 @@ -41,8 +41,8 @@ main (int argc, char *argv[]) { char *omf_name; - char scrollkeeper_dir[PATHLEN]; - char scrollkeeper_data_dir[PATHLEN]; + char scrollkeeper_dir[PATH_MAX]; + char scrollkeeper_data_dir[PATH_MAX]; FILE *fid; char outputprefs=0; int i; @@ -64,7 +64,7 @@ switch (i) { case 'p': - strncpy (scrollkeeper_dir, optarg, PATHLEN); + strncpy (scrollkeeper_dir, optarg, PATH_MAX-1); break; case 'v': --- scrollkeeper-0.3.14.orig/cl/src/scrollkeeper-uninstall.c 2002-02-25 11:23:14 +0300 +++ scrollkeeper-0.3.14.orig/cl/src/scrollkeeper-uninstall.c 2007-06-28 17:07:14 +0400 @@ -36,7 +36,7 @@ int main (int argc, char *argv[]) { - char *omf_name, scrollkeeper_dir[PATHLEN]; + char *omf_name, scrollkeeper_dir[PATH_MAX]; FILE *fid; char outputprefs=0; int i; @@ -55,7 +55,7 @@ switch (i) { case 'p': - strncpy (scrollkeeper_dir, optarg, PATHLEN); + strncpy (scrollkeeper_dir, optarg, PATH_MAX-1); break; case 'v': --- scrollkeeper-0.3.14.orig/cl/src/update.c 2003-09-02 15:08:47 +0400 +++ scrollkeeper-0.3.14.orig/cl/src/update.c 2007-06-28 17:07:14 +0400 @@ -31,7 +31,7 @@ #include static char **av; -static char config_omf_dir[PATHLEN]; +static char config_omf_dir[PATH_MAX]; static xmlExternalEntityLoader defaultEntityLoader = NULL; static void add_element(char ***elem_tab, int *elem_num, char *elem) @@ -289,7 +289,7 @@ sep[3] = '\0'; token = strtok(line, sep); - snprintf(name, PATHLEN, "%s", token); + snprintf(name, PATH_MAX, "%s", token); token = strtok(NULL, sep); token = strtok(NULL, sep); token = strtok(NULL, sep); @@ -334,7 +334,7 @@ ptr[strlen(ptr)-1] = '\0'; } - strncpy(config_omf_dir, ptr, PATHLEN); + strncpy(config_omf_dir, ptr, PATH_MAX-1); } } @@ -344,17 +344,17 @@ int main(int argc, char **argv) { FILE *fid, *config_fid; - char name[PATHLEN]; + char name[PATH_MAX]; long t; struct stat buf; int line_num = 0, i; char **name_tab = NULL; char **install_tab = NULL, **uninstall_tab = NULL; int install_num = 0, upgrade_num = 0, uninstall_num = 0; - char scrollkeeper_dir[PATHLEN], omf_dir[PATHLEN]; + char scrollkeeper_dir[PATH_MAX], omf_dir[PATH_MAX]; char **omf_dirs = NULL; - char scrollkeeper_docs[PATHLEN]; - char scrollkeeper_data_dir[PATHLEN]; + char scrollkeeper_docs[PATH_MAX]; + char scrollkeeper_data_dir[PATH_MAX]; char **upgrade_tab = NULL; char *s, **cpp; char outputprefs=0; @@ -376,11 +376,11 @@ switch (i) { case 'p': - strncpy (scrollkeeper_dir, optarg, PATHLEN); + strncpy (scrollkeeper_dir, optarg, PATH_MAX-1); break; case 'o': - strncpy (omf_dir, optarg, PATHLEN); + strncpy (omf_dir, optarg, PATH_MAX-1); break; case 'v': @@ -430,11 +430,11 @@ { if ((s = getenv ("OMF_DIR")) != NULL) { - strncpy (omf_dir, s, PATHLEN); + strncpy (omf_dir, s, PATH_MAX-1); } else if (config_omf_dir[0] != '\0') { - strncpy(omf_dir, config_omf_dir, PATHLEN); + strncpy(omf_dir, config_omf_dir, PATH_MAX-1); } else { @@ -446,7 +446,7 @@ omf_dirs = colon_split (omf_dir); - snprintf(scrollkeeper_docs, PATHLEN, "%s/scrollkeeper_docs", scrollkeeper_dir); + snprintf(scrollkeeper_docs, PATH_MAX, "%s/scrollkeeper_docs", scrollkeeper_dir); if (stat(scrollkeeper_docs, &buf) == 0 && S_ISREG(buf.st_mode)) { --- scrollkeeper-0.3.14.orig/libs/database.c 2002-06-02 10:03:10 +0400 +++ scrollkeeper-0.3.14.orig/libs/database.c 2007-06-28 17:07:27 +0400 @@ -27,7 +27,6 @@ #include #include -#define PATHLEN 256 /* @@ -55,7 +54,7 @@ */ int sk_mkdir_with_parents(char *fullpath, mode_t options, char outputprefs) { - char path[1024]; + char path[PATH_MAX]; char slash[]="/"; char delim[]="/"; char *token, *pathcopy; @@ -63,15 +62,16 @@ pathcopy = strdup(fullpath); /* Copy b/c strtok edits the string it operates on */ path[0] = '\0'; /* Initialize with end of string null character */ - if (pathcopy[0] == slash[0]) sprintf(path, "/"); /* preserve any starting slash */ + if (pathcopy[0] == slash[0]) strcpy(path, "/"); /* preserve any starting slash */ token = strtok (pathcopy, delim); delim[0]=slash[0]; while(token != NULL) { if (strlen(path) == 0 || ((strlen(path) == 1) && (path[0] == slash[0]))) { - sprintf(path, "%s%s", path, token); + strncat(path, token, PATH_MAX - strlen(path) - 1); } else { - sprintf(path, "%s/%s", path, token); + strncat(path, "/", PATH_MAX - strlen(path) - 1); + strncat(path, token, PATH_MAX - strlen(path) - 1); } if (stat(path, &buf) == -1) { if (sk_mkdir(path, options, outputprefs) != 0) { @@ -93,11 +93,11 @@ int create_database_directory(char *scrollkeeper_dir, char *scrollkeeper_data_dir, char outputprefs) { DIR *dir; - char source_path[PATHLEN], target_path[PATHLEN]; + char source_path[PATH_MAX], target_path[PATH_MAX]; struct dirent *dir_ent; struct stat buf; int empty; - char *data_dir, dirname[PATHLEN]; + char *data_dir, dirname[PATH_MAX]; /* check if it's empty */ @@ -109,6 +109,9 @@ return 1; } dir = opendir(scrollkeeper_dir); + if (dir == NULL) { + return 1; + } } @@ -133,41 +136,46 @@ dir = opendir(data_dir); + if (dir == NULL) { + free (data_dir); + return 2; + } + while((dir_ent = readdir(dir)) != NULL) { if (dir_ent->d_name[0] == '.') continue; - snprintf(source_path, PATHLEN, "%s/%s", data_dir, dir_ent->d_name); + snprintf(source_path, PATH_MAX, "%s/%s", data_dir, dir_ent->d_name); lstat(source_path, &buf); if (S_ISDIR(buf.st_mode)) /* copy the directory */ { - char source_file[PATHLEN], target_file[PATHLEN]; + char source_file[PATH_MAX], target_file[PATH_MAX]; - snprintf(dirname, PATHLEN, "%s/%s", scrollkeeper_dir, dir_ent->d_name); + snprintf(dirname, PATH_MAX, "%s/%s", scrollkeeper_dir, dir_ent->d_name); mkdir(dirname, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH|S_IXUSR|S_IXGRP|S_IXOTH); - snprintf(source_file, PATHLEN, "%s/scrollkeeper_cl.xml", source_path); - snprintf(target_file, PATHLEN, "%s/%s/scrollkeeper_cl.xml", + snprintf(source_file, PATH_MAX, "%s/scrollkeeper_cl.xml", source_path); + snprintf(target_file, PATH_MAX, "%s/%s/scrollkeeper_cl.xml", scrollkeeper_dir, dir_ent->d_name); copy_file(source_file, target_file); - snprintf(target_file, PATHLEN, "%s/%s/scrollkeeper_extended_cl.xml", + snprintf(target_file, PATH_MAX, "%s/%s/scrollkeeper_extended_cl.xml", scrollkeeper_dir, dir_ent->d_name); copy_file(source_file, target_file); } else /* link the directory */ { char *target_locale; - char aux_path[PATHLEN]; + char aux_path[PATH_MAX]; realpath(source_path, aux_path); target_locale = strrchr(aux_path, '/'); target_locale++; - snprintf(source_path, PATHLEN, "%s/%s", scrollkeeper_dir, dir_ent->d_name); - snprintf(target_path, PATHLEN, "%s", target_locale); + snprintf(source_path, PATH_MAX, "%s/%s", scrollkeeper_dir, dir_ent->d_name); + snprintf(target_path, PATH_MAX, "%s", target_locale); symlink(target_path, source_path); } @@ -178,10 +186,10 @@ /* create TOC and index directory */ - snprintf(dirname, PATHLEN, "%s/TOC", scrollkeeper_dir); + snprintf(dirname, PATH_MAX, "%s/TOC", scrollkeeper_dir); mkdir(dirname, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH|S_IXUSR|S_IXGRP|S_IXOTH); - snprintf(dirname, PATHLEN, "%s/index", scrollkeeper_dir); + snprintf(dirname, PATH_MAX, "%s/index", scrollkeeper_dir); mkdir(dirname, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH|S_IXUSR|S_IXGRP|S_IXOTH); return 0; } --- scrollkeeper-0.3.14.orig/libs/extract.c 2003-06-27 17:03:46 +0400 +++ scrollkeeper-0.3.14.orig/libs/extract.c 2007-06-28 17:07:14 +0400 @@ -51,7 +51,7 @@ FILE *res_fid; char *doctype; char command[1024]; - char temp1[PATHLEN], temp2[PATHLEN], errors[PATHLEN]; + char temp1[PATH_MAX], temp2[PATH_MAX], errors[PATH_MAX]; int temp1_fd, temp2_fd, errors_fd; #endif @@ -70,9 +70,9 @@ #ifdef SOLARIS doc = docbParseFile(input_file, NULL); #else - snprintf(temp1, PATHLEN, SCROLLKEEPER_STATEDIR "/tmp/scrollkeeper-extract-1.xml.XXXXXX"); - snprintf(temp2, PATHLEN, SCROLLKEEPER_STATEDIR "/tmp/scrollkeeper-extract-2.xml.XXXXXX"); - snprintf(errors, PATHLEN, SCROLLKEEPER_STATEDIR "/tmp/scrollkeeper-extract-errors.XXXXXX"); + snprintf(temp1, PATH_MAX, SCROLLKEEPER_STATEDIR "/tmp/scrollkeeper-extract-1.xml.XXXXXX"); + snprintf(temp2, PATH_MAX, SCROLLKEEPER_STATEDIR "/tmp/scrollkeeper-extract-2.xml.XXXXXX"); + snprintf(errors, PATH_MAX, SCROLLKEEPER_STATEDIR "/tmp/scrollkeeper-extract-errors.XXXXXX"); temp1_fd = mkstemp(temp1); printf ("%s\n", temp1); --- scrollkeeper-0.3.14.orig/libs/install.c 2003-09-03 14:33:52 +0400 +++ scrollkeeper-0.3.14.orig/libs/install.c 2007-06-28 17:07:14 +0400 @@ -32,7 +32,6 @@ #define _(String) gettext (String) #define SEP "|" -#define PATHLEN 256 #ifdef SOLARIS /*extern char *strtok_r(char *, const char *, char **);*/ @@ -53,12 +52,12 @@ dest_dir = malloc (strlen (scrollkeeper_dir) + strlen (locale) + 2); check_ptr(dest_dir, "scrollkeeper-install"); - snprintf(dest_dir, PATHLEN, "%s/%s", scrollkeeper_dir, locale); + snprintf(dest_dir, PATH_MAX, "%s/%s", scrollkeeper_dir, locale); if (is_dir(dest_dir)) { - strncpy(locale_dir, dest_dir, PATHLEN); - strncpy(locale_name, locale, PATHLEN); + strncpy(locale_dir, dest_dir, PATH_MAX-1); + strncpy(locale_name, locale, PATH_MAX-1); free(dest_dir); return 1; } @@ -70,11 +69,11 @@ if (ptr != NULL) { *ptr = '\0'; - snprintf(dest_dir, PATHLEN, "%s/%s", scrollkeeper_dir, loc); + snprintf(dest_dir, PATH_MAX, "%s/%s", scrollkeeper_dir, loc); if (is_dir(dest_dir)) { - strncpy(locale_dir, dest_dir, PATHLEN); - strncpy(locale_name, loc, PATHLEN); + strncpy(locale_dir, dest_dir, PATH_MAX-1); + strncpy(locale_name, loc, PATH_MAX-1); free(dest_dir); free(loc); return 1; @@ -85,11 +84,11 @@ if (ptr != NULL) { *ptr = '\0'; - snprintf(dest_dir, PATHLEN, "%s/%s", scrollkeeper_dir, loc); + snprintf(dest_dir, PATH_MAX, "%s/%s", scrollkeeper_dir, loc); if (is_dir(dest_dir)) { - strncpy(locale_dir, dest_dir, PATHLEN); - strncpy(locale_name, loc, PATHLEN); + strncpy(locale_dir, dest_dir, PATH_MAX); + strncpy(locale_name, loc, PATH_MAX); free(dest_dir); free(loc); return 1; @@ -105,7 +104,7 @@ { xmlDocPtr toc_doc; FILE *config_fid; - char command[1024], tocpath[PATHLEN]; + char command[1024], tocpath[PATH_MAX]; xmlNodePtr toc_tree; errorSAXFunc xml_error_handler; warningSAXFunc xml_warning_handler; @@ -160,11 +159,11 @@ xmlDtdPtr dtd; xmlNodePtr node, omf_node, s_node; char *docpath, *title, *format, str[1024]; - char cl_filename[PATHLEN], cl_ext_filename[PATHLEN]; - char locale_dir[PATHLEN], locale_name[PATHLEN], *locale, *ptr; + char cl_filename[PATH_MAX], cl_ext_filename[PATH_MAX]; + char locale_dir[PATH_MAX], locale_name[PATH_MAX], *locale, *ptr; int unique_id; xmlDocPtr cl_doc, cl_ext_doc; - char scrollkeeper_docs[PATHLEN]; + char scrollkeeper_docs[PATH_MAX]; char **stylesheets=NULL, **output_files=NULL, *toc_name; char *toc_stylesheet_name, *index_name, *index_stylesheet_name, *uid; @@ -197,7 +196,7 @@ } xmlFreeDtd(dtd); - snprintf(scrollkeeper_docs, PATHLEN, "%s/scrollkeeper_docs", scrollkeeper_dir); + snprintf(scrollkeeper_docs, PATH_MAX, "%s/scrollkeeper_docs", scrollkeeper_dir); /* We assume that this file is a concatenation of "resource" tags so * they should start from the top node's children. @@ -230,8 +229,8 @@ continue; } xmlFree(locale); - snprintf(cl_filename, PATHLEN, "%s/scrollkeeper_cl.xml", locale_dir); - snprintf(cl_ext_filename, PATHLEN, "%s/scrollkeeper_extended_cl.xml", locale_dir); + snprintf(cl_filename, PATH_MAX, "%s/scrollkeeper_cl.xml", locale_dir); + snprintf(cl_ext_filename, PATH_MAX, "%s/scrollkeeper_extended_cl.xml", locale_dir); if (!is_file(cl_filename)) continue; --- scrollkeeper-0.3.14.orig/libs/scrollkeeper.h 2003-12-06 11:20:20 +0300 +++ scrollkeeper-0.3.14.orig/libs/scrollkeeper.h 2007-06-28 17:07:14 +0400 @@ -21,6 +21,7 @@ #include #include +#include #define _(String) gettext (String) @@ -32,7 +33,6 @@ #define SCROLLKEEPERLOGFILE "/gnome/head/INSTALL/var/log/scrollkeeper.log" #define SCROLLKEEPERLOGFILE_ROT "/gnome/head/INSTALL/var/log/scrollkeeper.log.1" #define SCROLLKEEPER_OMF_DTD "/gnome/head/INSTALL/share/xml/scrollkeeper/dtds/scrollkeeper-omf.dtd" -#define PATHLEN 256 /* * --- scrollkeeper-0.3.14.orig/libs/scrollkeeper.h.in 2007-06-25 16:21:35 +0400 +++ scrollkeeper-0.3.14.orig/libs/scrollkeeper.h.in 2007-06-28 17:07:14 +0400 @@ -21,6 +21,7 @@ #include #include +#include #define _(String) gettext (String) @@ -32,7 +33,6 @@ #define SCROLLKEEPERLOGFILE "/var/log/scrollkeeper.log" #define SCROLLKEEPERLOGFILE_ROT "/var/log/scrollkeeper.log.1" #define SCROLLKEEPER_OMF_DTD "@prefix@/share/xml/scrollkeeper/dtds/scrollkeeper-omf.dtd" -#define PATHLEN 256 /* * --- scrollkeeper-0.3.14.orig/libs/uninstall.c 2003-12-02 11:09:56 +0300 +++ scrollkeeper-0.3.14.orig/libs/uninstall.c 2007-06-28 17:07:14 +0400 @@ -29,7 +29,6 @@ #define _(String) gettext (String) -#define PATHLEN 256 struct IdTab { int id; @@ -41,16 +40,16 @@ static void remove_tocs_and_index(struct IdTab *tab, int num, char *scrollkeeper_dir) { - char toc_dir[PATHLEN], toc_file[PATHLEN], index_dir[PATHLEN], index_file[PATHLEN]; + char toc_dir[PATH_MAX], toc_file[PATH_MAX], index_dir[PATH_MAX], index_file[PATH_MAX]; int i; - snprintf(toc_dir, PATHLEN, "%s/TOC", scrollkeeper_dir); - snprintf(index_dir, PATHLEN, "%s/index", scrollkeeper_dir); + snprintf(toc_dir, PATH_MAX, "%s/TOC", scrollkeeper_dir); + snprintf(index_dir, PATH_MAX, "%s/index", scrollkeeper_dir); for(i = 0; i < num; i++) { - snprintf(toc_file, PATHLEN, "%s/%d", toc_dir, tab[i].id); - snprintf(index_file, PATHLEN, "%s/%d", index_dir, tab[i].id); + snprintf(toc_file, PATH_MAX, "%s/%d", toc_dir, tab[i].id); + snprintf(index_file, PATH_MAX, "%s/%d", index_dir, tab[i].id); unlink(toc_file); unlink(index_file); } @@ -68,7 +67,7 @@ static void remove_docs_from_content_list(struct IdTab *id_tab, int id_num, char *scrollkeeper_dir, char outputprefs) { int start, end; - char cl_filename[PATHLEN], cl_ext_filename[PATHLEN]; + char cl_filename[PATH_MAX], cl_ext_filename[PATH_MAX]; xmlDocPtr cl_doc, cl_ext_doc; if (id_tab == NULL) @@ -87,8 +86,8 @@ if (start >= id_num) break; - snprintf(cl_filename, PATHLEN, "%s/%s/scrollkeeper_cl.xml", scrollkeeper_dir, id_tab[start].locale); - snprintf(cl_ext_filename, PATHLEN, "%s/%s/scrollkeeper_extended_cl.xml", scrollkeeper_dir, + snprintf(cl_filename, PATH_MAX, "%s/%s/scrollkeeper_cl.xml", scrollkeeper_dir, id_tab[start].locale); + snprintf(cl_ext_filename, PATH_MAX, "%s/%s/scrollkeeper_extended_cl.xml", scrollkeeper_dir, id_tab[start].locale); cl_doc = xmlParseFile(cl_filename); @@ -170,11 +169,11 @@ sep[3] = '\0'; token = strtok(line, sep); - snprintf(omf_name, PATHLEN, "%s", token); + snprintf(omf_name, PATH_MAX, "%s", token); token = strtok(NULL, sep); *id = atoi(token); token = strtok(NULL, sep); - snprintf(doc_name, PATHLEN, "%s", token); + snprintf(doc_name, PATH_MAX, "%s", token); token = strtok(NULL, sep); *timestamp = atol(token); token = strtok(NULL, sep); @@ -190,11 +189,11 @@ int id, count; struct IdTab *l_id_tab = NULL; FILE *fid, *tmp_fid; - char l_omf_name[PATHLEN], doc_name[PATHLEN], tmp[PATHLEN], locale[32]; - char scrollkeeper_docs[PATHLEN]; + char l_omf_name[PATH_MAX], doc_name[PATH_MAX], tmp[PATH_MAX], locale[32]; + char scrollkeeper_docs[PATH_MAX]; long timestamp; - snprintf(scrollkeeper_docs, PATHLEN, "%s/scrollkeeper_docs", scrollkeeper_dir); + snprintf(scrollkeeper_docs, PATH_MAX, "%s/scrollkeeper_docs", scrollkeeper_dir); fid = fopen(scrollkeeper_docs, "r"); if (fid == NULL) @@ -203,7 +202,7 @@ return; } - snprintf(tmp, PATHLEN, "%s.tmp", scrollkeeper_docs); + snprintf(tmp, PATH_MAX, "%s.tmp", scrollkeeper_docs); tmp_fid = fopen(tmp, "w"); if (tmp_fid == NULL)