diff options
| author | Paul Eggert | 2011-06-20 19:15:16 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-06-20 19:15:16 -0700 |
| commit | 281549626c7a22c2d8643fc563974ee6fbc401a8 (patch) | |
| tree | 36efa23cefa8f3e423ea21da7751d7b1917fe546 /src | |
| parent | 7de51af53b40c4fcaa4369feffad11e9db11fbe0 (diff) | |
| download | emacs-281549626c7a22c2d8643fc563974ee6fbc401a8.tar.gz emacs-281549626c7a22c2d8643fc563974ee6fbc401a8.zip | |
* xrdb.c: Don't assume strlen fits in int; avoid some strlens.
* xrdb.c (magic_file_p, search_magic_path):
Omit last arg SUFFIX; it was always 0. All callers changed.
(magic_file_p): Use ptrdiff_t, not int. Check for size overflow.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 5 | ||||
| -rw-r--r-- | src/xrdb.c | 53 |
2 files changed, 25 insertions, 33 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 857b0fa79e2..b388b1e3ea7 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | 2011-06-21 Paul Eggert <eggert@cs.ucla.edu> | 1 | 2011-06-21 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 2 | ||
| 3 | * xrdb.c: Don't assume strlen fits in int; avoid some strlens. | ||
| 4 | * xrdb.c (magic_file_p, search_magic_path): | ||
| 5 | Omit last arg SUFFIX; it was always 0. All callers changed. | ||
| 6 | (magic_file_p): Use ptrdiff_t, not int. Check for size overflow. | ||
| 7 | |||
| 3 | * xfont.c (xfont_match): Avoid need for strlen. | 8 | * xfont.c (xfont_match): Avoid need for strlen. |
| 4 | 9 | ||
| 5 | * xfns.c: Don't assume strlen fits in int. | 10 | * xfns.c: Don't assume strlen fits in int. |
diff --git a/src/xrdb.c b/src/xrdb.c index b490afdabaa..e18ff65f799 100644 --- a/src/xrdb.c +++ b/src/xrdb.c | |||
| @@ -120,20 +120,20 @@ x_get_customization_string (XrmDatabase db, const char *name, | |||
| 120 | refers to %L only when the LANG environment variable is set, or | 120 | refers to %L only when the LANG environment variable is set, or |
| 121 | otherwise provided by X. | 121 | otherwise provided by X. |
| 122 | 122 | ||
| 123 | ESCAPED_SUFFIX and SUFFIX are postpended to STRING if they are | 123 | ESCAPED_SUFFIX is postpended to STRING if it is non-zero. |
| 124 | non-zero. %-escapes in ESCAPED_SUFFIX are expanded; STRING is left | 124 | %-escapes in ESCAPED_SUFFIX are expanded. |
| 125 | alone. | ||
| 126 | 125 | ||
| 127 | Return NULL otherwise. */ | 126 | Return NULL otherwise. */ |
| 128 | 127 | ||
| 129 | static char * | 128 | static char * |
| 130 | magic_file_p (const char *string, EMACS_INT string_len, const char *class, const char *escaped_suffix, const char *suffix) | 129 | magic_file_p (const char *string, EMACS_INT string_len, const char *class, |
| 130 | const char *escaped_suffix) | ||
| 131 | { | 131 | { |
| 132 | char *lang = getenv ("LANG"); | 132 | char *lang = getenv ("LANG"); |
| 133 | 133 | ||
| 134 | int path_size = 100; | 134 | ptrdiff_t path_size = 100; |
| 135 | char *path = (char *) xmalloc (path_size); | 135 | char *path = (char *) xmalloc (path_size); |
| 136 | int path_len = 0; | 136 | ptrdiff_t path_len = 0; |
| 137 | 137 | ||
| 138 | const char *p = string; | 138 | const char *p = string; |
| 139 | 139 | ||
| @@ -141,7 +141,7 @@ magic_file_p (const char *string, EMACS_INT string_len, const char *class, const | |||
| 141 | { | 141 | { |
| 142 | /* The chunk we're about to stick on the end of result. */ | 142 | /* The chunk we're about to stick on the end of result. */ |
| 143 | const char *next = NULL; | 143 | const char *next = NULL; |
| 144 | int next_len; | 144 | ptrdiff_t next_len; |
| 145 | 145 | ||
| 146 | if (*p == '%') | 146 | if (*p == '%') |
| 147 | { | 147 | { |
| @@ -201,8 +201,10 @@ magic_file_p (const char *string, EMACS_INT string_len, const char *class, const | |||
| 201 | next = p, next_len = 1; | 201 | next = p, next_len = 1; |
| 202 | 202 | ||
| 203 | /* Do we have room for this component followed by a '\0' ? */ | 203 | /* Do we have room for this component followed by a '\0' ? */ |
| 204 | if (path_len + next_len + 1 > path_size) | 204 | if (path_size - path_len <= next_len) |
| 205 | { | 205 | { |
| 206 | if (min (PTRDIFF_MAX, SIZE_MAX) / 2 - 1 - path_len < next_len) | ||
| 207 | memory_full (SIZE_MAX); | ||
| 206 | path_size = (path_len + next_len + 1) * 2; | 208 | path_size = (path_len + next_len + 1) * 2; |
| 207 | path = (char *) xrealloc (path, path_size); | 209 | path = (char *) xrealloc (path, path_size); |
| 208 | } | 210 | } |
| @@ -222,21 +224,6 @@ magic_file_p (const char *string, EMACS_INT string_len, const char *class, const | |||
| 222 | } | 224 | } |
| 223 | } | 225 | } |
| 224 | 226 | ||
| 225 | /* Perhaps we should add the SUFFIX now. */ | ||
| 226 | if (suffix) | ||
| 227 | { | ||
| 228 | int suffix_len = strlen (suffix); | ||
| 229 | |||
| 230 | if (path_len + suffix_len + 1 > path_size) | ||
| 231 | { | ||
| 232 | path_size = (path_len + suffix_len + 1); | ||
| 233 | path = (char *) xrealloc (path, path_size); | ||
| 234 | } | ||
| 235 | |||
| 236 | memcpy (path + path_len, suffix, suffix_len); | ||
| 237 | path_len += suffix_len; | ||
| 238 | } | ||
| 239 | |||
| 240 | path[path_len] = '\0'; | 227 | path[path_len] = '\0'; |
| 241 | 228 | ||
| 242 | if (! file_p (path)) | 229 | if (! file_p (path)) |
| @@ -295,7 +282,8 @@ file_p (const char *filename) | |||
| 295 | the path name of the one we found otherwise. */ | 282 | the path name of the one we found otherwise. */ |
| 296 | 283 | ||
| 297 | static char * | 284 | static char * |
| 298 | search_magic_path (const char *search_path, const char *class, const char *escaped_suffix, const char *suffix) | 285 | search_magic_path (const char *search_path, const char *class, |
| 286 | const char *escaped_suffix) | ||
| 299 | { | 287 | { |
| 300 | const char *s, *p; | 288 | const char *s, *p; |
| 301 | 289 | ||
| @@ -306,8 +294,7 @@ search_magic_path (const char *search_path, const char *class, const char *escap | |||
| 306 | 294 | ||
| 307 | if (p > s) | 295 | if (p > s) |
| 308 | { | 296 | { |
| 309 | char *path = magic_file_p (s, p - s, class, escaped_suffix, | 297 | char *path = magic_file_p (s, p - s, class, escaped_suffix); |
| 310 | suffix); | ||
| 311 | if (path) | 298 | if (path) |
| 312 | return path; | 299 | return path; |
| 313 | } | 300 | } |
| @@ -316,7 +303,7 @@ search_magic_path (const char *search_path, const char *class, const char *escap | |||
| 316 | char *path; | 303 | char *path; |
| 317 | 304 | ||
| 318 | s = "%N%S"; | 305 | s = "%N%S"; |
| 319 | path = magic_file_p (s, strlen (s), class, escaped_suffix, suffix); | 306 | path = magic_file_p (s, strlen (s), class, escaped_suffix); |
| 320 | if (path) | 307 | if (path) |
| 321 | return path; | 308 | return path; |
| 322 | } | 309 | } |
| @@ -340,7 +327,7 @@ get_system_app (const char *class) | |||
| 340 | path = getenv ("XFILESEARCHPATH"); | 327 | path = getenv ("XFILESEARCHPATH"); |
| 341 | if (! path) path = PATH_X_DEFAULTS; | 328 | if (! path) path = PATH_X_DEFAULTS; |
| 342 | 329 | ||
| 343 | p = search_magic_path (path, class, 0, 0); | 330 | p = search_magic_path (path, class, 0); |
| 344 | if (p) | 331 | if (p) |
| 345 | { | 332 | { |
| 346 | db = XrmGetFileDatabase (p); | 333 | db = XrmGetFileDatabase (p); |
| @@ -368,19 +355,19 @@ get_user_app (const char *class) | |||
| 368 | /* Check for XUSERFILESEARCHPATH. It is a path of complete file | 355 | /* Check for XUSERFILESEARCHPATH. It is a path of complete file |
| 369 | names, not directories. */ | 356 | names, not directories. */ |
| 370 | if (((path = getenv ("XUSERFILESEARCHPATH")) | 357 | if (((path = getenv ("XUSERFILESEARCHPATH")) |
| 371 | && (file = search_magic_path (path, class, 0, 0))) | 358 | && (file = search_magic_path (path, class, 0))) |
| 372 | 359 | ||
| 373 | /* Check for APPLRESDIR; it is a path of directories. In each, | 360 | /* Check for APPLRESDIR; it is a path of directories. In each, |
| 374 | we have to search for LANG/CLASS and then CLASS. */ | 361 | we have to search for LANG/CLASS and then CLASS. */ |
| 375 | || ((path = getenv ("XAPPLRESDIR")) | 362 | || ((path = getenv ("XAPPLRESDIR")) |
| 376 | && ((file = search_magic_path (path, class, "/%L/%N", 0)) | 363 | && ((file = search_magic_path (path, class, "/%L/%N")) |
| 377 | || (file = search_magic_path (path, class, "/%N", 0)))) | 364 | || (file = search_magic_path (path, class, "/%N")))) |
| 378 | 365 | ||
| 379 | /* Check in the home directory. This is a bit of a hack; let's | 366 | /* Check in the home directory. This is a bit of a hack; let's |
| 380 | hope one's home directory doesn't contain any %-escapes. */ | 367 | hope one's home directory doesn't contain any %-escapes. */ |
| 381 | || (free_it = gethomedir (), | 368 | || (free_it = gethomedir (), |
| 382 | ((file = search_magic_path (free_it, class, "%L/%N", 0)) | 369 | ((file = search_magic_path (free_it, class, "%L/%N")) |
| 383 | || (file = search_magic_path (free_it, class, "%N", 0))))) | 370 | || (file = search_magic_path (free_it, class, "%N"))))) |
| 384 | { | 371 | { |
| 385 | XrmDatabase db = XrmGetFileDatabase (file); | 372 | XrmDatabase db = XrmGetFileDatabase (file); |
| 386 | xfree (file); | 373 | xfree (file); |