idx
int64 | func_before
string | Vulnerability Classification
string | vul
int64 | func_after
string | patch
string | CWE ID
string | lines_before
string | lines_after
string |
|---|---|---|---|---|---|---|---|---|
5,100
|
MenuCacheDir* menu_cache_get_dir_from_path( MenuCache* cache, const char* path )
{
char** names = g_strsplit( path + 1, "/", -1 );
int i = 0;
MenuCacheDir* dir = NULL;
if( !names )
return NULL;
if( G_UNLIKELY(!names[0]) )
{
g_strfreev(names);
return NULL;
}
/* the topmost dir of the path should be the root menu dir. */
MENU_CACHE_LOCK;
dir = cache->root_dir;
if (G_UNLIKELY(dir == NULL) || strcmp(names[0], MENU_CACHE_ITEM(dir)->id))
{
MENU_CACHE_UNLOCK;
return NULL;
}
for( ++i; names[i]; ++i )
{
GSList* l;
for( l = dir->children; l; l = l->next )
{
MenuCacheItem* item = MENU_CACHE_ITEM(l->data);
if( item->type == MENU_CACHE_TYPE_DIR && 0 == strcmp( item->id, names[i] ) )
dir = MENU_CACHE_DIR(item);
}
/* FIXME: we really should ref it on return since other thread may
destroy the parent at this time and returned data become invalid.
Therefore this call isn't thread-safe! */
if( ! dir )
{
MENU_CACHE_UNLOCK;
return NULL;
}
}
MENU_CACHE_UNLOCK;
return dir;
}
|
DoS
| 0
|
MenuCacheDir* menu_cache_get_dir_from_path( MenuCache* cache, const char* path )
{
char** names = g_strsplit( path + 1, "/", -1 );
int i = 0;
MenuCacheDir* dir = NULL;
if( !names )
return NULL;
if( G_UNLIKELY(!names[0]) )
{
g_strfreev(names);
return NULL;
}
/* the topmost dir of the path should be the root menu dir. */
MENU_CACHE_LOCK;
dir = cache->root_dir;
if (G_UNLIKELY(dir == NULL) || strcmp(names[0], MENU_CACHE_ITEM(dir)->id))
{
MENU_CACHE_UNLOCK;
return NULL;
}
for( ++i; names[i]; ++i )
{
GSList* l;
for( l = dir->children; l; l = l->next )
{
MenuCacheItem* item = MENU_CACHE_ITEM(l->data);
if( item->type == MENU_CACHE_TYPE_DIR && 0 == strcmp( item->id, names[i] ) )
dir = MENU_CACHE_DIR(item);
}
/* FIXME: we really should ref it on return since other thread may
destroy the parent at this time and returned data become invalid.
Therefore this call isn't thread-safe! */
if( ! dir )
{
MENU_CACHE_UNLOCK;
return NULL;
}
}
MENU_CACHE_UNLOCK;
return dir;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,101
|
MenuCacheDir* menu_cache_get_root_dir( MenuCache* cache )
{
MenuCacheDir* dir = menu_cache_dup_root_dir(cache);
/* NOTE: this is very ugly hack but cache->root_dir may be changed by
cache reload in server-io thread, so we should keep it alive :( */
if(dir)
g_timeout_add_seconds(10, (GSourceFunc)menu_cache_item_unref, dir);
return dir;
}
|
DoS
| 0
|
MenuCacheDir* menu_cache_get_root_dir( MenuCache* cache )
{
MenuCacheDir* dir = menu_cache_dup_root_dir(cache);
/* NOTE: this is very ugly hack but cache->root_dir may be changed by
cache reload in server-io thread, so we should keep it alive :( */
if(dir)
g_timeout_add_seconds(10, (GSourceFunc)menu_cache_item_unref, dir);
return dir;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,102
|
void menu_cache_init(int flags)
{
#if !GLIB_CHECK_VERSION(2, 36, 0)
g_type_init();
#endif
}
|
DoS
| 0
|
void menu_cache_init(int flags)
{
#if !GLIB_CHECK_VERSION(2, 36, 0)
g_type_init();
#endif
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,103
|
MenuCacheDir* menu_cache_item_dup_parent( MenuCacheItem* item )
{
MenuCacheDir* dir;
MENU_CACHE_LOCK;
dir = item->parent;
if(G_LIKELY(dir))
menu_cache_item_ref(MENU_CACHE_ITEM(dir));
MENU_CACHE_UNLOCK;
return dir;
}
|
DoS
| 0
|
MenuCacheDir* menu_cache_item_dup_parent( MenuCacheItem* item )
{
MenuCacheDir* dir;
MENU_CACHE_LOCK;
dir = item->parent;
if(G_LIKELY(dir))
menu_cache_item_ref(MENU_CACHE_ITEM(dir));
MENU_CACHE_UNLOCK;
return dir;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,104
|
const char* menu_cache_item_get_comment( MenuCacheItem* item )
{
return item->comment;
}
|
DoS
| 0
|
const char* menu_cache_item_get_comment( MenuCacheItem* item )
{
return item->comment;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,105
|
const char* menu_cache_item_get_file_basename( MenuCacheItem* item )
{
return item->file_name;
}
|
DoS
| 0
|
const char* menu_cache_item_get_file_basename( MenuCacheItem* item )
{
return item->file_name;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,106
|
const char* menu_cache_item_get_file_dirname( MenuCacheItem* item )
{
return item->file_dir ? item->file_dir->dir + 1 : NULL;
}
|
DoS
| 0
|
const char* menu_cache_item_get_file_dirname( MenuCacheItem* item )
{
return item->file_dir ? item->file_dir->dir + 1 : NULL;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,107
|
char* menu_cache_item_get_file_path( MenuCacheItem* item )
{
if( ! item->file_name || ! item->file_dir )
return NULL;
return g_build_filename( item->file_dir->dir + 1, item->file_name, NULL );
}
|
DoS
| 0
|
char* menu_cache_item_get_file_path( MenuCacheItem* item )
{
if( ! item->file_name || ! item->file_dir )
return NULL;
return g_build_filename( item->file_dir->dir + 1, item->file_name, NULL );
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,108
|
const char* menu_cache_item_get_icon( MenuCacheItem* item )
{
return item->icon;
}
|
DoS
| 0
|
const char* menu_cache_item_get_icon( MenuCacheItem* item )
{
return item->icon;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,109
|
const char* menu_cache_item_get_id( MenuCacheItem* item )
{
return item->id;
}
|
DoS
| 0
|
const char* menu_cache_item_get_id( MenuCacheItem* item )
{
return item->id;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,110
|
const char* menu_cache_item_get_name( MenuCacheItem* item )
{
return item->name;
}
|
DoS
| 0
|
const char* menu_cache_item_get_name( MenuCacheItem* item )
{
return item->name;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,111
|
MenuCacheType menu_cache_item_get_type( MenuCacheItem* item )
{
return item->type;
}
|
DoS
| 0
|
MenuCacheType menu_cache_item_get_type( MenuCacheItem* item )
{
return item->type;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,112
|
MenuCacheItem* menu_cache_item_ref(MenuCacheItem* item)
{
g_atomic_int_inc( &item->n_ref );
/* DEBUG("item_ref %s: %d -> %d", item->id, item->n_ref-1, item->n_ref); */
return item;
}
|
DoS
| 0
|
MenuCacheItem* menu_cache_item_ref(MenuCacheItem* item)
{
g_atomic_int_inc( &item->n_ref );
/* DEBUG("item_ref %s: %d -> %d", item->id, item->n_ref-1, item->n_ref); */
return item;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,113
|
MenuCache* menu_cache_ref(MenuCache* cache)
{
g_atomic_int_inc( &cache->n_ref );
return cache;
}
|
DoS
| 0
|
MenuCache* menu_cache_ref(MenuCache* cache)
{
g_atomic_int_inc( &cache->n_ref );
return cache;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,114
|
gboolean menu_cache_reload( MenuCache* cache )
{
char* line;
gsize len;
GFile* file;
GFileInputStream* istr = NULL;
GDataInputStream* f;
MenuCacheFileDir** all_used_files;
int i, n;
int ver_maj, ver_min;
MENU_CACHE_LOCK;
if (cache->reload_id)
g_source_remove(cache->reload_id);
cache->reload_id = 0;
MENU_CACHE_UNLOCK;
file = g_file_new_for_path(cache->cache_file);
if(!file)
return FALSE;
istr = g_file_read(file, cache->cancellable, NULL);
g_object_unref(file);
if(!istr)
return FALSE;
f = g_data_input_stream_new(G_INPUT_STREAM(istr));
g_object_unref(istr);
if( ! f )
return FALSE;
/* the first line is version number */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_LIKELY(line))
{
len = sscanf(line, "%d.%d", &ver_maj, &ver_min);
g_free(line);
if(len < 2)
goto _fail;
if( ver_maj != VER_MAJOR ||
ver_min > VER_MINOR || ver_min < VER_MINOR_SUPPORTED )
goto _fail;
}
else
goto _fail;
g_debug("menu cache: got file version 1.%d", ver_min);
/* the second line is menu name */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
goto _fail;
g_free(line);
/* FIXME: this may lock other threads for some time */
MENU_CACHE_LOCK;
if(cache->notifiers == NULL)
{
/* nobody aware of reloads, stupid clients may think root is forever */
MENU_CACHE_UNLOCK;
goto _fail;
}
/* get all used files */
n = read_all_used_files( f, cache, &all_used_files );
if (n <= 0)
{
MENU_CACHE_UNLOCK;
goto _fail;
}
/* read known DEs */
g_strfreev( cache->known_des );
if( ! read_all_known_des( f, cache ) )
{
cache->known_des = NULL;
MENU_CACHE_UNLOCK;
for (i = 0; i < n; i++)
menu_cache_file_dir_unref(all_used_files[i]);
g_free(all_used_files);
_fail:
g_object_unref(f);
return FALSE;
}
cache->version = ver_min;
if(cache->root_dir)
menu_cache_item_unref( MENU_CACHE_ITEM(cache->root_dir) );
cache->root_dir = (MenuCacheDir*)read_item( f, cache, all_used_files, n );
g_object_unref(f);
g_idle_add_full(G_PRIORITY_HIGH_IDLE, reload_notify, menu_cache_ref(cache),
(GDestroyNotify)menu_cache_unref);
MENU_CACHE_UNLOCK;
for (i = 0; i < n; i++)
menu_cache_file_dir_unref(all_used_files[i]);
g_free(all_used_files);
return TRUE;
}
|
DoS
| 0
|
gboolean menu_cache_reload( MenuCache* cache )
{
char* line;
gsize len;
GFile* file;
GFileInputStream* istr = NULL;
GDataInputStream* f;
MenuCacheFileDir** all_used_files;
int i, n;
int ver_maj, ver_min;
MENU_CACHE_LOCK;
if (cache->reload_id)
g_source_remove(cache->reload_id);
cache->reload_id = 0;
MENU_CACHE_UNLOCK;
file = g_file_new_for_path(cache->cache_file);
if(!file)
return FALSE;
istr = g_file_read(file, cache->cancellable, NULL);
g_object_unref(file);
if(!istr)
return FALSE;
f = g_data_input_stream_new(G_INPUT_STREAM(istr));
g_object_unref(istr);
if( ! f )
return FALSE;
/* the first line is version number */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_LIKELY(line))
{
len = sscanf(line, "%d.%d", &ver_maj, &ver_min);
g_free(line);
if(len < 2)
goto _fail;
if( ver_maj != VER_MAJOR ||
ver_min > VER_MINOR || ver_min < VER_MINOR_SUPPORTED )
goto _fail;
}
else
goto _fail;
g_debug("menu cache: got file version 1.%d", ver_min);
/* the second line is menu name */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
goto _fail;
g_free(line);
/* FIXME: this may lock other threads for some time */
MENU_CACHE_LOCK;
if(cache->notifiers == NULL)
{
/* nobody aware of reloads, stupid clients may think root is forever */
MENU_CACHE_UNLOCK;
goto _fail;
}
/* get all used files */
n = read_all_used_files( f, cache, &all_used_files );
if (n <= 0)
{
MENU_CACHE_UNLOCK;
goto _fail;
}
/* read known DEs */
g_strfreev( cache->known_des );
if( ! read_all_known_des( f, cache ) )
{
cache->known_des = NULL;
MENU_CACHE_UNLOCK;
for (i = 0; i < n; i++)
menu_cache_file_dir_unref(all_used_files[i]);
g_free(all_used_files);
_fail:
g_object_unref(f);
return FALSE;
}
cache->version = ver_min;
if(cache->root_dir)
menu_cache_item_unref( MENU_CACHE_ITEM(cache->root_dir) );
cache->root_dir = (MenuCacheDir*)read_item( f, cache, all_used_files, n );
g_object_unref(f);
g_idle_add_full(G_PRIORITY_HIGH_IDLE, reload_notify, menu_cache_ref(cache),
(GDestroyNotify)menu_cache_unref);
MENU_CACHE_UNLOCK;
for (i = 0; i < n; i++)
menu_cache_file_dir_unref(all_used_files[i]);
g_free(all_used_files);
return TRUE;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,115
|
static gboolean menu_cache_reload_idle(gpointer cache)
{
/* do reload once */
if (!g_source_is_destroyed(g_main_current_source()))
menu_cache_reload(cache);
return FALSE;
}
|
DoS
| 0
|
static gboolean menu_cache_reload_idle(gpointer cache)
{
/* do reload once */
if (!g_source_is_destroyed(g_main_current_source()))
menu_cache_reload(cache);
return FALSE;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,116
|
void menu_cache_remove_reload_notify(MenuCache* cache, MenuCacheNotifyId notify_id)
{
MENU_CACHE_LOCK;
g_slice_free( CacheReloadNotifier, ((GSList*)notify_id)->data );
cache->notifiers = g_slist_delete_link( cache->notifiers, (GSList*)notify_id );
MENU_CACHE_UNLOCK;
}
|
DoS
| 0
|
void menu_cache_remove_reload_notify(MenuCache* cache, MenuCacheNotifyId notify_id)
{
MENU_CACHE_LOCK;
g_slice_free( CacheReloadNotifier, ((GSList*)notify_id)->data );
cache->notifiers = g_slist_delete_link( cache->notifiers, (GSList*)notify_id );
MENU_CACHE_UNLOCK;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,117
|
void menu_cache_unref(MenuCache* cache)
{
/* DEBUG("cache_unref: %d", cache->n_ref); */
/* we need a lock here unfortunately because item in hash isn't protected
by reference therefore another thread may get access to it right now */
MENU_CACHE_LOCK;
if( g_atomic_int_dec_and_test(&cache->n_ref) )
{
/* g_assert(cache->reload_id != 0); */
unregister_menu_from_server( cache );
/* DEBUG("unregister to server"); */
g_hash_table_remove( hash, cache->menu_name );
if( g_hash_table_size(hash) == 0 )
{
/* DEBUG("destroy hash"); */
g_hash_table_destroy(hash);
/* DEBUG("disconnect from server"); */
G_LOCK(connect);
shutdown(server_fd, SHUT_RDWR); /* the IO thread will terminate itself */
server_fd = -1;
G_UNLOCK(connect);
hash = NULL;
}
MENU_CACHE_UNLOCK;
if(G_LIKELY(cache->thr))
{
g_cancellable_cancel(cache->cancellable);
g_thread_join(cache->thr);
}
g_object_unref(cache->cancellable);
if( G_LIKELY(cache->root_dir) )
{
/* DEBUG("unref root dir"); */
menu_cache_item_unref( MENU_CACHE_ITEM(cache->root_dir) );
/* DEBUG("unref root dir finished"); */
}
g_free( cache->cache_file );
g_free( cache->menu_name );
g_free(cache->reg);
/* g_free( cache->menu_file_path ); */
g_strfreev(cache->known_des);
g_slist_free(cache->notifiers);
g_slice_free( MenuCache, cache );
}
else
MENU_CACHE_UNLOCK;
}
|
DoS
| 0
|
void menu_cache_unref(MenuCache* cache)
{
/* DEBUG("cache_unref: %d", cache->n_ref); */
/* we need a lock here unfortunately because item in hash isn't protected
by reference therefore another thread may get access to it right now */
MENU_CACHE_LOCK;
if( g_atomic_int_dec_and_test(&cache->n_ref) )
{
/* g_assert(cache->reload_id != 0); */
unregister_menu_from_server( cache );
/* DEBUG("unregister to server"); */
g_hash_table_remove( hash, cache->menu_name );
if( g_hash_table_size(hash) == 0 )
{
/* DEBUG("destroy hash"); */
g_hash_table_destroy(hash);
/* DEBUG("disconnect from server"); */
G_LOCK(connect);
shutdown(server_fd, SHUT_RDWR); /* the IO thread will terminate itself */
server_fd = -1;
G_UNLOCK(connect);
hash = NULL;
}
MENU_CACHE_UNLOCK;
if(G_LIKELY(cache->thr))
{
g_cancellable_cancel(cache->cancellable);
g_thread_join(cache->thr);
}
g_object_unref(cache->cancellable);
if( G_LIKELY(cache->root_dir) )
{
/* DEBUG("unref root dir"); */
menu_cache_item_unref( MENU_CACHE_ITEM(cache->root_dir) );
/* DEBUG("unref root dir finished"); */
}
g_free( cache->cache_file );
g_free( cache->menu_name );
g_free(cache->reg);
/* g_free( cache->menu_file_path ); */
g_strfreev(cache->known_des);
g_slist_free(cache->notifiers);
g_slice_free( MenuCache, cache );
}
else
MENU_CACHE_UNLOCK;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,118
|
static void read_app(GDataInputStream* f, MenuCacheApp* app, MenuCache* cache)
{
char *line;
gsize len;
GString *str;
/* generic name */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
return;
if(G_LIKELY(len > 0))
app->generic_name = _unescape_lf(line);
else
g_free(line);
/* exec */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
return;
if(G_LIKELY(len > 0))
app->exec = _unescape_lf(line);
else
g_free(line);
/* terminal / startup notify */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
return;
app->flags = (guint32)atoi(line);
g_free(line);
/* ShowIn flags */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
return;
app->show_in_flags = (guint32)atol(line);
g_free(line);
if (cache->version < 2)
return;
/* TryExec */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if (G_UNLIKELY(line == NULL))
return;
if (G_LIKELY(len > 0))
app->try_exec = g_strchomp(line);
else
g_free(line);
/* Path */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if (G_UNLIKELY(line == NULL))
return;
if (G_LIKELY(len > 0))
app->working_dir = line;
else
g_free(line);
/* Categories */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if (G_UNLIKELY(line == NULL))
return;
if (G_LIKELY(len > 0))
{
const char **x;
/* split and intern all the strings so categories can be processed
later for search doing g_quark_try_string()+g_quark_to_string() */
app->categories = x = (const char **)g_strsplit(line, ";", 0);
while (*x != NULL)
{
char *cat = (char *)*x;
*x = g_intern_string(cat);
g_free(cat);
x++;
}
}
g_free(line);
/* Keywords */
str = g_string_new(MENU_CACHE_ITEM(app)->name);
if (G_LIKELY(app->exec != NULL))
{
char *sp = strchr(app->exec, ' ');
char *bn = strrchr(app->exec, G_DIR_SEPARATOR);
g_string_append_c(str, ',');
if (bn == NULL && sp == NULL)
g_string_append(str, app->exec);
else if (bn == NULL || (sp != NULL && sp < bn))
g_string_append_len(str, app->exec, sp - app->exec);
else if (sp == NULL)
g_string_append(str, &bn[1]);
else
g_string_append_len(str, &bn[1], sp - &bn[1]);
}
if (app->generic_name != NULL)
{
g_string_append_c(str, ',');
g_string_append(str, app->generic_name);
}
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if (G_UNLIKELY(line == NULL))
return;
if (len > 0)
{
g_string_append_c(str, ',');
g_string_append(str, line);
}
app->keywords = g_utf8_casefold(str->str, str->len);
g_string_free(str, TRUE);
g_free(line);
}
|
DoS
| 0
|
static void read_app(GDataInputStream* f, MenuCacheApp* app, MenuCache* cache)
{
char *line;
gsize len;
GString *str;
/* generic name */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
return;
if(G_LIKELY(len > 0))
app->generic_name = _unescape_lf(line);
else
g_free(line);
/* exec */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
return;
if(G_LIKELY(len > 0))
app->exec = _unescape_lf(line);
else
g_free(line);
/* terminal / startup notify */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
return;
app->flags = (guint32)atoi(line);
g_free(line);
/* ShowIn flags */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
return;
app->show_in_flags = (guint32)atol(line);
g_free(line);
if (cache->version < 2)
return;
/* TryExec */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if (G_UNLIKELY(line == NULL))
return;
if (G_LIKELY(len > 0))
app->try_exec = g_strchomp(line);
else
g_free(line);
/* Path */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if (G_UNLIKELY(line == NULL))
return;
if (G_LIKELY(len > 0))
app->working_dir = line;
else
g_free(line);
/* Categories */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if (G_UNLIKELY(line == NULL))
return;
if (G_LIKELY(len > 0))
{
const char **x;
/* split and intern all the strings so categories can be processed
later for search doing g_quark_try_string()+g_quark_to_string() */
app->categories = x = (const char **)g_strsplit(line, ";", 0);
while (*x != NULL)
{
char *cat = (char *)*x;
*x = g_intern_string(cat);
g_free(cat);
x++;
}
}
g_free(line);
/* Keywords */
str = g_string_new(MENU_CACHE_ITEM(app)->name);
if (G_LIKELY(app->exec != NULL))
{
char *sp = strchr(app->exec, ' ');
char *bn = strrchr(app->exec, G_DIR_SEPARATOR);
g_string_append_c(str, ',');
if (bn == NULL && sp == NULL)
g_string_append(str, app->exec);
else if (bn == NULL || (sp != NULL && sp < bn))
g_string_append_len(str, app->exec, sp - app->exec);
else if (sp == NULL)
g_string_append(str, &bn[1]);
else
g_string_append_len(str, &bn[1], sp - &bn[1]);
}
if (app->generic_name != NULL)
{
g_string_append_c(str, ',');
g_string_append(str, app->generic_name);
}
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if (G_UNLIKELY(line == NULL))
return;
if (len > 0)
{
g_string_append_c(str, ',');
g_string_append(str, line);
}
app->keywords = g_utf8_casefold(str->str, str->len);
g_string_free(str, TRUE);
g_free(line);
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,119
|
static void read_dir(GDataInputStream* f, MenuCacheDir* dir, MenuCache* cache,
MenuCacheFileDir** all_used_files, int n_all_used_files)
{
MenuCacheItem* item;
char *line;
gsize len;
/* nodisplay flag */
if (cache->version >= 2)
{
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if (G_UNLIKELY(line == NULL))
return;
dir->flags = (guint32)atoi(line);
g_free(line);
}
/* load child items in the dir */
while( (item = read_item( f, cache, all_used_files, n_all_used_files )) )
{
/* menu_cache_ref shouldn't be called here for dir.
* Otherwise, circular reference will happen. */
item->parent = dir;
dir->children = g_slist_prepend( dir->children, item );
}
dir->children = g_slist_reverse( dir->children );
/* set flag by children if working with old cache generator */
if (cache->version == 1)
{
if (dir->children == NULL)
dir->flags = FLAG_IS_NODISPLAY;
else if ((line = menu_cache_item_get_file_path(MENU_CACHE_ITEM(dir))) != NULL)
{
GKeyFile *kf = g_key_file_new();
if (g_key_file_load_from_file(kf, line, G_KEY_FILE_NONE, NULL) &&
g_key_file_get_boolean(kf, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, NULL))
dir->flags = FLAG_IS_NODISPLAY;
g_key_file_free(kf);
g_free(line);
}
}
}
|
DoS
| 0
|
static void read_dir(GDataInputStream* f, MenuCacheDir* dir, MenuCache* cache,
MenuCacheFileDir** all_used_files, int n_all_used_files)
{
MenuCacheItem* item;
char *line;
gsize len;
/* nodisplay flag */
if (cache->version >= 2)
{
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if (G_UNLIKELY(line == NULL))
return;
dir->flags = (guint32)atoi(line);
g_free(line);
}
/* load child items in the dir */
while( (item = read_item( f, cache, all_used_files, n_all_used_files )) )
{
/* menu_cache_ref shouldn't be called here for dir.
* Otherwise, circular reference will happen. */
item->parent = dir;
dir->children = g_slist_prepend( dir->children, item );
}
dir->children = g_slist_reverse( dir->children );
/* set flag by children if working with old cache generator */
if (cache->version == 1)
{
if (dir->children == NULL)
dir->flags = FLAG_IS_NODISPLAY;
else if ((line = menu_cache_item_get_file_path(MENU_CACHE_ITEM(dir))) != NULL)
{
GKeyFile *kf = g_key_file_new();
if (g_key_file_load_from_file(kf, line, G_KEY_FILE_NONE, NULL) &&
g_key_file_get_boolean(kf, G_KEY_FILE_DESKTOP_GROUP,
G_KEY_FILE_DESKTOP_KEY_NO_DISPLAY, NULL))
dir->flags = FLAG_IS_NODISPLAY;
g_key_file_free(kf);
g_free(line);
}
}
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,120
|
static MenuCacheItem* read_item(GDataInputStream* f, MenuCache* cache,
MenuCacheFileDir** all_used_files, int n_all_used_files)
{
MenuCacheItem* item;
char *line;
gsize len;
gint idx;
/* desktop/menu id */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
return NULL;
if( G_LIKELY(len >= 1) )
{
if( line[0] == '+' ) /* menu dir */
{
item = (MenuCacheItem*)g_slice_new0( MenuCacheDir );
item->n_ref = 1;
item->type = MENU_CACHE_TYPE_DIR;
}
else if( line[0] == '-' ) /* menu item */
{
item = (MenuCacheItem*)g_slice_new0( MenuCacheApp );
item->n_ref = 1;
if( G_LIKELY( len > 1 ) ) /* application item */
item->type = MENU_CACHE_TYPE_APP;
else /* separator */
{
item->type = MENU_CACHE_TYPE_SEP;
return item;
}
}
else
return NULL;
item->id = g_strndup( line + 1, len - 1 );
g_free(line);
}
else
{
g_free(line);
return NULL;
}
/* name */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
goto _fail;
if(G_LIKELY(len > 0))
item->name = _unescape_lf(line);
else
g_free(line);
/* comment */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
goto _fail;
if(G_LIKELY(len > 0))
item->comment = _unescape_lf(line);
else
g_free(line);
/* icon */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
goto _fail;
if(G_LIKELY(len > 0))
item->icon = line;
else
g_free(line);
/* file dir/basename */
/* file name */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
goto _fail;
if(G_LIKELY(len > 0))
item->file_name = line;
else if( item->type == MENU_CACHE_TYPE_APP )
{
/* When file name is the same as desktop_id, which is
* quite common in desktop files, we use this trick to
* save memory usage. */
item->file_name = item->id;
g_free(line);
}
else
g_free(line);
/* desktop file dir */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
{
_fail:
g_free(item->id);
g_free(item->name);
g_free(item->comment);
g_free(item->icon);
if(item->file_name && item->file_name != item->id)
g_free(item->file_name);
if(item->type == MENU_CACHE_TYPE_DIR)
g_slice_free(MenuCacheDir, MENU_CACHE_DIR(item));
else
g_slice_free(MenuCacheApp, MENU_CACHE_APP(item));
return NULL;
}
idx = atoi( line );
g_free(line);
if( G_LIKELY( idx >=0 && idx < n_all_used_files ) )
{
item->file_dir = all_used_files[ idx ];
g_atomic_int_inc(&item->file_dir->n_ref);
}
if( item->type == MENU_CACHE_TYPE_DIR )
read_dir( f, MENU_CACHE_DIR(item), cache, all_used_files, n_all_used_files );
else if( item->type == MENU_CACHE_TYPE_APP )
read_app( f, MENU_CACHE_APP(item), cache );
return item;
}
|
DoS
| 0
|
static MenuCacheItem* read_item(GDataInputStream* f, MenuCache* cache,
MenuCacheFileDir** all_used_files, int n_all_used_files)
{
MenuCacheItem* item;
char *line;
gsize len;
gint idx;
/* desktop/menu id */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
return NULL;
if( G_LIKELY(len >= 1) )
{
if( line[0] == '+' ) /* menu dir */
{
item = (MenuCacheItem*)g_slice_new0( MenuCacheDir );
item->n_ref = 1;
item->type = MENU_CACHE_TYPE_DIR;
}
else if( line[0] == '-' ) /* menu item */
{
item = (MenuCacheItem*)g_slice_new0( MenuCacheApp );
item->n_ref = 1;
if( G_LIKELY( len > 1 ) ) /* application item */
item->type = MENU_CACHE_TYPE_APP;
else /* separator */
{
item->type = MENU_CACHE_TYPE_SEP;
return item;
}
}
else
return NULL;
item->id = g_strndup( line + 1, len - 1 );
g_free(line);
}
else
{
g_free(line);
return NULL;
}
/* name */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
goto _fail;
if(G_LIKELY(len > 0))
item->name = _unescape_lf(line);
else
g_free(line);
/* comment */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
goto _fail;
if(G_LIKELY(len > 0))
item->comment = _unescape_lf(line);
else
g_free(line);
/* icon */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
goto _fail;
if(G_LIKELY(len > 0))
item->icon = line;
else
g_free(line);
/* file dir/basename */
/* file name */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
goto _fail;
if(G_LIKELY(len > 0))
item->file_name = line;
else if( item->type == MENU_CACHE_TYPE_APP )
{
/* When file name is the same as desktop_id, which is
* quite common in desktop files, we use this trick to
* save memory usage. */
item->file_name = item->id;
g_free(line);
}
else
g_free(line);
/* desktop file dir */
line = g_data_input_stream_read_line(f, &len, cache->cancellable, NULL);
if(G_UNLIKELY(line == NULL))
{
_fail:
g_free(item->id);
g_free(item->name);
g_free(item->comment);
g_free(item->icon);
if(item->file_name && item->file_name != item->id)
g_free(item->file_name);
if(item->type == MENU_CACHE_TYPE_DIR)
g_slice_free(MenuCacheDir, MENU_CACHE_DIR(item));
else
g_slice_free(MenuCacheApp, MENU_CACHE_APP(item));
return NULL;
}
idx = atoi( line );
g_free(line);
if( G_LIKELY( idx >=0 && idx < n_all_used_files ) )
{
item->file_dir = all_used_files[ idx ];
g_atomic_int_inc(&item->file_dir->n_ref);
}
if( item->type == MENU_CACHE_TYPE_DIR )
read_dir( f, MENU_CACHE_DIR(item), cache, all_used_files, n_all_used_files );
else if( item->type == MENU_CACHE_TYPE_APP )
read_app( f, MENU_CACHE_APP(item), cache );
return item;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,121
|
static gboolean reload_notify(gpointer data)
{
MenuCache* cache = (MenuCache*)data;
GSList* l;
MENU_CACHE_LOCK;
/* we have it referenced and there is no source removal so no check */
for( l = cache->notifiers; l; l = l->next )
{
CacheReloadNotifier* n = (CacheReloadNotifier*)l->data;
if(n->func)
n->func( cache, n->user_data );
}
MENU_CACHE_UNLOCK;
return FALSE;
}
|
DoS
| 0
|
static gboolean reload_notify(gpointer data)
{
MenuCache* cache = (MenuCache*)data;
GSList* l;
MENU_CACHE_LOCK;
/* we have it referenced and there is no source removal so no check */
for( l = cache->notifiers; l; l = l->next )
{
CacheReloadNotifier* n = (CacheReloadNotifier*)l->data;
if(n->func)
n->func( cache, n->user_data );
}
MENU_CACHE_UNLOCK;
return FALSE;
}
|
@@ -3,7 +3,7 @@
*
* Copyright 2008 PCMan <pcman.tw@gmail.com>
* Copyright 2009 Jürgen Hötzel <juergen@archlinux.org>
- * Copyright 2012-2015 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
+ * Copyright 2012-2017 Andriy Grytsenko (LStranger) <andrej@rep.kiev.ua>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1538,8 +1538,13 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+#if GLIB_CHECK_VERSION(2, 28, 0)
+ g_snprintf( buf, len, "%s/menu-cached-%s", g_get_user_runtime_dir(),
+ dpy ? dpy : ":0" );
+#else
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
+#endif
g_free(dpy);
}
|
CWE-20
| null | null |
5,122
|
static gboolean cache_file_is_updated( const char* cache_file, int* n_used_files, char*** used_files )
{
gboolean ret = FALSE;
struct stat st;
#if 0
time_t cache_mtime;
char** files;
int n, i;
#endif
FILE* f;
f = fopen( cache_file, "r" );
if( f )
{
if( fstat( fileno(f), &st) == 0 )
{
#if 0
cache_mtime = st.st_mtime;
if( read_all_used_files(f, &n, &files) )
{
for( i =0; i < n; ++i )
{
/* files[i][0] is 'D' or 'F' indicating file type. */
if( stat( files[i] + 1, &st ) == -1 )
continue;
if( st.st_mtime > cache_mtime )
break;
}
if( i >= n )
{
ret = TRUE;
*n_used_files = n;
*used_files = files;
}
}
#else
ret = read_all_used_files(f, n_used_files, used_files);
#endif
}
fclose( f );
}
return ret;
}
|
DoS
| 0
|
static gboolean cache_file_is_updated( const char* cache_file, int* n_used_files, char*** used_files )
{
gboolean ret = FALSE;
struct stat st;
#if 0
time_t cache_mtime;
char** files;
int n, i;
#endif
FILE* f;
f = fopen( cache_file, "r" );
if( f )
{
if( fstat( fileno(f), &st) == 0 )
{
#if 0
cache_mtime = st.st_mtime;
if( read_all_used_files(f, &n, &files) )
{
for( i =0; i < n; ++i )
{
/* files[i][0] is 'D' or 'F' indicating file type. */
if( stat( files[i] + 1, &st ) == -1 )
continue;
if( st.st_mtime > cache_mtime )
break;
}
if( i >= n )
{
ret = TRUE;
*n_used_files = n;
*used_files = files;
}
}
#else
ret = read_all_used_files(f, n_used_files, used_files);
#endif
}
fclose( f );
}
return ret;
}
|
@@ -473,6 +473,9 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+ /* NOTE: this socket name is incompatible with versions > 1.0.2,
+ although this function is never used since 0.7.0 but
+ libmenu-cache always requests exact socket name instead */
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
g_free(dpy);
|
CWE-20
| null | null |
5,123
|
static gboolean delayed_cache_free(gpointer data)
{
Cache* cache = data;
int i;
if(g_source_is_destroyed(g_main_current_source()))
return FALSE;
g_hash_table_remove( hash, cache->md5 );
/* DEBUG("menu cache freed"); */
for(i = 0; i < cache->n_files; ++i)
{
g_file_monitor_cancel( cache->mons[i] );
g_object_unref( cache->mons[i] );
}
/*
g_file_monitor_cancel(cache->cache_mon);
g_object_unref(cache->cache_mon);
*/
g_free( cache->mons );
g_free(cache->menu_name);
g_free(cache->lang_name);
g_free(cache->cache_file);
g_strfreev( cache->env );
g_strfreev( cache->files );
if( cache->delayed_reload_handler )
g_source_remove( cache->delayed_reload_handler );
g_slice_free( Cache, cache );
if(g_hash_table_size(hash) == 0)
g_main_loop_quit(main_loop);
return FALSE;
}
|
DoS
| 0
|
static gboolean delayed_cache_free(gpointer data)
{
Cache* cache = data;
int i;
if(g_source_is_destroyed(g_main_current_source()))
return FALSE;
g_hash_table_remove( hash, cache->md5 );
/* DEBUG("menu cache freed"); */
for(i = 0; i < cache->n_files; ++i)
{
g_file_monitor_cancel( cache->mons[i] );
g_object_unref( cache->mons[i] );
}
/*
g_file_monitor_cancel(cache->cache_mon);
g_object_unref(cache->cache_mon);
*/
g_free( cache->mons );
g_free(cache->menu_name);
g_free(cache->lang_name);
g_free(cache->cache_file);
g_strfreev( cache->env );
g_strfreev( cache->files );
if( cache->delayed_reload_handler )
g_source_remove( cache->delayed_reload_handler );
g_slice_free( Cache, cache );
if(g_hash_table_size(hash) == 0)
g_main_loop_quit(main_loop);
return FALSE;
}
|
@@ -473,6 +473,9 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+ /* NOTE: this socket name is incompatible with versions > 1.0.2,
+ although this function is never used since 0.7.0 but
+ libmenu-cache always requests exact socket name instead */
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
g_free(dpy);
|
CWE-20
| null | null |
5,124
|
static gboolean delayed_reload( Cache* cache )
{
if(g_source_is_destroyed(g_main_current_source()))
return FALSE;
if(cache->need_reload)
do_reload(cache);
if (cache->need_reload)
return TRUE;
cache->delayed_reload_handler = 0;
return FALSE;
}
|
DoS
| 0
|
static gboolean delayed_reload( Cache* cache )
{
if(g_source_is_destroyed(g_main_current_source()))
return FALSE;
if(cache->need_reload)
do_reload(cache);
if (cache->need_reload)
return TRUE;
cache->delayed_reload_handler = 0;
return FALSE;
}
|
@@ -473,6 +473,9 @@ static void get_socket_name( char* buf, int len )
if(*p)
*p = '\0';
}
+ /* NOTE: this socket name is incompatible with versions > 1.0.2,
+ although this function is never used since 0.7.0 but
+ libmenu-cache always requests exact socket name instead */
g_snprintf( buf, len, "%s/.menu-cached-%s-%s", g_get_tmp_dir(),
dpy ? dpy : ":0", g_get_user_name() );
g_free(dpy);
|
CWE-20
| null | null |
5,125
|
int EC_GROUP_get_basis_type(const EC_GROUP *group)
{
int i = 0;
if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
NID_X9_62_characteristic_two_field)
/* everything else is currently not supported */
return 0;
while (group->poly[i] != 0)
i++;
if (i == 4)
return NID_X9_62_ppBasis;
else if (i == 2)
return NID_X9_62_tpBasis;
else
/* everything else is currently not supported */
return 0;
}
|
DoS Mem. Corr.
| 0
|
int EC_GROUP_get_basis_type(const EC_GROUP *group)
{
int i = 0;
if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) !=
NID_X9_62_characteristic_two_field)
/* everything else is currently not supported */
return 0;
while (group->poly[i] != 0)
i++;
if (i == 4)
return NID_X9_62_ppBasis;
else if (i == 2)
return NID_X9_62_tpBasis;
else
/* everything else is currently not supported */
return 0;
}
|
@@ -1014,8 +1014,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
- if (a)
- *a = ret;
} else
ret = *a;
@@ -1067,10 +1065,12 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
}
}
+ if (a)
+ *a = ret;
ok = 1;
err:
if (!ok) {
- if (ret)
+ if (ret && (a == NULL || *a != ret))
EC_KEY_free(ret);
ret = NULL;
}
| null | null | null |
5,126
|
int EC_GROUP_get_pentanomial_basis(const EC_GROUP *group, unsigned int *k1,
unsigned int *k2, unsigned int *k3)
{
if (group == NULL)
return 0;
if (EC_GROUP_method_of(group)->group_set_curve !=
ec_GF2m_simple_group_set_curve || !((group->poly[0] != 0)
&& (group->poly[1] != 0)
&& (group->poly[2] != 0)
&& (group->poly[3] != 0)
&& (group->poly[4] == 0))) {
ECerr(EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS,
ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
if (k1)
*k1 = group->poly[3];
if (k2)
*k2 = group->poly[2];
if (k3)
*k3 = group->poly[1];
return 1;
}
|
DoS Mem. Corr.
| 0
|
int EC_GROUP_get_pentanomial_basis(const EC_GROUP *group, unsigned int *k1,
unsigned int *k2, unsigned int *k3)
{
if (group == NULL)
return 0;
if (EC_GROUP_method_of(group)->group_set_curve !=
ec_GF2m_simple_group_set_curve || !((group->poly[0] != 0)
&& (group->poly[1] != 0)
&& (group->poly[2] != 0)
&& (group->poly[3] != 0)
&& (group->poly[4] == 0))) {
ECerr(EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS,
ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
return 0;
}
if (k1)
*k1 = group->poly[3];
if (k2)
*k2 = group->poly[2];
if (k3)
*k3 = group->poly[1];
return 1;
}
|
@@ -1014,8 +1014,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
- if (a)
- *a = ret;
} else
ret = *a;
@@ -1067,10 +1065,12 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
}
}
+ if (a)
+ *a = ret;
ok = 1;
err:
if (!ok) {
- if (ret)
+ if (ret && (a == NULL || *a != ret))
EC_KEY_free(ret);
ret = NULL;
}
| null | null | null |
5,127
|
static int ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field)
{
int ok = 0, nid;
BIGNUM *tmp = NULL;
if (group == NULL || field == NULL)
return 0;
/* clear the old values (if necessary) */
if (field->fieldType != NULL)
ASN1_OBJECT_free(field->fieldType);
if (field->p.other != NULL)
ASN1_TYPE_free(field->p.other);
nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group));
/* set OID for the field */
if ((field->fieldType = OBJ_nid2obj(nid)) == NULL) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_OBJ_LIB);
goto err;
}
if (nid == NID_X9_62_prime_field) {
if ((tmp = BN_new()) == NULL) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE);
goto err;
}
/* the parameters are specified by the prime number p */
if (!EC_GROUP_get_curve_GFp(group, tmp, NULL, NULL, NULL)) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_EC_LIB);
goto err;
}
/* set the prime number */
field->p.prime = BN_to_ASN1_INTEGER(tmp, NULL);
if (field->p.prime == NULL) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_ASN1_LIB);
goto err;
}
} else { /* nid == NID_X9_62_characteristic_two_field */
int field_type;
X9_62_CHARACTERISTIC_TWO *char_two;
field->p.char_two = X9_62_CHARACTERISTIC_TWO_new();
char_two = field->p.char_two;
if (char_two == NULL) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE);
goto err;
}
char_two->m = (long)EC_GROUP_get_degree(group);
field_type = EC_GROUP_get_basis_type(group);
if (field_type == 0) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_EC_LIB);
goto err;
}
/* set base type OID */
if ((char_two->type = OBJ_nid2obj(field_type)) == NULL) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_OBJ_LIB);
goto err;
}
if (field_type == NID_X9_62_tpBasis) {
unsigned int k;
if (!EC_GROUP_get_trinomial_basis(group, &k))
goto err;
char_two->p.tpBasis = ASN1_INTEGER_new();
if (!char_two->p.tpBasis) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!ASN1_INTEGER_set(char_two->p.tpBasis, (long)k)) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_ASN1_LIB);
goto err;
}
} else if (field_type == NID_X9_62_ppBasis) {
unsigned int k1, k2, k3;
if (!EC_GROUP_get_pentanomial_basis(group, &k1, &k2, &k3))
goto err;
char_two->p.ppBasis = X9_62_PENTANOMIAL_new();
if (!char_two->p.ppBasis) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE);
goto err;
}
/* set k? values */
char_two->p.ppBasis->k1 = (long)k1;
char_two->p.ppBasis->k2 = (long)k2;
char_two->p.ppBasis->k3 = (long)k3;
} else { /* field_type == NID_X9_62_onBasis */
/* for ONB the parameters are (asn1) NULL */
char_two->p.onBasis = ASN1_NULL_new();
if (!char_two->p.onBasis) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE);
goto err;
}
}
}
ok = 1;
err:if (tmp)
BN_free(tmp);
return (ok);
}
|
DoS Mem. Corr.
| 0
|
static int ec_asn1_group2fieldid(const EC_GROUP *group, X9_62_FIELDID *field)
{
int ok = 0, nid;
BIGNUM *tmp = NULL;
if (group == NULL || field == NULL)
return 0;
/* clear the old values (if necessary) */
if (field->fieldType != NULL)
ASN1_OBJECT_free(field->fieldType);
if (field->p.other != NULL)
ASN1_TYPE_free(field->p.other);
nid = EC_METHOD_get_field_type(EC_GROUP_method_of(group));
/* set OID for the field */
if ((field->fieldType = OBJ_nid2obj(nid)) == NULL) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_OBJ_LIB);
goto err;
}
if (nid == NID_X9_62_prime_field) {
if ((tmp = BN_new()) == NULL) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE);
goto err;
}
/* the parameters are specified by the prime number p */
if (!EC_GROUP_get_curve_GFp(group, tmp, NULL, NULL, NULL)) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_EC_LIB);
goto err;
}
/* set the prime number */
field->p.prime = BN_to_ASN1_INTEGER(tmp, NULL);
if (field->p.prime == NULL) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_ASN1_LIB);
goto err;
}
} else { /* nid == NID_X9_62_characteristic_two_field */
int field_type;
X9_62_CHARACTERISTIC_TWO *char_two;
field->p.char_two = X9_62_CHARACTERISTIC_TWO_new();
char_two = field->p.char_two;
if (char_two == NULL) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE);
goto err;
}
char_two->m = (long)EC_GROUP_get_degree(group);
field_type = EC_GROUP_get_basis_type(group);
if (field_type == 0) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_EC_LIB);
goto err;
}
/* set base type OID */
if ((char_two->type = OBJ_nid2obj(field_type)) == NULL) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_OBJ_LIB);
goto err;
}
if (field_type == NID_X9_62_tpBasis) {
unsigned int k;
if (!EC_GROUP_get_trinomial_basis(group, &k))
goto err;
char_two->p.tpBasis = ASN1_INTEGER_new();
if (!char_two->p.tpBasis) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!ASN1_INTEGER_set(char_two->p.tpBasis, (long)k)) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_ASN1_LIB);
goto err;
}
} else if (field_type == NID_X9_62_ppBasis) {
unsigned int k1, k2, k3;
if (!EC_GROUP_get_pentanomial_basis(group, &k1, &k2, &k3))
goto err;
char_two->p.ppBasis = X9_62_PENTANOMIAL_new();
if (!char_two->p.ppBasis) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE);
goto err;
}
/* set k? values */
char_two->p.ppBasis->k1 = (long)k1;
char_two->p.ppBasis->k2 = (long)k2;
char_two->p.ppBasis->k3 = (long)k3;
} else { /* field_type == NID_X9_62_onBasis */
/* for ONB the parameters are (asn1) NULL */
char_two->p.onBasis = ASN1_NULL_new();
if (!char_two->p.onBasis) {
ECerr(EC_F_EC_ASN1_GROUP2FIELDID, ERR_R_MALLOC_FAILURE);
goto err;
}
}
}
ok = 1;
err:if (tmp)
BN_free(tmp);
return (ok);
}
|
@@ -1014,8 +1014,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
- if (a)
- *a = ret;
} else
ret = *a;
@@ -1067,10 +1065,12 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
}
}
+ if (a)
+ *a = ret;
ok = 1;
err:
if (!ok) {
- if (ret)
+ if (ret && (a == NULL || *a != ret))
EC_KEY_free(ret);
ret = NULL;
}
| null | null | null |
5,128
|
static EC_GROUP *ec_asn1_parameters2group(const ECPARAMETERS *params)
{
int ok = 0, tmp;
EC_GROUP *ret = NULL;
BIGNUM *p = NULL, *a = NULL, *b = NULL;
EC_POINT *point = NULL;
long field_bits;
if (!params->fieldID || !params->fieldID->fieldType ||
!params->fieldID->p.ptr) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
/* now extract the curve parameters a and b */
if (!params->curve || !params->curve->a ||
!params->curve->a->data || !params->curve->b ||
!params->curve->b->data) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
a = BN_bin2bn(params->curve->a->data, params->curve->a->length, NULL);
if (a == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_BN_LIB);
goto err;
}
b = BN_bin2bn(params->curve->b->data, params->curve->b->length, NULL);
if (b == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_BN_LIB);
goto err;
}
/* get the field parameters */
tmp = OBJ_obj2nid(params->fieldID->fieldType);
if (tmp == NID_X9_62_characteristic_two_field) {
X9_62_CHARACTERISTIC_TWO *char_two;
char_two = params->fieldID->p.char_two;
field_bits = char_two->m;
if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_FIELD_TOO_LARGE);
goto err;
}
if ((p = BN_new()) == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_MALLOC_FAILURE);
goto err;
}
/* get the base type */
tmp = OBJ_obj2nid(char_two->type);
if (tmp == NID_X9_62_tpBasis) {
long tmp_long;
if (!char_two->p.tpBasis) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
tmp_long = ASN1_INTEGER_get(char_two->p.tpBasis);
if (!(char_two->m > tmp_long && tmp_long > 0)) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP,
EC_R_INVALID_TRINOMIAL_BASIS);
goto err;
}
/* create the polynomial */
if (!BN_set_bit(p, (int)char_two->m))
goto err;
if (!BN_set_bit(p, (int)tmp_long))
goto err;
if (!BN_set_bit(p, 0))
goto err;
} else if (tmp == NID_X9_62_ppBasis) {
X9_62_PENTANOMIAL *penta;
penta = char_two->p.ppBasis;
if (!penta) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
if (!
(char_two->m > penta->k3 && penta->k3 > penta->k2
&& penta->k2 > penta->k1 && penta->k1 > 0)) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP,
EC_R_INVALID_PENTANOMIAL_BASIS);
goto err;
}
/* create the polynomial */
if (!BN_set_bit(p, (int)char_two->m))
goto err;
if (!BN_set_bit(p, (int)penta->k1))
goto err;
if (!BN_set_bit(p, (int)penta->k2))
goto err;
if (!BN_set_bit(p, (int)penta->k3))
goto err;
if (!BN_set_bit(p, 0))
goto err;
} else if (tmp == NID_X9_62_onBasis) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_NOT_IMPLEMENTED);
goto err;
} else { /* error */
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
/* create the EC_GROUP structure */
ret = EC_GROUP_new_curve_GF2m(p, a, b, NULL);
} else if (tmp == NID_X9_62_prime_field) {
/* we have a curve over a prime field */
/* extract the prime number */
if (!params->fieldID->p.prime) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
p = ASN1_INTEGER_to_BN(params->fieldID->p.prime, NULL);
if (p == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);
goto err;
}
if (BN_is_negative(p) || BN_is_zero(p)) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_FIELD);
goto err;
}
field_bits = BN_num_bits(p);
if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_FIELD_TOO_LARGE);
goto err;
}
/* create the EC_GROUP structure */
ret = EC_GROUP_new_curve_GFp(p, a, b, NULL);
} else {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_FIELD);
goto err;
}
if (ret == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB);
goto err;
}
/* extract seed (optional) */
if (params->curve->seed != NULL) {
if (ret->seed != NULL)
OPENSSL_free(ret->seed);
if (!(ret->seed = OPENSSL_malloc(params->curve->seed->length))) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_MALLOC_FAILURE);
goto err;
}
memcpy(ret->seed, params->curve->seed->data,
params->curve->seed->length);
ret->seed_len = params->curve->seed->length;
}
if (!params->order || !params->base || !params->base->data) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
if ((point = EC_POINT_new(ret)) == NULL)
goto err;
/* set the point conversion form */
EC_GROUP_set_point_conversion_form(ret, (point_conversion_form_t)
(params->base->data[0] & ~0x01));
/* extract the ec point */
if (!EC_POINT_oct2point(ret, point, params->base->data,
params->base->length, NULL)) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB);
goto err;
}
/* extract the order */
if ((a = ASN1_INTEGER_to_BN(params->order, a)) == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);
goto err;
}
if (BN_is_negative(a) || BN_is_zero(a)) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_GROUP_ORDER);
goto err;
}
if (BN_num_bits(a) > (int)field_bits + 1) { /* Hasse bound */
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_GROUP_ORDER);
goto err;
}
/* extract the cofactor (optional) */
if (params->cofactor == NULL) {
if (b) {
BN_free(b);
b = NULL;
}
} else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);
goto err;
}
/* set the generator, order and cofactor (if present) */
if (!EC_GROUP_set_generator(ret, point, a, b)) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB);
goto err;
}
ok = 1;
err:if (!ok) {
if (ret)
EC_GROUP_clear_free(ret);
ret = NULL;
}
if (p)
BN_free(p);
if (a)
BN_free(a);
if (b)
BN_free(b);
if (point)
EC_POINT_free(point);
return (ret);
}
|
DoS Mem. Corr.
| 0
|
static EC_GROUP *ec_asn1_parameters2group(const ECPARAMETERS *params)
{
int ok = 0, tmp;
EC_GROUP *ret = NULL;
BIGNUM *p = NULL, *a = NULL, *b = NULL;
EC_POINT *point = NULL;
long field_bits;
if (!params->fieldID || !params->fieldID->fieldType ||
!params->fieldID->p.ptr) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
/* now extract the curve parameters a and b */
if (!params->curve || !params->curve->a ||
!params->curve->a->data || !params->curve->b ||
!params->curve->b->data) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
a = BN_bin2bn(params->curve->a->data, params->curve->a->length, NULL);
if (a == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_BN_LIB);
goto err;
}
b = BN_bin2bn(params->curve->b->data, params->curve->b->length, NULL);
if (b == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_BN_LIB);
goto err;
}
/* get the field parameters */
tmp = OBJ_obj2nid(params->fieldID->fieldType);
if (tmp == NID_X9_62_characteristic_two_field) {
X9_62_CHARACTERISTIC_TWO *char_two;
char_two = params->fieldID->p.char_two;
field_bits = char_two->m;
if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_FIELD_TOO_LARGE);
goto err;
}
if ((p = BN_new()) == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_MALLOC_FAILURE);
goto err;
}
/* get the base type */
tmp = OBJ_obj2nid(char_two->type);
if (tmp == NID_X9_62_tpBasis) {
long tmp_long;
if (!char_two->p.tpBasis) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
tmp_long = ASN1_INTEGER_get(char_two->p.tpBasis);
if (!(char_two->m > tmp_long && tmp_long > 0)) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP,
EC_R_INVALID_TRINOMIAL_BASIS);
goto err;
}
/* create the polynomial */
if (!BN_set_bit(p, (int)char_two->m))
goto err;
if (!BN_set_bit(p, (int)tmp_long))
goto err;
if (!BN_set_bit(p, 0))
goto err;
} else if (tmp == NID_X9_62_ppBasis) {
X9_62_PENTANOMIAL *penta;
penta = char_two->p.ppBasis;
if (!penta) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
if (!
(char_two->m > penta->k3 && penta->k3 > penta->k2
&& penta->k2 > penta->k1 && penta->k1 > 0)) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP,
EC_R_INVALID_PENTANOMIAL_BASIS);
goto err;
}
/* create the polynomial */
if (!BN_set_bit(p, (int)char_two->m))
goto err;
if (!BN_set_bit(p, (int)penta->k1))
goto err;
if (!BN_set_bit(p, (int)penta->k2))
goto err;
if (!BN_set_bit(p, (int)penta->k3))
goto err;
if (!BN_set_bit(p, 0))
goto err;
} else if (tmp == NID_X9_62_onBasis) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_NOT_IMPLEMENTED);
goto err;
} else { /* error */
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
/* create the EC_GROUP structure */
ret = EC_GROUP_new_curve_GF2m(p, a, b, NULL);
} else if (tmp == NID_X9_62_prime_field) {
/* we have a curve over a prime field */
/* extract the prime number */
if (!params->fieldID->p.prime) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
p = ASN1_INTEGER_to_BN(params->fieldID->p.prime, NULL);
if (p == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);
goto err;
}
if (BN_is_negative(p) || BN_is_zero(p)) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_FIELD);
goto err;
}
field_bits = BN_num_bits(p);
if (field_bits > OPENSSL_ECC_MAX_FIELD_BITS) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_FIELD_TOO_LARGE);
goto err;
}
/* create the EC_GROUP structure */
ret = EC_GROUP_new_curve_GFp(p, a, b, NULL);
} else {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_FIELD);
goto err;
}
if (ret == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB);
goto err;
}
/* extract seed (optional) */
if (params->curve->seed != NULL) {
if (ret->seed != NULL)
OPENSSL_free(ret->seed);
if (!(ret->seed = OPENSSL_malloc(params->curve->seed->length))) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_MALLOC_FAILURE);
goto err;
}
memcpy(ret->seed, params->curve->seed->data,
params->curve->seed->length);
ret->seed_len = params->curve->seed->length;
}
if (!params->order || !params->base || !params->base->data) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_ASN1_ERROR);
goto err;
}
if ((point = EC_POINT_new(ret)) == NULL)
goto err;
/* set the point conversion form */
EC_GROUP_set_point_conversion_form(ret, (point_conversion_form_t)
(params->base->data[0] & ~0x01));
/* extract the ec point */
if (!EC_POINT_oct2point(ret, point, params->base->data,
params->base->length, NULL)) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB);
goto err;
}
/* extract the order */
if ((a = ASN1_INTEGER_to_BN(params->order, a)) == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);
goto err;
}
if (BN_is_negative(a) || BN_is_zero(a)) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_GROUP_ORDER);
goto err;
}
if (BN_num_bits(a) > (int)field_bits + 1) { /* Hasse bound */
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, EC_R_INVALID_GROUP_ORDER);
goto err;
}
/* extract the cofactor (optional) */
if (params->cofactor == NULL) {
if (b) {
BN_free(b);
b = NULL;
}
} else if ((b = ASN1_INTEGER_to_BN(params->cofactor, b)) == NULL) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_ASN1_LIB);
goto err;
}
/* set the generator, order and cofactor (if present) */
if (!EC_GROUP_set_generator(ret, point, a, b)) {
ECerr(EC_F_EC_ASN1_PARAMETERS2GROUP, ERR_R_EC_LIB);
goto err;
}
ok = 1;
err:if (!ok) {
if (ret)
EC_GROUP_clear_free(ret);
ret = NULL;
}
if (p)
BN_free(p);
if (a)
BN_free(a);
if (b)
BN_free(b);
if (point)
EC_POINT_free(point);
return (ret);
}
|
@@ -1014,8 +1014,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
- if (a)
- *a = ret;
} else
ret = *a;
@@ -1067,10 +1065,12 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
}
}
+ if (a)
+ *a = ret;
ok = 1;
err:
if (!ok) {
- if (ret)
+ if (ret && (a == NULL || *a != ret))
EC_KEY_free(ret);
ret = NULL;
}
| null | null | null |
5,129
|
EC_GROUP *ec_asn1_pkparameters2group(const ECPKPARAMETERS *params)
{
EC_GROUP *ret = NULL;
int tmp = 0;
if (params == NULL) {
ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, EC_R_MISSING_PARAMETERS);
return NULL;
}
if (params->type == 0) { /* the curve is given by an OID */
tmp = OBJ_obj2nid(params->value.named_curve);
if ((ret = EC_GROUP_new_by_curve_name(tmp)) == NULL) {
ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP,
EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);
return NULL;
}
EC_GROUP_set_asn1_flag(ret, OPENSSL_EC_NAMED_CURVE);
} else if (params->type == 1) { /* the parameters are given by a
* ECPARAMETERS structure */
ret = ec_asn1_parameters2group(params->value.parameters);
if (!ret) {
ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, ERR_R_EC_LIB);
return NULL;
}
EC_GROUP_set_asn1_flag(ret, 0x0);
} else if (params->type == 2) { /* implicitlyCA */
return NULL;
} else {
ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, EC_R_ASN1_ERROR);
return NULL;
}
return ret;
}
|
DoS Mem. Corr.
| 0
|
EC_GROUP *ec_asn1_pkparameters2group(const ECPKPARAMETERS *params)
{
EC_GROUP *ret = NULL;
int tmp = 0;
if (params == NULL) {
ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, EC_R_MISSING_PARAMETERS);
return NULL;
}
if (params->type == 0) { /* the curve is given by an OID */
tmp = OBJ_obj2nid(params->value.named_curve);
if ((ret = EC_GROUP_new_by_curve_name(tmp)) == NULL) {
ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP,
EC_R_EC_GROUP_NEW_BY_NAME_FAILURE);
return NULL;
}
EC_GROUP_set_asn1_flag(ret, OPENSSL_EC_NAMED_CURVE);
} else if (params->type == 1) { /* the parameters are given by a
* ECPARAMETERS structure */
ret = ec_asn1_parameters2group(params->value.parameters);
if (!ret) {
ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, ERR_R_EC_LIB);
return NULL;
}
EC_GROUP_set_asn1_flag(ret, 0x0);
} else if (params->type == 2) { /* implicitlyCA */
return NULL;
} else {
ECerr(EC_F_EC_ASN1_PKPARAMETERS2GROUP, EC_R_ASN1_ERROR);
return NULL;
}
return ret;
}
|
@@ -1014,8 +1014,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
- if (a)
- *a = ret;
} else
ret = *a;
@@ -1067,10 +1065,12 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
}
}
+ if (a)
+ *a = ret;
ok = 1;
err:
if (!ok) {
- if (ret)
+ if (ret && (a == NULL || *a != ret))
EC_KEY_free(ret);
ret = NULL;
}
| null | null | null |
5,130
|
int i2d_ECPKParameters(const EC_GROUP *a, unsigned char **out)
{
int ret = 0;
ECPKPARAMETERS *tmp = ec_asn1_group2pkparameters(a, NULL);
if (tmp == NULL) {
ECerr(EC_F_I2D_ECPKPARAMETERS, EC_R_GROUP2PKPARAMETERS_FAILURE);
return 0;
}
if ((ret = i2d_ECPKPARAMETERS(tmp, out)) == 0) {
ECerr(EC_F_I2D_ECPKPARAMETERS, EC_R_I2D_ECPKPARAMETERS_FAILURE);
ECPKPARAMETERS_free(tmp);
return 0;
}
ECPKPARAMETERS_free(tmp);
return (ret);
}
|
DoS Mem. Corr.
| 0
|
int i2d_ECPKParameters(const EC_GROUP *a, unsigned char **out)
{
int ret = 0;
ECPKPARAMETERS *tmp = ec_asn1_group2pkparameters(a, NULL);
if (tmp == NULL) {
ECerr(EC_F_I2D_ECPKPARAMETERS, EC_R_GROUP2PKPARAMETERS_FAILURE);
return 0;
}
if ((ret = i2d_ECPKPARAMETERS(tmp, out)) == 0) {
ECerr(EC_F_I2D_ECPKPARAMETERS, EC_R_I2D_ECPKPARAMETERS_FAILURE);
ECPKPARAMETERS_free(tmp);
return 0;
}
ECPKPARAMETERS_free(tmp);
return (ret);
}
|
@@ -1014,8 +1014,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
- if (a)
- *a = ret;
} else
ret = *a;
@@ -1067,10 +1065,12 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
}
}
+ if (a)
+ *a = ret;
ok = 1;
err:
if (!ok) {
- if (ret)
+ if (ret && (a == NULL || *a != ret))
EC_KEY_free(ret);
ret = NULL;
}
| null | null | null |
5,131
|
int i2d_ECParameters(EC_KEY *a, unsigned char **out)
{
if (a == NULL) {
ECerr(EC_F_I2D_ECPARAMETERS, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
return i2d_ECPKParameters(a->group, out);
}
|
DoS Mem. Corr.
| 0
|
int i2d_ECParameters(EC_KEY *a, unsigned char **out)
{
if (a == NULL) {
ECerr(EC_F_I2D_ECPARAMETERS, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
return i2d_ECPKParameters(a->group, out);
}
|
@@ -1014,8 +1014,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
- if (a)
- *a = ret;
} else
ret = *a;
@@ -1067,10 +1065,12 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
}
}
+ if (a)
+ *a = ret;
ok = 1;
err:
if (!ok) {
- if (ret)
+ if (ret && (a == NULL || *a != ret))
EC_KEY_free(ret);
ret = NULL;
}
| null | null | null |
5,132
|
int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
{
int ret = 0, ok = 0;
unsigned char *buffer = NULL;
size_t buf_len = 0, tmp_len;
EC_PRIVATEKEY *priv_key = NULL;
if (a == NULL || a->group == NULL || a->priv_key == NULL) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_PASSED_NULL_PARAMETER);
goto err;
}
if ((priv_key = EC_PRIVATEKEY_new()) == NULL) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
priv_key->version = a->version;
buf_len = (size_t)BN_num_bytes(a->priv_key);
buffer = OPENSSL_malloc(buf_len);
if (buffer == NULL) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!BN_bn2bin(a->priv_key, buffer)) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_BN_LIB);
goto err;
}
if (!M_ASN1_OCTET_STRING_set(priv_key->privateKey, buffer, buf_len)) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_ASN1_LIB);
goto err;
}
if (!(a->enc_flag & EC_PKEY_NO_PARAMETERS)) {
if ((priv_key->parameters =
ec_asn1_group2pkparameters(a->group,
priv_key->parameters)) == NULL) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB);
goto err;
}
}
if (!(a->enc_flag & EC_PKEY_NO_PUBKEY)) {
priv_key->publicKey = M_ASN1_BIT_STRING_new();
if (priv_key->publicKey == NULL) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
tmp_len = EC_POINT_point2oct(a->group, a->pub_key,
a->conv_form, NULL, 0, NULL);
if (tmp_len > buf_len) {
unsigned char *tmp_buffer = OPENSSL_realloc(buffer, tmp_len);
if (!tmp_buffer) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
buffer = tmp_buffer;
buf_len = tmp_len;
}
if (!EC_POINT_point2oct(a->group, a->pub_key,
a->conv_form, buffer, buf_len, NULL)) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB);
goto err;
}
priv_key->publicKey->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
priv_key->publicKey->flags |= ASN1_STRING_FLAG_BITS_LEFT;
if (!M_ASN1_BIT_STRING_set(priv_key->publicKey, buffer, buf_len)) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_ASN1_LIB);
goto err;
}
}
if ((ret = i2d_EC_PRIVATEKEY(priv_key, out)) == 0) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB);
goto err;
}
ok = 1;
err:
if (buffer)
OPENSSL_free(buffer);
if (priv_key)
EC_PRIVATEKEY_free(priv_key);
return (ok ? ret : 0);
}
|
DoS Mem. Corr.
| 0
|
int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out)
{
int ret = 0, ok = 0;
unsigned char *buffer = NULL;
size_t buf_len = 0, tmp_len;
EC_PRIVATEKEY *priv_key = NULL;
if (a == NULL || a->group == NULL || a->priv_key == NULL) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_PASSED_NULL_PARAMETER);
goto err;
}
if ((priv_key = EC_PRIVATEKEY_new()) == NULL) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
priv_key->version = a->version;
buf_len = (size_t)BN_num_bytes(a->priv_key);
buffer = OPENSSL_malloc(buf_len);
if (buffer == NULL) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!BN_bn2bin(a->priv_key, buffer)) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_BN_LIB);
goto err;
}
if (!M_ASN1_OCTET_STRING_set(priv_key->privateKey, buffer, buf_len)) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_ASN1_LIB);
goto err;
}
if (!(a->enc_flag & EC_PKEY_NO_PARAMETERS)) {
if ((priv_key->parameters =
ec_asn1_group2pkparameters(a->group,
priv_key->parameters)) == NULL) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB);
goto err;
}
}
if (!(a->enc_flag & EC_PKEY_NO_PUBKEY)) {
priv_key->publicKey = M_ASN1_BIT_STRING_new();
if (priv_key->publicKey == NULL) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
tmp_len = EC_POINT_point2oct(a->group, a->pub_key,
a->conv_form, NULL, 0, NULL);
if (tmp_len > buf_len) {
unsigned char *tmp_buffer = OPENSSL_realloc(buffer, tmp_len);
if (!tmp_buffer) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
buffer = tmp_buffer;
buf_len = tmp_len;
}
if (!EC_POINT_point2oct(a->group, a->pub_key,
a->conv_form, buffer, buf_len, NULL)) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB);
goto err;
}
priv_key->publicKey->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
priv_key->publicKey->flags |= ASN1_STRING_FLAG_BITS_LEFT;
if (!M_ASN1_BIT_STRING_set(priv_key->publicKey, buffer, buf_len)) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_ASN1_LIB);
goto err;
}
}
if ((ret = i2d_EC_PRIVATEKEY(priv_key, out)) == 0) {
ECerr(EC_F_I2D_ECPRIVATEKEY, ERR_R_EC_LIB);
goto err;
}
ok = 1;
err:
if (buffer)
OPENSSL_free(buffer);
if (priv_key)
EC_PRIVATEKEY_free(priv_key);
return (ok ? ret : 0);
}
|
@@ -1014,8 +1014,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
- if (a)
- *a = ret;
} else
ret = *a;
@@ -1067,10 +1065,12 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
}
}
+ if (a)
+ *a = ret;
ok = 1;
err:
if (!ok) {
- if (ret)
+ if (ret && (a == NULL || *a != ret))
EC_KEY_free(ret);
ret = NULL;
}
| null | null | null |
5,133
|
int i2o_ECPublicKey(EC_KEY *a, unsigned char **out)
{
size_t buf_len = 0;
int new_buffer = 0;
if (a == NULL) {
ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
buf_len = EC_POINT_point2oct(a->group, a->pub_key,
a->conv_form, NULL, 0, NULL);
if (out == NULL || buf_len == 0)
/* out == NULL => just return the length of the octet string */
return buf_len;
if (*out == NULL) {
if ((*out = OPENSSL_malloc(buf_len)) == NULL) {
ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_MALLOC_FAILURE);
return 0;
}
new_buffer = 1;
}
if (!EC_POINT_point2oct(a->group, a->pub_key, a->conv_form,
*out, buf_len, NULL)) {
ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_EC_LIB);
OPENSSL_free(*out);
*out = NULL;
return 0;
}
if (!new_buffer)
*out += buf_len;
return buf_len;
}
|
DoS Mem. Corr.
| 0
|
int i2o_ECPublicKey(EC_KEY *a, unsigned char **out)
{
size_t buf_len = 0;
int new_buffer = 0;
if (a == NULL) {
ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
buf_len = EC_POINT_point2oct(a->group, a->pub_key,
a->conv_form, NULL, 0, NULL);
if (out == NULL || buf_len == 0)
/* out == NULL => just return the length of the octet string */
return buf_len;
if (*out == NULL) {
if ((*out = OPENSSL_malloc(buf_len)) == NULL) {
ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_MALLOC_FAILURE);
return 0;
}
new_buffer = 1;
}
if (!EC_POINT_point2oct(a->group, a->pub_key, a->conv_form,
*out, buf_len, NULL)) {
ECerr(EC_F_I2O_ECPUBLICKEY, ERR_R_EC_LIB);
OPENSSL_free(*out);
*out = NULL;
return 0;
}
if (!new_buffer)
*out += buf_len;
return buf_len;
}
|
@@ -1014,8 +1014,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
- if (a)
- *a = ret;
} else
ret = *a;
@@ -1067,10 +1065,12 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
}
}
+ if (a)
+ *a = ret;
ok = 1;
err:
if (!ok) {
- if (ret)
+ if (ret && (a == NULL || *a != ret))
EC_KEY_free(ret);
ret = NULL;
}
| null | null | null |
5,134
|
EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len)
{
EC_KEY *ret = NULL;
if (a == NULL || (*a) == NULL || (*a)->group == NULL) {
/*
* sorry, but a EC_GROUP-structur is necessary to set the public key
*/
ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
ret = *a;
if (ret->pub_key == NULL &&
(ret->pub_key = EC_POINT_new(ret->group)) == NULL) {
ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_MALLOC_FAILURE);
return 0;
}
if (!EC_POINT_oct2point(ret->group, ret->pub_key, *in, len, NULL)) {
ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_EC_LIB);
return 0;
}
/* save the point conversion form */
ret->conv_form = (point_conversion_form_t) (*in[0] & ~0x01);
*in += len;
return ret;
}
|
DoS Mem. Corr.
| 0
|
EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len)
{
EC_KEY *ret = NULL;
if (a == NULL || (*a) == NULL || (*a)->group == NULL) {
/*
* sorry, but a EC_GROUP-structur is necessary to set the public key
*/
ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_PASSED_NULL_PARAMETER);
return 0;
}
ret = *a;
if (ret->pub_key == NULL &&
(ret->pub_key = EC_POINT_new(ret->group)) == NULL) {
ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_MALLOC_FAILURE);
return 0;
}
if (!EC_POINT_oct2point(ret->group, ret->pub_key, *in, len, NULL)) {
ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_EC_LIB);
return 0;
}
/* save the point conversion form */
ret->conv_form = (point_conversion_form_t) (*in[0] & ~0x01);
*in += len;
return ret;
}
|
@@ -1014,8 +1014,6 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);
goto err;
}
- if (a)
- *a = ret;
} else
ret = *a;
@@ -1067,10 +1065,12 @@ EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
}
}
+ if (a)
+ *a = ret;
ok = 1;
err:
if (!ok) {
- if (ret)
+ if (ret && (a == NULL || *a != ret))
EC_KEY_free(ret);
ret = NULL;
}
| null | null | null |
5,135
|
static X509_ALGOR *rsa_mgf1_decode(X509_ALGOR *alg)
{
const unsigned char *p;
int plen;
if (alg == NULL)
return NULL;
if (OBJ_obj2nid(alg->algorithm) != NID_mgf1)
return NULL;
if (alg->parameter->type != V_ASN1_SEQUENCE)
return NULL;
p = alg->parameter->value.sequence->data;
plen = alg->parameter->value.sequence->length;
return d2i_X509_ALGOR(NULL, &p, plen);
}
|
DoS
| 0
|
static X509_ALGOR *rsa_mgf1_decode(X509_ALGOR *alg)
{
const unsigned char *p;
int plen;
if (alg == NULL)
return NULL;
if (OBJ_obj2nid(alg->algorithm) != NID_mgf1)
return NULL;
if (alg->parameter->type != V_ASN1_SEQUENCE)
return NULL;
p = alg->parameter->value.sequence->data;
plen = alg->parameter->value.sequence->length;
return d2i_X509_ALGOR(NULL, &p, plen);
}
|
@@ -698,9 +698,10 @@ static int rsa_item_verify(EVP_MD_CTX *ctx, const ASN1_ITEM *it, void *asn,
RSAerr(RSA_F_RSA_ITEM_VERIFY, RSA_R_UNSUPPORTED_SIGNATURE_TYPE);
return -1;
}
- if (rsa_pss_to_ctx(ctx, NULL, sigalg, pkey))
+ if (rsa_pss_to_ctx(ctx, NULL, sigalg, pkey) > 0) {
/* Carry on */
return 2;
+ }
return -1;
}
| null | null | null |
5,136
|
void dtls1_clear(SSL *s)
{
pqueue unprocessed_rcds;
pqueue processed_rcds;
pqueue buffered_messages;
pqueue sent_messages;
pqueue buffered_app_data;
unsigned int mtu;
unsigned int link_mtu;
if (s->d1) {
unprocessed_rcds = s->d1->unprocessed_rcds.q;
processed_rcds = s->d1->processed_rcds.q;
buffered_messages = s->d1->buffered_messages;
sent_messages = s->d1->sent_messages;
buffered_app_data = s->d1->buffered_app_data.q;
mtu = s->d1->mtu;
link_mtu = s->d1->link_mtu;
dtls1_clear_queues(s);
memset(s->d1, 0, sizeof(*(s->d1)));
if (s->server) {
s->d1->cookie_len = sizeof(s->d1->cookie);
}
if (SSL_get_options(s) & SSL_OP_NO_QUERY_MTU) {
s->d1->mtu = mtu;
s->d1->link_mtu = link_mtu;
}
s->d1->unprocessed_rcds.q = unprocessed_rcds;
s->d1->processed_rcds.q = processed_rcds;
s->d1->buffered_messages = buffered_messages;
s->d1->sent_messages = sent_messages;
s->d1->buffered_app_data.q = buffered_app_data;
}
ssl3_clear(s);
if (s->options & SSL_OP_CISCO_ANYCONNECT)
s->client_version = s->version = DTLS1_BAD_VER;
else if (s->method->version == DTLS_ANY_VERSION)
s->version = DTLS1_2_VERSION;
else
s->version = s->method->version;
}
|
DoS
| 0
|
void dtls1_clear(SSL *s)
{
pqueue unprocessed_rcds;
pqueue processed_rcds;
pqueue buffered_messages;
pqueue sent_messages;
pqueue buffered_app_data;
unsigned int mtu;
unsigned int link_mtu;
if (s->d1) {
unprocessed_rcds = s->d1->unprocessed_rcds.q;
processed_rcds = s->d1->processed_rcds.q;
buffered_messages = s->d1->buffered_messages;
sent_messages = s->d1->sent_messages;
buffered_app_data = s->d1->buffered_app_data.q;
mtu = s->d1->mtu;
link_mtu = s->d1->link_mtu;
dtls1_clear_queues(s);
memset(s->d1, 0, sizeof(*(s->d1)));
if (s->server) {
s->d1->cookie_len = sizeof(s->d1->cookie);
}
if (SSL_get_options(s) & SSL_OP_NO_QUERY_MTU) {
s->d1->mtu = mtu;
s->d1->link_mtu = link_mtu;
}
s->d1->unprocessed_rcds.q = unprocessed_rcds;
s->d1->processed_rcds.q = processed_rcds;
s->d1->buffered_messages = buffered_messages;
s->d1->sent_messages = sent_messages;
s->d1->buffered_app_data.q = buffered_app_data;
}
ssl3_clear(s);
if (s->options & SSL_OP_CISCO_ANYCONNECT)
s->client_version = s->version = DTLS1_BAD_VER;
else if (s->method->version == DTLS_ANY_VERSION)
s->version = DTLS1_2_VERSION;
else
s->version = s->method->version;
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,137
|
static void dtls1_clear_queues(SSL *s)
{
pitem *item = NULL;
hm_fragment *frag = NULL;
DTLS1_RECORD_DATA *rdata;
while ((item = pqueue_pop(s->d1->unprocessed_rcds.q)) != NULL) {
rdata = (DTLS1_RECORD_DATA *)item->data;
if (rdata->rbuf.buf) {
OPENSSL_free(rdata->rbuf.buf);
}
OPENSSL_free(item->data);
pitem_free(item);
}
while ((item = pqueue_pop(s->d1->processed_rcds.q)) != NULL) {
rdata = (DTLS1_RECORD_DATA *)item->data;
if (rdata->rbuf.buf) {
OPENSSL_free(rdata->rbuf.buf);
}
OPENSSL_free(item->data);
pitem_free(item);
}
while ((item = pqueue_pop(s->d1->buffered_messages)) != NULL) {
frag = (hm_fragment *)item->data;
dtls1_hm_fragment_free(frag);
pitem_free(item);
}
while ((item = pqueue_pop(s->d1->sent_messages)) != NULL) {
frag = (hm_fragment *)item->data;
dtls1_hm_fragment_free(frag);
pitem_free(item);
}
while ((item = pqueue_pop(s->d1->buffered_app_data.q)) != NULL) {
rdata = (DTLS1_RECORD_DATA *)item->data;
if (rdata->rbuf.buf) {
OPENSSL_free(rdata->rbuf.buf);
}
OPENSSL_free(item->data);
pitem_free(item);
}
}
|
DoS
| 0
|
static void dtls1_clear_queues(SSL *s)
{
pitem *item = NULL;
hm_fragment *frag = NULL;
DTLS1_RECORD_DATA *rdata;
while ((item = pqueue_pop(s->d1->unprocessed_rcds.q)) != NULL) {
rdata = (DTLS1_RECORD_DATA *)item->data;
if (rdata->rbuf.buf) {
OPENSSL_free(rdata->rbuf.buf);
}
OPENSSL_free(item->data);
pitem_free(item);
}
while ((item = pqueue_pop(s->d1->processed_rcds.q)) != NULL) {
rdata = (DTLS1_RECORD_DATA *)item->data;
if (rdata->rbuf.buf) {
OPENSSL_free(rdata->rbuf.buf);
}
OPENSSL_free(item->data);
pitem_free(item);
}
while ((item = pqueue_pop(s->d1->buffered_messages)) != NULL) {
frag = (hm_fragment *)item->data;
dtls1_hm_fragment_free(frag);
pitem_free(item);
}
while ((item = pqueue_pop(s->d1->sent_messages)) != NULL) {
frag = (hm_fragment *)item->data;
dtls1_hm_fragment_free(frag);
pitem_free(item);
}
while ((item = pqueue_pop(s->d1->buffered_app_data.q)) != NULL) {
rdata = (DTLS1_RECORD_DATA *)item->data;
if (rdata->rbuf.buf) {
OPENSSL_free(rdata->rbuf.buf);
}
OPENSSL_free(item->data);
pitem_free(item);
}
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,138
|
long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg)
{
int ret = 0;
switch (cmd) {
case DTLS_CTRL_GET_TIMEOUT:
if (dtls1_get_timeout(s, (struct timeval *)parg) != NULL) {
ret = 1;
}
break;
case DTLS_CTRL_HANDLE_TIMEOUT:
ret = dtls1_handle_timeout(s);
break;
case DTLS_CTRL_LISTEN:
ret = dtls1_listen(s, parg);
break;
case SSL_CTRL_CHECK_PROTO_VERSION:
/*
* For library-internal use; checks that the current protocol is the
* highest enabled version (according to s->ctx->method, as version
* negotiation may have changed s->method).
*/
if (s->version == s->ctx->method->version)
return 1;
/*
* Apparently we're using a version-flexible SSL_METHOD (not at its
* highest protocol version).
*/
if (s->ctx->method->version == DTLS_method()->version) {
#if DTLS_MAX_VERSION != DTLS1_2_VERSION
# error Code needs update for DTLS_method() support beyond DTLS1_2_VERSION.
#endif
if (!(s->options & SSL_OP_NO_DTLSv1_2))
return s->version == DTLS1_2_VERSION;
if (!(s->options & SSL_OP_NO_DTLSv1))
return s->version == DTLS1_VERSION;
}
return 0; /* Unexpected state; fail closed. */
case DTLS_CTRL_SET_LINK_MTU:
if (larg < (long)dtls1_link_min_mtu())
return 0;
s->d1->link_mtu = larg;
return 1;
case DTLS_CTRL_GET_LINK_MIN_MTU:
return (long)dtls1_link_min_mtu();
case SSL_CTRL_SET_MTU:
/*
* We may not have a BIO set yet so can't call dtls1_min_mtu()
* We'll have to make do with dtls1_link_min_mtu() and max overhead
*/
if (larg < (long)dtls1_link_min_mtu() - DTLS1_MAX_MTU_OVERHEAD)
return 0;
s->d1->mtu = larg;
return larg;
default:
ret = ssl3_ctrl(s, cmd, larg, parg);
break;
}
return (ret);
}
|
DoS
| 0
|
long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg)
{
int ret = 0;
switch (cmd) {
case DTLS_CTRL_GET_TIMEOUT:
if (dtls1_get_timeout(s, (struct timeval *)parg) != NULL) {
ret = 1;
}
break;
case DTLS_CTRL_HANDLE_TIMEOUT:
ret = dtls1_handle_timeout(s);
break;
case DTLS_CTRL_LISTEN:
ret = dtls1_listen(s, parg);
break;
case SSL_CTRL_CHECK_PROTO_VERSION:
/*
* For library-internal use; checks that the current protocol is the
* highest enabled version (according to s->ctx->method, as version
* negotiation may have changed s->method).
*/
if (s->version == s->ctx->method->version)
return 1;
/*
* Apparently we're using a version-flexible SSL_METHOD (not at its
* highest protocol version).
*/
if (s->ctx->method->version == DTLS_method()->version) {
#if DTLS_MAX_VERSION != DTLS1_2_VERSION
# error Code needs update for DTLS_method() support beyond DTLS1_2_VERSION.
#endif
if (!(s->options & SSL_OP_NO_DTLSv1_2))
return s->version == DTLS1_2_VERSION;
if (!(s->options & SSL_OP_NO_DTLSv1))
return s->version == DTLS1_VERSION;
}
return 0; /* Unexpected state; fail closed. */
case DTLS_CTRL_SET_LINK_MTU:
if (larg < (long)dtls1_link_min_mtu())
return 0;
s->d1->link_mtu = larg;
return 1;
case DTLS_CTRL_GET_LINK_MIN_MTU:
return (long)dtls1_link_min_mtu();
case SSL_CTRL_SET_MTU:
/*
* We may not have a BIO set yet so can't call dtls1_min_mtu()
* We'll have to make do with dtls1_link_min_mtu() and max overhead
*/
if (larg < (long)dtls1_link_min_mtu() - DTLS1_MAX_MTU_OVERHEAD)
return 0;
s->d1->mtu = larg;
return larg;
default:
ret = ssl3_ctrl(s, cmd, larg, parg);
break;
}
return (ret);
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,139
|
long dtls1_default_timeout(void)
{
/*
* 2 hours, the 24 hours mentioned in the DTLSv1 spec is way too long for
* http, the cache would over fill
*/
return (60 * 60 * 2);
}
|
DoS
| 0
|
long dtls1_default_timeout(void)
{
/*
* 2 hours, the 24 hours mentioned in the DTLSv1 spec is way too long for
* http, the cache would over fill
*/
return (60 * 60 * 2);
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,140
|
void dtls1_double_timeout(SSL *s)
{
s->d1->timeout_duration *= 2;
if (s->d1->timeout_duration > 60)
s->d1->timeout_duration = 60;
dtls1_start_timer(s);
}
|
DoS
| 0
|
void dtls1_double_timeout(SSL *s)
{
s->d1->timeout_duration *= 2;
if (s->d1->timeout_duration > 60)
s->d1->timeout_duration = 60;
dtls1_start_timer(s);
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,141
|
void dtls1_free(SSL *s)
{
ssl3_free(s);
dtls1_clear_queues(s);
pqueue_free(s->d1->unprocessed_rcds.q);
pqueue_free(s->d1->processed_rcds.q);
pqueue_free(s->d1->buffered_messages);
pqueue_free(s->d1->sent_messages);
pqueue_free(s->d1->buffered_app_data.q);
OPENSSL_free(s->d1);
s->d1 = NULL;
}
|
DoS
| 0
|
void dtls1_free(SSL *s)
{
ssl3_free(s);
dtls1_clear_queues(s);
pqueue_free(s->d1->unprocessed_rcds.q);
pqueue_free(s->d1->processed_rcds.q);
pqueue_free(s->d1->buffered_messages);
pqueue_free(s->d1->sent_messages);
pqueue_free(s->d1->buffered_app_data.q);
OPENSSL_free(s->d1);
s->d1 = NULL;
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,142
|
const SSL_CIPHER *dtls1_get_cipher(unsigned int u)
{
const SSL_CIPHER *ciph = ssl3_get_cipher(u);
if (ciph != NULL) {
if (ciph->algorithm_enc == SSL_RC4)
return NULL;
}
return ciph;
}
|
DoS
| 0
|
const SSL_CIPHER *dtls1_get_cipher(unsigned int u)
{
const SSL_CIPHER *ciph = ssl3_get_cipher(u);
if (ciph != NULL) {
if (ciph->algorithm_enc == SSL_RC4)
return NULL;
}
return ciph;
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,143
|
struct timeval *dtls1_get_timeout(SSL *s, struct timeval *timeleft)
{
struct timeval timenow;
/* If no timeout is set, just return NULL */
if (s->d1->next_timeout.tv_sec == 0 && s->d1->next_timeout.tv_usec == 0) {
return NULL;
}
/* Get current time */
get_current_time(&timenow);
/* If timer already expired, set remaining time to 0 */
if (s->d1->next_timeout.tv_sec < timenow.tv_sec ||
(s->d1->next_timeout.tv_sec == timenow.tv_sec &&
s->d1->next_timeout.tv_usec <= timenow.tv_usec)) {
memset(timeleft, 0, sizeof(struct timeval));
return timeleft;
}
/* Calculate time left until timer expires */
memcpy(timeleft, &(s->d1->next_timeout), sizeof(struct timeval));
timeleft->tv_sec -= timenow.tv_sec;
timeleft->tv_usec -= timenow.tv_usec;
if (timeleft->tv_usec < 0) {
timeleft->tv_sec--;
timeleft->tv_usec += 1000000;
}
/*
* If remaining time is less than 15 ms, set it to 0 to prevent issues
* because of small devergences with socket timeouts.
*/
if (timeleft->tv_sec == 0 && timeleft->tv_usec < 15000) {
memset(timeleft, 0, sizeof(struct timeval));
}
return timeleft;
}
|
DoS
| 0
|
struct timeval *dtls1_get_timeout(SSL *s, struct timeval *timeleft)
{
struct timeval timenow;
/* If no timeout is set, just return NULL */
if (s->d1->next_timeout.tv_sec == 0 && s->d1->next_timeout.tv_usec == 0) {
return NULL;
}
/* Get current time */
get_current_time(&timenow);
/* If timer already expired, set remaining time to 0 */
if (s->d1->next_timeout.tv_sec < timenow.tv_sec ||
(s->d1->next_timeout.tv_sec == timenow.tv_sec &&
s->d1->next_timeout.tv_usec <= timenow.tv_usec)) {
memset(timeleft, 0, sizeof(struct timeval));
return timeleft;
}
/* Calculate time left until timer expires */
memcpy(timeleft, &(s->d1->next_timeout), sizeof(struct timeval));
timeleft->tv_sec -= timenow.tv_sec;
timeleft->tv_usec -= timenow.tv_usec;
if (timeleft->tv_usec < 0) {
timeleft->tv_sec--;
timeleft->tv_usec += 1000000;
}
/*
* If remaining time is less than 15 ms, set it to 0 to prevent issues
* because of small devergences with socket timeouts.
*/
if (timeleft->tv_sec == 0 && timeleft->tv_usec < 15000) {
memset(timeleft, 0, sizeof(struct timeval));
}
return timeleft;
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,144
|
int dtls1_handle_timeout(SSL *s)
{
/* if no timer is expired, don't do anything */
if (!dtls1_is_timer_expired(s)) {
return 0;
}
dtls1_double_timeout(s);
if (dtls1_check_timeout_num(s) < 0)
return -1;
s->d1->timeout.read_timeouts++;
if (s->d1->timeout.read_timeouts > DTLS1_TMO_READ_COUNT) {
s->d1->timeout.read_timeouts = 1;
}
#ifndef OPENSSL_NO_HEARTBEATS
if (s->tlsext_hb_pending) {
s->tlsext_hb_pending = 0;
return dtls1_heartbeat(s);
}
#endif
dtls1_start_timer(s);
return dtls1_retransmit_buffered_messages(s);
}
|
DoS
| 0
|
int dtls1_handle_timeout(SSL *s)
{
/* if no timer is expired, don't do anything */
if (!dtls1_is_timer_expired(s)) {
return 0;
}
dtls1_double_timeout(s);
if (dtls1_check_timeout_num(s) < 0)
return -1;
s->d1->timeout.read_timeouts++;
if (s->d1->timeout.read_timeouts > DTLS1_TMO_READ_COUNT) {
s->d1->timeout.read_timeouts = 1;
}
#ifndef OPENSSL_NO_HEARTBEATS
if (s->tlsext_hb_pending) {
s->tlsext_hb_pending = 0;
return dtls1_heartbeat(s);
}
#endif
dtls1_start_timer(s);
return dtls1_retransmit_buffered_messages(s);
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,145
|
static int dtls1_handshake_write(SSL *s)
{
return dtls1_do_write(s, SSL3_RT_HANDSHAKE);
}
|
DoS
| 0
|
static int dtls1_handshake_write(SSL *s)
{
return dtls1_do_write(s, SSL3_RT_HANDSHAKE);
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,146
|
int dtls1_is_timer_expired(SSL *s)
{
struct timeval timeleft;
/* Get time left until timeout, return false if no timer running */
if (dtls1_get_timeout(s, &timeleft) == NULL) {
return 0;
}
/* Return false if timer is not expired yet */
if (timeleft.tv_sec > 0 || timeleft.tv_usec > 0) {
return 0;
}
/* Timer expired, so return true */
return 1;
}
|
DoS
| 0
|
int dtls1_is_timer_expired(SSL *s)
{
struct timeval timeleft;
/* Get time left until timeout, return false if no timer running */
if (dtls1_get_timeout(s, &timeleft) == NULL) {
return 0;
}
/* Return false if timer is not expired yet */
if (timeleft.tv_sec > 0 || timeleft.tv_usec > 0) {
return 0;
}
/* Timer expired, so return true */
return 1;
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,147
|
int dtls1_new(SSL *s)
{
DTLS1_STATE *d1;
if (!ssl3_new(s))
return (0);
if ((d1 = OPENSSL_malloc(sizeof *d1)) == NULL)
return (0);
memset(d1, 0, sizeof *d1);
/* d1->handshake_epoch=0; */
d1->unprocessed_rcds.q = pqueue_new();
d1->processed_rcds.q = pqueue_new();
d1->buffered_messages = pqueue_new();
d1->sent_messages = pqueue_new();
d1->buffered_app_data.q = pqueue_new();
if (s->server) {
d1->cookie_len = sizeof(s->d1->cookie);
}
d1->link_mtu = 0;
d1->mtu = 0;
if (!d1->unprocessed_rcds.q || !d1->processed_rcds.q
|| !d1->buffered_messages || !d1->sent_messages
|| !d1->buffered_app_data.q) {
if (d1->unprocessed_rcds.q)
pqueue_free(d1->unprocessed_rcds.q);
if (d1->processed_rcds.q)
pqueue_free(d1->processed_rcds.q);
if (d1->buffered_messages)
pqueue_free(d1->buffered_messages);
if (d1->sent_messages)
pqueue_free(d1->sent_messages);
if (d1->buffered_app_data.q)
pqueue_free(d1->buffered_app_data.q);
OPENSSL_free(d1);
return (0);
}
s->d1 = d1;
s->method->ssl_clear(s);
return (1);
}
|
DoS
| 0
|
int dtls1_new(SSL *s)
{
DTLS1_STATE *d1;
if (!ssl3_new(s))
return (0);
if ((d1 = OPENSSL_malloc(sizeof *d1)) == NULL)
return (0);
memset(d1, 0, sizeof *d1);
/* d1->handshake_epoch=0; */
d1->unprocessed_rcds.q = pqueue_new();
d1->processed_rcds.q = pqueue_new();
d1->buffered_messages = pqueue_new();
d1->sent_messages = pqueue_new();
d1->buffered_app_data.q = pqueue_new();
if (s->server) {
d1->cookie_len = sizeof(s->d1->cookie);
}
d1->link_mtu = 0;
d1->mtu = 0;
if (!d1->unprocessed_rcds.q || !d1->processed_rcds.q
|| !d1->buffered_messages || !d1->sent_messages
|| !d1->buffered_app_data.q) {
if (d1->unprocessed_rcds.q)
pqueue_free(d1->unprocessed_rcds.q);
if (d1->processed_rcds.q)
pqueue_free(d1->processed_rcds.q);
if (d1->buffered_messages)
pqueue_free(d1->buffered_messages);
if (d1->sent_messages)
pqueue_free(d1->sent_messages);
if (d1->buffered_app_data.q)
pqueue_free(d1->buffered_app_data.q);
OPENSSL_free(d1);
return (0);
}
s->d1 = d1;
s->method->ssl_clear(s);
return (1);
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,148
|
static void dtls1_set_handshake_header(SSL *s, int htype, unsigned long len)
{
unsigned char *p = (unsigned char *)s->init_buf->data;
dtls1_set_message_header(s, p, htype, len, 0, len);
s->init_num = (int)len + DTLS1_HM_HEADER_LENGTH;
s->init_off = 0;
/* Buffer the message to handle re-xmits */
dtls1_buffer_message(s, 0);
}
|
DoS
| 0
|
static void dtls1_set_handshake_header(SSL *s, int htype, unsigned long len)
{
unsigned char *p = (unsigned char *)s->init_buf->data;
dtls1_set_message_header(s, p, htype, len, 0, len);
s->init_num = (int)len + DTLS1_HM_HEADER_LENGTH;
s->init_off = 0;
/* Buffer the message to handle re-xmits */
dtls1_buffer_message(s, 0);
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,149
|
void dtls1_start_timer(SSL *s)
{
#ifndef OPENSSL_NO_SCTP
/* Disable timer for SCTP */
if (BIO_dgram_is_sctp(SSL_get_wbio(s))) {
memset(&(s->d1->next_timeout), 0, sizeof(struct timeval));
return;
}
#endif
/* If timer is not set, initialize duration with 1 second */
if (s->d1->next_timeout.tv_sec == 0 && s->d1->next_timeout.tv_usec == 0) {
s->d1->timeout_duration = 1;
}
/* Set timeout to current time */
get_current_time(&(s->d1->next_timeout));
/* Add duration to current time */
s->d1->next_timeout.tv_sec += s->d1->timeout_duration;
BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0,
&(s->d1->next_timeout));
}
|
DoS
| 0
|
void dtls1_start_timer(SSL *s)
{
#ifndef OPENSSL_NO_SCTP
/* Disable timer for SCTP */
if (BIO_dgram_is_sctp(SSL_get_wbio(s))) {
memset(&(s->d1->next_timeout), 0, sizeof(struct timeval));
return;
}
#endif
/* If timer is not set, initialize duration with 1 second */
if (s->d1->next_timeout.tv_sec == 0 && s->d1->next_timeout.tv_usec == 0) {
s->d1->timeout_duration = 1;
}
/* Set timeout to current time */
get_current_time(&(s->d1->next_timeout));
/* Add duration to current time */
s->d1->next_timeout.tv_sec += s->d1->timeout_duration;
BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0,
&(s->d1->next_timeout));
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,150
|
void dtls1_stop_timer(SSL *s)
{
/* Reset everything */
memset(&(s->d1->timeout), 0, sizeof(struct dtls1_timeout_st));
memset(&(s->d1->next_timeout), 0, sizeof(struct timeval));
s->d1->timeout_duration = 1;
BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0,
&(s->d1->next_timeout));
/* Clear retransmission buffer */
dtls1_clear_record_buffer(s);
}
|
DoS
| 0
|
void dtls1_stop_timer(SSL *s)
{
/* Reset everything */
memset(&(s->d1->timeout), 0, sizeof(struct dtls1_timeout_st));
memset(&(s->d1->next_timeout), 0, sizeof(struct timeval));
s->d1->timeout_duration = 1;
BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0,
&(s->d1->next_timeout));
/* Clear retransmission buffer */
dtls1_clear_record_buffer(s);
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,151
|
static void get_current_time(struct timeval *t)
{
#if defined(_WIN32)
SYSTEMTIME st;
union {
unsigned __int64 ul;
FILETIME ft;
} now;
GetSystemTime(&st);
SystemTimeToFileTime(&st, &now.ft);
# ifdef __MINGW32__
now.ul -= 116444736000000000ULL;
# else
now.ul -= 116444736000000000UI64; /* re-bias to 1/1/1970 */
# endif
t->tv_sec = (long)(now.ul / 10000000);
t->tv_usec = ((int)(now.ul % 10000000)) / 10;
#elif defined(OPENSSL_SYS_VMS)
struct timeb tb;
ftime(&tb);
t->tv_sec = (long)tb.time;
t->tv_usec = (long)tb.millitm * 1000;
#else
gettimeofday(t, NULL);
#endif
}
|
DoS
| 0
|
static void get_current_time(struct timeval *t)
{
#if defined(_WIN32)
SYSTEMTIME st;
union {
unsigned __int64 ul;
FILETIME ft;
} now;
GetSystemTime(&st);
SystemTimeToFileTime(&st, &now.ft);
# ifdef __MINGW32__
now.ul -= 116444736000000000ULL;
# else
now.ul -= 116444736000000000UI64; /* re-bias to 1/1/1970 */
# endif
t->tv_sec = (long)(now.ul / 10000000);
t->tv_usec = ((int)(now.ul % 10000000)) / 10;
#elif defined(OPENSSL_SYS_VMS)
struct timeb tb;
ftime(&tb);
t->tv_sec = (long)tb.time;
t->tv_usec = (long)tb.millitm * 1000;
#else
gettimeofday(t, NULL);
#endif
}
|
@@ -543,6 +543,9 @@ int dtls1_listen(SSL *s, struct sockaddr *client)
{
int ret;
+ /* Ensure there is no state left over from a previous invocation */
+ SSL_clear(s);
+
SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
s->d1->listen = 1;
| null | null | null |
5,152
|
_bdf_add_comment( bdf_font_t* font,
char* comment,
unsigned long len )
{
char* cp;
FT_Memory memory = font->memory;
FT_Error error = BDF_Err_Ok;
if ( FT_RENEW_ARRAY( font->comments,
font->comments_len,
font->comments_len + len + 1 ) )
goto Exit;
cp = font->comments + font->comments_len;
FT_MEM_COPY( cp, comment, len );
cp[len] = '\n';
font->comments_len += len + 1;
Exit:
return error;
}
|
DoS Overflow
| 0
|
_bdf_add_comment( bdf_font_t* font,
char* comment,
unsigned long len )
{
char* cp;
FT_Memory memory = font->memory;
FT_Error error = BDF_Err_Ok;
if ( FT_RENEW_ARRAY( font->comments,
font->comments_len,
font->comments_len + len + 1 ) )
goto Exit;
cp = font->comments + font->comments_len;
FT_MEM_COPY( cp, comment, len );
cp[len] = '\n';
font->comments_len += len + 1;
Exit:
return error;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,153
|
_bdf_add_property( bdf_font_t* font,
char* name,
char* value,
unsigned long lineno )
{
size_t propid;
hashnode hn;
bdf_property_t *prop, *fp;
FT_Memory memory = font->memory;
FT_Error error = BDF_Err_Ok;
/* First, check whether the property already exists in the font. */
if ( ( hn = hash_lookup( name, (hashtable *)font->internal ) ) != 0 )
{
/* The property already exists in the font, so simply replace */
/* the value of the property with the current value. */
fp = font->props + hn->data;
switch ( fp->format )
{
case BDF_ATOM:
/* Delete the current atom if it exists. */
FT_FREE( fp->value.atom );
if ( value && value[0] != 0 )
{
if ( FT_STRDUP( fp->value.atom, value ) )
goto Exit;
}
break;
case BDF_INTEGER:
fp->value.l = _bdf_atol( value, 0, 10 );
break;
case BDF_CARDINAL:
fp->value.ul = _bdf_atoul( value, 0, 10 );
break;
default:
;
}
goto Exit;
}
/* See whether this property type exists yet or not. */
/* If not, create it. */
hn = hash_lookup( name, &(font->proptbl) );
if ( hn == 0 )
{
error = bdf_create_property( name, BDF_ATOM, font );
if ( error )
goto Exit;
hn = hash_lookup( name, &(font->proptbl) );
}
/* Allocate another property if this is overflow. */
if ( font->props_used == font->props_size )
{
if ( font->props_size == 0 )
{
if ( FT_NEW_ARRAY( font->props, 1 ) )
goto Exit;
}
else
{
if ( FT_RENEW_ARRAY( font->props,
font->props_size,
font->props_size + 1 ) )
goto Exit;
}
fp = font->props + font->props_size;
FT_MEM_ZERO( fp, sizeof ( bdf_property_t ) );
font->props_size++;
}
propid = hn->data;
if ( propid >= _num_bdf_properties )
prop = font->user_props + ( propid - _num_bdf_properties );
else
prop = (bdf_property_t*)_bdf_properties + propid;
fp = font->props + font->props_used;
fp->name = prop->name;
fp->format = prop->format;
fp->builtin = prop->builtin;
switch ( prop->format )
{
case BDF_ATOM:
fp->value.atom = 0;
if ( value != 0 && value[0] )
{
if ( FT_STRDUP( fp->value.atom, value ) )
goto Exit;
}
break;
case BDF_INTEGER:
fp->value.l = _bdf_atol( value, 0, 10 );
break;
case BDF_CARDINAL:
fp->value.ul = _bdf_atoul( value, 0, 10 );
break;
}
/* If the property happens to be a comment, then it doesn't need */
/* to be added to the internal hash table. */
if ( ft_memcmp( name, "COMMENT", 7 ) != 0 )
{
/* Add the property to the font property table. */
error = hash_insert( fp->name,
font->props_used,
(hashtable *)font->internal,
memory );
if ( error )
goto Exit;
}
font->props_used++;
/* Some special cases need to be handled here. The DEFAULT_CHAR */
/* property needs to be located if it exists in the property list, the */
/* FONT_ASCENT and FONT_DESCENT need to be assigned if they are */
/* present, and the SPACING property should override the default */
/* spacing. */
if ( ft_memcmp( name, "DEFAULT_CHAR", 12 ) == 0 )
font->default_char = fp->value.l;
else if ( ft_memcmp( name, "FONT_ASCENT", 11 ) == 0 )
font->font_ascent = fp->value.l;
else if ( ft_memcmp( name, "FONT_DESCENT", 12 ) == 0 )
font->font_descent = fp->value.l;
else if ( ft_memcmp( name, "SPACING", 7 ) == 0 )
{
if ( !fp->value.atom )
{
FT_ERROR(( "_bdf_add_property: " ERRMSG8, lineno, "SPACING" ));
error = BDF_Err_Invalid_File_Format;
goto Exit;
}
if ( fp->value.atom[0] == 'p' || fp->value.atom[0] == 'P' )
font->spacing = BDF_PROPORTIONAL;
else if ( fp->value.atom[0] == 'm' || fp->value.atom[0] == 'M' )
font->spacing = BDF_MONOWIDTH;
else if ( fp->value.atom[0] == 'c' || fp->value.atom[0] == 'C' )
font->spacing = BDF_CHARCELL;
}
Exit:
return error;
}
|
DoS Overflow
| 0
|
_bdf_add_property( bdf_font_t* font,
char* name,
char* value,
unsigned long lineno )
{
size_t propid;
hashnode hn;
bdf_property_t *prop, *fp;
FT_Memory memory = font->memory;
FT_Error error = BDF_Err_Ok;
/* First, check whether the property already exists in the font. */
if ( ( hn = hash_lookup( name, (hashtable *)font->internal ) ) != 0 )
{
/* The property already exists in the font, so simply replace */
/* the value of the property with the current value. */
fp = font->props + hn->data;
switch ( fp->format )
{
case BDF_ATOM:
/* Delete the current atom if it exists. */
FT_FREE( fp->value.atom );
if ( value && value[0] != 0 )
{
if ( FT_STRDUP( fp->value.atom, value ) )
goto Exit;
}
break;
case BDF_INTEGER:
fp->value.l = _bdf_atol( value, 0, 10 );
break;
case BDF_CARDINAL:
fp->value.ul = _bdf_atoul( value, 0, 10 );
break;
default:
;
}
goto Exit;
}
/* See whether this property type exists yet or not. */
/* If not, create it. */
hn = hash_lookup( name, &(font->proptbl) );
if ( hn == 0 )
{
error = bdf_create_property( name, BDF_ATOM, font );
if ( error )
goto Exit;
hn = hash_lookup( name, &(font->proptbl) );
}
/* Allocate another property if this is overflow. */
if ( font->props_used == font->props_size )
{
if ( font->props_size == 0 )
{
if ( FT_NEW_ARRAY( font->props, 1 ) )
goto Exit;
}
else
{
if ( FT_RENEW_ARRAY( font->props,
font->props_size,
font->props_size + 1 ) )
goto Exit;
}
fp = font->props + font->props_size;
FT_MEM_ZERO( fp, sizeof ( bdf_property_t ) );
font->props_size++;
}
propid = hn->data;
if ( propid >= _num_bdf_properties )
prop = font->user_props + ( propid - _num_bdf_properties );
else
prop = (bdf_property_t*)_bdf_properties + propid;
fp = font->props + font->props_used;
fp->name = prop->name;
fp->format = prop->format;
fp->builtin = prop->builtin;
switch ( prop->format )
{
case BDF_ATOM:
fp->value.atom = 0;
if ( value != 0 && value[0] )
{
if ( FT_STRDUP( fp->value.atom, value ) )
goto Exit;
}
break;
case BDF_INTEGER:
fp->value.l = _bdf_atol( value, 0, 10 );
break;
case BDF_CARDINAL:
fp->value.ul = _bdf_atoul( value, 0, 10 );
break;
}
/* If the property happens to be a comment, then it doesn't need */
/* to be added to the internal hash table. */
if ( ft_memcmp( name, "COMMENT", 7 ) != 0 )
{
/* Add the property to the font property table. */
error = hash_insert( fp->name,
font->props_used,
(hashtable *)font->internal,
memory );
if ( error )
goto Exit;
}
font->props_used++;
/* Some special cases need to be handled here. The DEFAULT_CHAR */
/* property needs to be located if it exists in the property list, the */
/* FONT_ASCENT and FONT_DESCENT need to be assigned if they are */
/* present, and the SPACING property should override the default */
/* spacing. */
if ( ft_memcmp( name, "DEFAULT_CHAR", 12 ) == 0 )
font->default_char = fp->value.l;
else if ( ft_memcmp( name, "FONT_ASCENT", 11 ) == 0 )
font->font_ascent = fp->value.l;
else if ( ft_memcmp( name, "FONT_DESCENT", 12 ) == 0 )
font->font_descent = fp->value.l;
else if ( ft_memcmp( name, "SPACING", 7 ) == 0 )
{
if ( !fp->value.atom )
{
FT_ERROR(( "_bdf_add_property: " ERRMSG8, lineno, "SPACING" ));
error = BDF_Err_Invalid_File_Format;
goto Exit;
}
if ( fp->value.atom[0] == 'p' || fp->value.atom[0] == 'P' )
font->spacing = BDF_PROPORTIONAL;
else if ( fp->value.atom[0] == 'm' || fp->value.atom[0] == 'M' )
font->spacing = BDF_MONOWIDTH;
else if ( fp->value.atom[0] == 'c' || fp->value.atom[0] == 'C' )
font->spacing = BDF_CHARCELL;
}
Exit:
return error;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,154
|
_bdf_atol( char* s,
char** end,
int base )
{
long v, neg;
const unsigned char* dmap;
if ( s == 0 || *s == 0 )
return 0;
/* Make sure the radix is something recognizable. Default to 10. */
switch ( base )
{
case 8:
dmap = odigits;
break;
case 16:
dmap = hdigits;
break;
default:
base = 10;
dmap = ddigits;
break;
}
/* Check for a minus sign. */
neg = 0;
if ( *s == '-' )
{
s++;
neg = 1;
}
/* Check for the special hex prefix. */
if ( *s == '0' &&
( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) )
{
base = 16;
dmap = hdigits;
s += 2;
}
for ( v = 0; sbitset( dmap, *s ); s++ )
v = v * base + a2i[(int)*s];
if ( end != 0 )
*end = s;
return ( !neg ) ? v : -v;
}
|
DoS Overflow
| 0
|
_bdf_atol( char* s,
char** end,
int base )
{
long v, neg;
const unsigned char* dmap;
if ( s == 0 || *s == 0 )
return 0;
/* Make sure the radix is something recognizable. Default to 10. */
switch ( base )
{
case 8:
dmap = odigits;
break;
case 16:
dmap = hdigits;
break;
default:
base = 10;
dmap = ddigits;
break;
}
/* Check for a minus sign. */
neg = 0;
if ( *s == '-' )
{
s++;
neg = 1;
}
/* Check for the special hex prefix. */
if ( *s == '0' &&
( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) )
{
base = 16;
dmap = hdigits;
s += 2;
}
for ( v = 0; sbitset( dmap, *s ); s++ )
v = v * base + a2i[(int)*s];
if ( end != 0 )
*end = s;
return ( !neg ) ? v : -v;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,155
|
_bdf_atos( char* s,
char** end,
int base )
{
short v, neg;
const unsigned char* dmap;
if ( s == 0 || *s == 0 )
return 0;
/* Make sure the radix is something recognizable. Default to 10. */
switch ( base )
{
case 8:
dmap = odigits;
break;
case 16:
dmap = hdigits;
break;
default:
base = 10;
dmap = ddigits;
break;
}
/* Check for a minus. */
neg = 0;
if ( *s == '-' )
{
s++;
neg = 1;
}
/* Check for the special hex prefix. */
if ( *s == '0' &&
( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) )
{
base = 16;
dmap = hdigits;
s += 2;
}
for ( v = 0; sbitset( dmap, *s ); s++ )
v = (short)( v * base + a2i[(int)*s] );
if ( end != 0 )
*end = s;
return (short)( ( !neg ) ? v : -v );
}
|
DoS Overflow
| 0
|
_bdf_atos( char* s,
char** end,
int base )
{
short v, neg;
const unsigned char* dmap;
if ( s == 0 || *s == 0 )
return 0;
/* Make sure the radix is something recognizable. Default to 10. */
switch ( base )
{
case 8:
dmap = odigits;
break;
case 16:
dmap = hdigits;
break;
default:
base = 10;
dmap = ddigits;
break;
}
/* Check for a minus. */
neg = 0;
if ( *s == '-' )
{
s++;
neg = 1;
}
/* Check for the special hex prefix. */
if ( *s == '0' &&
( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) )
{
base = 16;
dmap = hdigits;
s += 2;
}
for ( v = 0; sbitset( dmap, *s ); s++ )
v = (short)( v * base + a2i[(int)*s] );
if ( end != 0 )
*end = s;
return (short)( ( !neg ) ? v : -v );
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,156
|
_bdf_atoul( char* s,
char** end,
int base )
{
unsigned long v;
const unsigned char* dmap;
if ( s == 0 || *s == 0 )
return 0;
/* Make sure the radix is something recognizable. Default to 10. */
switch ( base )
{
case 8:
dmap = odigits;
break;
case 16:
dmap = hdigits;
break;
default:
base = 10;
dmap = ddigits;
break;
}
/* Check for the special hex prefix. */
if ( *s == '0' &&
( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) )
{
base = 16;
dmap = hdigits;
s += 2;
}
for ( v = 0; sbitset( dmap, *s ); s++ )
v = v * base + a2i[(int)*s];
if ( end != 0 )
*end = s;
return v;
}
|
DoS Overflow
| 0
|
_bdf_atoul( char* s,
char** end,
int base )
{
unsigned long v;
const unsigned char* dmap;
if ( s == 0 || *s == 0 )
return 0;
/* Make sure the radix is something recognizable. Default to 10. */
switch ( base )
{
case 8:
dmap = odigits;
break;
case 16:
dmap = hdigits;
break;
default:
base = 10;
dmap = ddigits;
break;
}
/* Check for the special hex prefix. */
if ( *s == '0' &&
( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) )
{
base = 16;
dmap = hdigits;
s += 2;
}
for ( v = 0; sbitset( dmap, *s ); s++ )
v = v * base + a2i[(int)*s];
if ( end != 0 )
*end = s;
return v;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,157
|
_bdf_is_atom( char* line,
unsigned long linelen,
char** name,
char** value,
bdf_font_t* font )
{
int hold;
char *sp, *ep;
bdf_property_t* p;
*name = sp = ep = line;
while ( *ep && *ep != ' ' && *ep != '\t' )
ep++;
hold = -1;
if ( *ep )
{
hold = *ep;
*ep = 0;
}
p = bdf_get_property( sp, font );
/* Restore the character that was saved before any return can happen. */
if ( hold != -1 )
*ep = (char)hold;
/* If the property exists and is not an atom, just return here. */
if ( p && p->format != BDF_ATOM )
return 0;
/* The property is an atom. Trim all leading and trailing whitespace */
/* and double quotes for the atom value. */
sp = ep;
ep = line + linelen;
/* Trim the leading whitespace if it exists. */
if ( *sp )
*sp++ = 0;
while ( *sp &&
( *sp == ' ' || *sp == '\t' ) )
sp++;
/* Trim the leading double quote if it exists. */
if ( *sp == '"' )
sp++;
*value = sp;
/* Trim the trailing whitespace if it exists. */
while ( ep > sp &&
( *( ep - 1 ) == ' ' || *( ep - 1 ) == '\t' ) )
*--ep = 0;
/* Trim the trailing double quote if it exists. */
if ( ep > sp && *( ep - 1 ) == '"' )
*--ep = 0;
return 1;
}
|
DoS Overflow
| 0
|
_bdf_is_atom( char* line,
unsigned long linelen,
char** name,
char** value,
bdf_font_t* font )
{
int hold;
char *sp, *ep;
bdf_property_t* p;
*name = sp = ep = line;
while ( *ep && *ep != ' ' && *ep != '\t' )
ep++;
hold = -1;
if ( *ep )
{
hold = *ep;
*ep = 0;
}
p = bdf_get_property( sp, font );
/* Restore the character that was saved before any return can happen. */
if ( hold != -1 )
*ep = (char)hold;
/* If the property exists and is not an atom, just return here. */
if ( p && p->format != BDF_ATOM )
return 0;
/* The property is an atom. Trim all leading and trailing whitespace */
/* and double quotes for the atom value. */
sp = ep;
ep = line + linelen;
/* Trim the leading whitespace if it exists. */
if ( *sp )
*sp++ = 0;
while ( *sp &&
( *sp == ' ' || *sp == '\t' ) )
sp++;
/* Trim the leading double quote if it exists. */
if ( *sp == '"' )
sp++;
*value = sp;
/* Trim the trailing whitespace if it exists. */
while ( ep > sp &&
( *( ep - 1 ) == ' ' || *( ep - 1 ) == '\t' ) )
*--ep = 0;
/* Trim the trailing double quote if it exists. */
if ( ep > sp && *( ep - 1 ) == '"' )
*--ep = 0;
return 1;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,158
|
_bdf_list_done( _bdf_list_t* list )
{
FT_Memory memory = list->memory;
if ( memory )
{
FT_FREE( list->field );
FT_ZERO( list );
}
}
|
DoS Overflow
| 0
|
_bdf_list_done( _bdf_list_t* list )
{
FT_Memory memory = list->memory;
if ( memory )
{
FT_FREE( list->field );
FT_ZERO( list );
}
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,159
|
_bdf_list_init( _bdf_list_t* list,
FT_Memory memory )
{
FT_ZERO( list );
list->memory = memory;
}
|
DoS Overflow
| 0
|
_bdf_list_init( _bdf_list_t* list,
FT_Memory memory )
{
FT_ZERO( list );
list->memory = memory;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,160
|
_bdf_list_split( _bdf_list_t* list,
char* separators,
char* line,
unsigned long linelen )
{
int mult, final_empty;
char *sp, *ep, *end;
char seps[32];
FT_Error error = BDF_Err_Ok;
/* Initialize the list. */
list->used = 0;
if ( list->size )
{
list->field[0] = (char*)empty;
list->field[1] = (char*)empty;
list->field[2] = (char*)empty;
list->field[3] = (char*)empty;
list->field[4] = (char*)empty;
}
/* If the line is empty, then simply return. */
if ( linelen == 0 || line[0] == 0 )
goto Exit;
/* In the original code, if the `separators' parameter is NULL or */
/* empty, the list is split into individual bytes. We don't need */
/* this, so an error is signaled. */
if ( separators == 0 || *separators == 0 )
{
error = BDF_Err_Invalid_Argument;
goto Exit;
}
/* Prepare the separator bitmap. */
FT_MEM_ZERO( seps, 32 );
/* If the very last character of the separator string is a plus, then */
/* set the `mult' flag to indicate that multiple separators should be */
/* collapsed into one. */
for ( mult = 0, sp = separators; sp && *sp; sp++ )
{
if ( *sp == '+' && *( sp + 1 ) == 0 )
mult = 1;
else
setsbit( seps, *sp );
}
/* Break the line up into fields. */
for ( final_empty = 0, sp = ep = line, end = sp + linelen;
sp < end && *sp; )
{
/* Collect everything that is not a separator. */
for ( ; *ep && !sbitset( seps, *ep ); ep++ )
;
/* Resize the list if necessary. */
if ( list->used == list->size )
{
error = _bdf_list_ensure( list, list->used + 1 );
if ( error )
goto Exit;
}
/* Assign the field appropriately. */
list->field[list->used++] = ( ep > sp ) ? sp : (char*)empty;
sp = ep;
if ( mult )
{
/* If multiple separators should be collapsed, do it now by */
/* setting all the separator characters to 0. */
for ( ; *ep && sbitset( seps, *ep ); ep++ )
*ep = 0;
}
else if ( *ep != 0 )
/* Don't collapse multiple separators by making them 0, so just */
/* make the one encountered 0. */
*ep++ = 0;
final_empty = ( ep > sp && *ep == 0 );
sp = ep;
}
/* Finally, NULL-terminate the list. */
if ( list->used + final_empty >= list->size )
{
error = _bdf_list_ensure( list, list->used + final_empty + 1 );
if ( error )
goto Exit;
}
if ( final_empty )
list->field[list->used++] = (char*)empty;
list->field[list->used] = 0;
Exit:
return error;
}
|
DoS Overflow
| 0
|
_bdf_list_split( _bdf_list_t* list,
char* separators,
char* line,
unsigned long linelen )
{
int mult, final_empty;
char *sp, *ep, *end;
char seps[32];
FT_Error error = BDF_Err_Ok;
/* Initialize the list. */
list->used = 0;
if ( list->size )
{
list->field[0] = (char*)empty;
list->field[1] = (char*)empty;
list->field[2] = (char*)empty;
list->field[3] = (char*)empty;
list->field[4] = (char*)empty;
}
/* If the line is empty, then simply return. */
if ( linelen == 0 || line[0] == 0 )
goto Exit;
/* In the original code, if the `separators' parameter is NULL or */
/* empty, the list is split into individual bytes. We don't need */
/* this, so an error is signaled. */
if ( separators == 0 || *separators == 0 )
{
error = BDF_Err_Invalid_Argument;
goto Exit;
}
/* Prepare the separator bitmap. */
FT_MEM_ZERO( seps, 32 );
/* If the very last character of the separator string is a plus, then */
/* set the `mult' flag to indicate that multiple separators should be */
/* collapsed into one. */
for ( mult = 0, sp = separators; sp && *sp; sp++ )
{
if ( *sp == '+' && *( sp + 1 ) == 0 )
mult = 1;
else
setsbit( seps, *sp );
}
/* Break the line up into fields. */
for ( final_empty = 0, sp = ep = line, end = sp + linelen;
sp < end && *sp; )
{
/* Collect everything that is not a separator. */
for ( ; *ep && !sbitset( seps, *ep ); ep++ )
;
/* Resize the list if necessary. */
if ( list->used == list->size )
{
error = _bdf_list_ensure( list, list->used + 1 );
if ( error )
goto Exit;
}
/* Assign the field appropriately. */
list->field[list->used++] = ( ep > sp ) ? sp : (char*)empty;
sp = ep;
if ( mult )
{
/* If multiple separators should be collapsed, do it now by */
/* setting all the separator characters to 0. */
for ( ; *ep && sbitset( seps, *ep ); ep++ )
*ep = 0;
}
else if ( *ep != 0 )
/* Don't collapse multiple separators by making them 0, so just */
/* make the one encountered 0. */
*ep++ = 0;
final_empty = ( ep > sp && *ep == 0 );
sp = ep;
}
/* Finally, NULL-terminate the list. */
if ( list->used + final_empty >= list->size )
{
error = _bdf_list_ensure( list, list->used + final_empty + 1 );
if ( error )
goto Exit;
}
if ( final_empty )
list->field[list->used++] = (char*)empty;
list->field[list->used] = 0;
Exit:
return error;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,161
|
_bdf_parse_properties( char* line,
unsigned long linelen,
unsigned long lineno,
void* call_data,
void* client_data )
{
unsigned long vlen;
_bdf_line_func_t* next;
_bdf_parse_t* p;
char* name;
char* value;
char nbuf[128];
FT_Error error = BDF_Err_Ok;
FT_UNUSED( lineno );
next = (_bdf_line_func_t *)call_data;
p = (_bdf_parse_t *) client_data;
/* Check for the end of the properties. */
if ( ft_memcmp( line, "ENDPROPERTIES", 13 ) == 0 )
{
/* If the FONT_ASCENT or FONT_DESCENT properties have not been */
/* encountered yet, then make sure they are added as properties and */
/* make sure they are set from the font bounding box info. */
/* */
/* This is *always* done regardless of the options, because X11 */
/* requires these two fields to compile fonts. */
if ( bdf_get_font_property( p->font, "FONT_ASCENT" ) == 0 )
{
p->font->font_ascent = p->font->bbx.ascent;
ft_sprintf( nbuf, "%hd", p->font->bbx.ascent );
error = _bdf_add_property( p->font, (char *)"FONT_ASCENT",
nbuf, lineno );
if ( error )
goto Exit;
FT_TRACE2(( "_bdf_parse_properties: " ACMSG1, p->font->bbx.ascent ));
p->font->modified = 1;
}
if ( bdf_get_font_property( p->font, "FONT_DESCENT" ) == 0 )
{
p->font->font_descent = p->font->bbx.descent;
ft_sprintf( nbuf, "%hd", p->font->bbx.descent );
error = _bdf_add_property( p->font, (char *)"FONT_DESCENT",
nbuf, lineno );
if ( error )
goto Exit;
FT_TRACE2(( "_bdf_parse_properties: " ACMSG2, p->font->bbx.descent ));
p->font->modified = 1;
}
p->flags &= ~_BDF_PROPS;
*next = _bdf_parse_glyphs;
goto Exit;
}
/* Ignore the _XFREE86_GLYPH_RANGES properties. */
if ( ft_memcmp( line, "_XFREE86_GLYPH_RANGES", 21 ) == 0 )
goto Exit;
/* Handle COMMENT fields and properties in a special way to preserve */
/* the spacing. */
if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
{
name = value = line;
value += 7;
if ( *value )
*value++ = 0;
error = _bdf_add_property( p->font, name, value, lineno );
if ( error )
goto Exit;
}
else if ( _bdf_is_atom( line, linelen, &name, &value, p->font ) )
{
error = _bdf_add_property( p->font, name, value, lineno );
if ( error )
goto Exit;
}
else
{
error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
if ( error )
goto Exit;
name = p->list.field[0];
_bdf_list_shift( &p->list, 1 );
value = _bdf_list_join( &p->list, ' ', &vlen );
error = _bdf_add_property( p->font, name, value, lineno );
if ( error )
goto Exit;
}
Exit:
return error;
}
|
DoS Overflow
| 0
|
_bdf_parse_properties( char* line,
unsigned long linelen,
unsigned long lineno,
void* call_data,
void* client_data )
{
unsigned long vlen;
_bdf_line_func_t* next;
_bdf_parse_t* p;
char* name;
char* value;
char nbuf[128];
FT_Error error = BDF_Err_Ok;
FT_UNUSED( lineno );
next = (_bdf_line_func_t *)call_data;
p = (_bdf_parse_t *) client_data;
/* Check for the end of the properties. */
if ( ft_memcmp( line, "ENDPROPERTIES", 13 ) == 0 )
{
/* If the FONT_ASCENT or FONT_DESCENT properties have not been */
/* encountered yet, then make sure they are added as properties and */
/* make sure they are set from the font bounding box info. */
/* */
/* This is *always* done regardless of the options, because X11 */
/* requires these two fields to compile fonts. */
if ( bdf_get_font_property( p->font, "FONT_ASCENT" ) == 0 )
{
p->font->font_ascent = p->font->bbx.ascent;
ft_sprintf( nbuf, "%hd", p->font->bbx.ascent );
error = _bdf_add_property( p->font, (char *)"FONT_ASCENT",
nbuf, lineno );
if ( error )
goto Exit;
FT_TRACE2(( "_bdf_parse_properties: " ACMSG1, p->font->bbx.ascent ));
p->font->modified = 1;
}
if ( bdf_get_font_property( p->font, "FONT_DESCENT" ) == 0 )
{
p->font->font_descent = p->font->bbx.descent;
ft_sprintf( nbuf, "%hd", p->font->bbx.descent );
error = _bdf_add_property( p->font, (char *)"FONT_DESCENT",
nbuf, lineno );
if ( error )
goto Exit;
FT_TRACE2(( "_bdf_parse_properties: " ACMSG2, p->font->bbx.descent ));
p->font->modified = 1;
}
p->flags &= ~_BDF_PROPS;
*next = _bdf_parse_glyphs;
goto Exit;
}
/* Ignore the _XFREE86_GLYPH_RANGES properties. */
if ( ft_memcmp( line, "_XFREE86_GLYPH_RANGES", 21 ) == 0 )
goto Exit;
/* Handle COMMENT fields and properties in a special way to preserve */
/* the spacing. */
if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
{
name = value = line;
value += 7;
if ( *value )
*value++ = 0;
error = _bdf_add_property( p->font, name, value, lineno );
if ( error )
goto Exit;
}
else if ( _bdf_is_atom( line, linelen, &name, &value, p->font ) )
{
error = _bdf_add_property( p->font, name, value, lineno );
if ( error )
goto Exit;
}
else
{
error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
if ( error )
goto Exit;
name = p->list.field[0];
_bdf_list_shift( &p->list, 1 );
value = _bdf_list_join( &p->list, ' ', &vlen );
error = _bdf_add_property( p->font, name, value, lineno );
if ( error )
goto Exit;
}
Exit:
return error;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,162
|
_bdf_parse_start( char* line,
unsigned long linelen,
unsigned long lineno,
void* call_data,
void* client_data )
{
unsigned long slen;
_bdf_line_func_t* next;
_bdf_parse_t* p;
bdf_font_t* font;
char *s;
FT_Memory memory = NULL;
FT_Error error = BDF_Err_Ok;
FT_UNUSED( lineno ); /* only used in debug mode */
next = (_bdf_line_func_t *)call_data;
p = (_bdf_parse_t *) client_data;
if ( p->font )
memory = p->font->memory;
/* Check for a comment. This is done to handle those fonts that have */
/* comments before the STARTFONT line for some reason. */
if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
{
if ( p->opts->keep_comments != 0 && p->font != 0 )
{
linelen -= 7;
s = line + 7;
if ( *s != 0 )
{
s++;
linelen--;
}
error = _bdf_add_comment( p->font, s, linelen );
if ( error )
goto Exit;
/* here font is not defined! */
}
goto Exit;
}
if ( !( p->flags & _BDF_START ) )
{
memory = p->memory;
if ( ft_memcmp( line, "STARTFONT", 9 ) != 0 )
{
/* we don't emit an error message since this code gets */
/* explicitly caught one level higher */
error = BDF_Err_Missing_Startfont_Field;
goto Exit;
}
p->flags = _BDF_START;
font = p->font = 0;
if ( FT_NEW( font ) )
goto Exit;
p->font = font;
font->memory = p->memory;
p->memory = 0;
{ /* setup */
size_t i;
bdf_property_t* prop;
error = hash_init( &(font->proptbl), memory );
if ( error )
goto Exit;
for ( i = 0, prop = (bdf_property_t*)_bdf_properties;
i < _num_bdf_properties; i++, prop++ )
{
error = hash_insert( prop->name, i,
&(font->proptbl), memory );
if ( error )
goto Exit;
}
}
if ( FT_ALLOC( p->font->internal, sizeof ( hashtable ) ) )
goto Exit;
error = hash_init( (hashtable *)p->font->internal,memory );
if ( error )
goto Exit;
p->font->spacing = p->opts->font_spacing;
p->font->default_char = -1;
goto Exit;
}
/* Check for the start of the properties. */
if ( ft_memcmp( line, "STARTPROPERTIES", 15 ) == 0 )
{
if ( !( p->flags & _BDF_FONT_BBX ) )
{
/* Missing the FONTBOUNDINGBOX field. */
FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" ));
error = BDF_Err_Missing_Fontboundingbox_Field;
goto Exit;
}
error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
if ( error )
goto Exit;
/* at this point, `p->font' can't be NULL */
p->cnt = p->font->props_size = _bdf_atoul( p->list.field[1], 0, 10 );
if ( FT_NEW_ARRAY( p->font->props, p->cnt ) )
{
p->font->props_size = 0;
goto Exit;
}
p->flags |= _BDF_PROPS;
*next = _bdf_parse_properties;
goto Exit;
}
/* Check for the FONTBOUNDINGBOX field. */
if ( ft_memcmp( line, "FONTBOUNDINGBOX", 15 ) == 0 )
{
if ( !( p->flags & _BDF_SIZE ) )
{
/* Missing the SIZE field. */
FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "SIZE" ));
error = BDF_Err_Missing_Size_Field;
goto Exit;
}
error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
if ( error )
goto Exit;
p->font->bbx.width = _bdf_atos( p->list.field[1], 0, 10 );
p->font->bbx.height = _bdf_atos( p->list.field[2], 0, 10 );
p->font->bbx.x_offset = _bdf_atos( p->list.field[3], 0, 10 );
p->font->bbx.y_offset = _bdf_atos( p->list.field[4], 0, 10 );
p->font->bbx.ascent = (short)( p->font->bbx.height +
p->font->bbx.y_offset );
p->font->bbx.descent = (short)( -p->font->bbx.y_offset );
p->flags |= _BDF_FONT_BBX;
goto Exit;
}
/* The next thing to check for is the FONT field. */
if ( ft_memcmp( line, "FONT", 4 ) == 0 )
{
error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
if ( error )
goto Exit;
_bdf_list_shift( &p->list, 1 );
s = _bdf_list_join( &p->list, ' ', &slen );
if ( !s )
{
FT_ERROR(( "_bdf_parse_start: " ERRMSG8, lineno, "FONT" ));
error = BDF_Err_Invalid_File_Format;
goto Exit;
}
/* Allowing multiple `FONT' lines (which is invalid) doesn't hurt... */
FT_FREE( p->font->name );
if ( FT_NEW_ARRAY( p->font->name, slen + 1 ) )
goto Exit;
FT_MEM_COPY( p->font->name, s, slen + 1 );
/* If the font name is an XLFD name, set the spacing to the one in */
/* the font name. If there is no spacing fall back on the default. */
error = _bdf_set_default_spacing( p->font, p->opts, lineno );
if ( error )
goto Exit;
p->flags |= _BDF_FONT_NAME;
goto Exit;
}
/* Check for the SIZE field. */
if ( ft_memcmp( line, "SIZE", 4 ) == 0 )
{
if ( !( p->flags & _BDF_FONT_NAME ) )
{
/* Missing the FONT field. */
FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONT" ));
error = BDF_Err_Missing_Font_Field;
goto Exit;
}
error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
if ( error )
goto Exit;
p->font->point_size = _bdf_atoul( p->list.field[1], 0, 10 );
p->font->resolution_x = _bdf_atoul( p->list.field[2], 0, 10 );
p->font->resolution_y = _bdf_atoul( p->list.field[3], 0, 10 );
/* Check for the bits per pixel field. */
if ( p->list.used == 5 )
{
unsigned short bitcount, i, shift;
p->font->bpp = (unsigned short)_bdf_atos( p->list.field[4], 0, 10 );
/* Only values 1, 2, 4, 8 are allowed. */
shift = p->font->bpp;
bitcount = 0;
for ( i = 0; shift > 0; i++ )
{
if ( shift & 1 )
bitcount = i;
shift >>= 1;
}
shift = (short)( ( bitcount > 3 ) ? 8 : ( 1 << bitcount ) );
if ( p->font->bpp > shift || p->font->bpp != shift )
{
/* select next higher value */
p->font->bpp = (unsigned short)( shift << 1 );
FT_TRACE2(( "_bdf_parse_start: " ACMSG11, p->font->bpp ));
}
}
else
p->font->bpp = 1;
p->flags |= _BDF_SIZE;
goto Exit;
}
/* Check for the CHARS field -- font properties are optional */
if ( ft_memcmp( line, "CHARS", 5 ) == 0 )
{
char nbuf[128];
if ( !( p->flags & _BDF_FONT_BBX ) )
{
/* Missing the FONTBOUNDINGBOX field. */
FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" ));
error = BDF_Err_Missing_Fontboundingbox_Field;
goto Exit;
}
/* Add the two standard X11 properties which are required */
/* for compiling fonts. */
p->font->font_ascent = p->font->bbx.ascent;
ft_sprintf( nbuf, "%hd", p->font->bbx.ascent );
error = _bdf_add_property( p->font, (char *)"FONT_ASCENT",
nbuf, lineno );
if ( error )
goto Exit;
FT_TRACE2(( "_bdf_parse_properties: " ACMSG1, p->font->bbx.ascent ));
p->font->font_descent = p->font->bbx.descent;
ft_sprintf( nbuf, "%hd", p->font->bbx.descent );
error = _bdf_add_property( p->font, (char *)"FONT_DESCENT",
nbuf, lineno );
if ( error )
goto Exit;
FT_TRACE2(( "_bdf_parse_properties: " ACMSG2, p->font->bbx.descent ));
p->font->modified = 1;
*next = _bdf_parse_glyphs;
/* A special return value. */
error = -1;
goto Exit;
}
FT_ERROR(( "_bdf_parse_start: " ERRMSG9, lineno ));
error = BDF_Err_Invalid_File_Format;
Exit:
return error;
}
|
DoS Overflow
| 0
|
_bdf_parse_start( char* line,
unsigned long linelen,
unsigned long lineno,
void* call_data,
void* client_data )
{
unsigned long slen;
_bdf_line_func_t* next;
_bdf_parse_t* p;
bdf_font_t* font;
char *s;
FT_Memory memory = NULL;
FT_Error error = BDF_Err_Ok;
FT_UNUSED( lineno ); /* only used in debug mode */
next = (_bdf_line_func_t *)call_data;
p = (_bdf_parse_t *) client_data;
if ( p->font )
memory = p->font->memory;
/* Check for a comment. This is done to handle those fonts that have */
/* comments before the STARTFONT line for some reason. */
if ( ft_memcmp( line, "COMMENT", 7 ) == 0 )
{
if ( p->opts->keep_comments != 0 && p->font != 0 )
{
linelen -= 7;
s = line + 7;
if ( *s != 0 )
{
s++;
linelen--;
}
error = _bdf_add_comment( p->font, s, linelen );
if ( error )
goto Exit;
/* here font is not defined! */
}
goto Exit;
}
if ( !( p->flags & _BDF_START ) )
{
memory = p->memory;
if ( ft_memcmp( line, "STARTFONT", 9 ) != 0 )
{
/* we don't emit an error message since this code gets */
/* explicitly caught one level higher */
error = BDF_Err_Missing_Startfont_Field;
goto Exit;
}
p->flags = _BDF_START;
font = p->font = 0;
if ( FT_NEW( font ) )
goto Exit;
p->font = font;
font->memory = p->memory;
p->memory = 0;
{ /* setup */
size_t i;
bdf_property_t* prop;
error = hash_init( &(font->proptbl), memory );
if ( error )
goto Exit;
for ( i = 0, prop = (bdf_property_t*)_bdf_properties;
i < _num_bdf_properties; i++, prop++ )
{
error = hash_insert( prop->name, i,
&(font->proptbl), memory );
if ( error )
goto Exit;
}
}
if ( FT_ALLOC( p->font->internal, sizeof ( hashtable ) ) )
goto Exit;
error = hash_init( (hashtable *)p->font->internal,memory );
if ( error )
goto Exit;
p->font->spacing = p->opts->font_spacing;
p->font->default_char = -1;
goto Exit;
}
/* Check for the start of the properties. */
if ( ft_memcmp( line, "STARTPROPERTIES", 15 ) == 0 )
{
if ( !( p->flags & _BDF_FONT_BBX ) )
{
/* Missing the FONTBOUNDINGBOX field. */
FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" ));
error = BDF_Err_Missing_Fontboundingbox_Field;
goto Exit;
}
error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
if ( error )
goto Exit;
/* at this point, `p->font' can't be NULL */
p->cnt = p->font->props_size = _bdf_atoul( p->list.field[1], 0, 10 );
if ( FT_NEW_ARRAY( p->font->props, p->cnt ) )
{
p->font->props_size = 0;
goto Exit;
}
p->flags |= _BDF_PROPS;
*next = _bdf_parse_properties;
goto Exit;
}
/* Check for the FONTBOUNDINGBOX field. */
if ( ft_memcmp( line, "FONTBOUNDINGBOX", 15 ) == 0 )
{
if ( !( p->flags & _BDF_SIZE ) )
{
/* Missing the SIZE field. */
FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "SIZE" ));
error = BDF_Err_Missing_Size_Field;
goto Exit;
}
error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
if ( error )
goto Exit;
p->font->bbx.width = _bdf_atos( p->list.field[1], 0, 10 );
p->font->bbx.height = _bdf_atos( p->list.field[2], 0, 10 );
p->font->bbx.x_offset = _bdf_atos( p->list.field[3], 0, 10 );
p->font->bbx.y_offset = _bdf_atos( p->list.field[4], 0, 10 );
p->font->bbx.ascent = (short)( p->font->bbx.height +
p->font->bbx.y_offset );
p->font->bbx.descent = (short)( -p->font->bbx.y_offset );
p->flags |= _BDF_FONT_BBX;
goto Exit;
}
/* The next thing to check for is the FONT field. */
if ( ft_memcmp( line, "FONT", 4 ) == 0 )
{
error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
if ( error )
goto Exit;
_bdf_list_shift( &p->list, 1 );
s = _bdf_list_join( &p->list, ' ', &slen );
if ( !s )
{
FT_ERROR(( "_bdf_parse_start: " ERRMSG8, lineno, "FONT" ));
error = BDF_Err_Invalid_File_Format;
goto Exit;
}
/* Allowing multiple `FONT' lines (which is invalid) doesn't hurt... */
FT_FREE( p->font->name );
if ( FT_NEW_ARRAY( p->font->name, slen + 1 ) )
goto Exit;
FT_MEM_COPY( p->font->name, s, slen + 1 );
/* If the font name is an XLFD name, set the spacing to the one in */
/* the font name. If there is no spacing fall back on the default. */
error = _bdf_set_default_spacing( p->font, p->opts, lineno );
if ( error )
goto Exit;
p->flags |= _BDF_FONT_NAME;
goto Exit;
}
/* Check for the SIZE field. */
if ( ft_memcmp( line, "SIZE", 4 ) == 0 )
{
if ( !( p->flags & _BDF_FONT_NAME ) )
{
/* Missing the FONT field. */
FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONT" ));
error = BDF_Err_Missing_Font_Field;
goto Exit;
}
error = _bdf_list_split( &p->list, (char *)" +", line, linelen );
if ( error )
goto Exit;
p->font->point_size = _bdf_atoul( p->list.field[1], 0, 10 );
p->font->resolution_x = _bdf_atoul( p->list.field[2], 0, 10 );
p->font->resolution_y = _bdf_atoul( p->list.field[3], 0, 10 );
/* Check for the bits per pixel field. */
if ( p->list.used == 5 )
{
unsigned short bitcount, i, shift;
p->font->bpp = (unsigned short)_bdf_atos( p->list.field[4], 0, 10 );
/* Only values 1, 2, 4, 8 are allowed. */
shift = p->font->bpp;
bitcount = 0;
for ( i = 0; shift > 0; i++ )
{
if ( shift & 1 )
bitcount = i;
shift >>= 1;
}
shift = (short)( ( bitcount > 3 ) ? 8 : ( 1 << bitcount ) );
if ( p->font->bpp > shift || p->font->bpp != shift )
{
/* select next higher value */
p->font->bpp = (unsigned short)( shift << 1 );
FT_TRACE2(( "_bdf_parse_start: " ACMSG11, p->font->bpp ));
}
}
else
p->font->bpp = 1;
p->flags |= _BDF_SIZE;
goto Exit;
}
/* Check for the CHARS field -- font properties are optional */
if ( ft_memcmp( line, "CHARS", 5 ) == 0 )
{
char nbuf[128];
if ( !( p->flags & _BDF_FONT_BBX ) )
{
/* Missing the FONTBOUNDINGBOX field. */
FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" ));
error = BDF_Err_Missing_Fontboundingbox_Field;
goto Exit;
}
/* Add the two standard X11 properties which are required */
/* for compiling fonts. */
p->font->font_ascent = p->font->bbx.ascent;
ft_sprintf( nbuf, "%hd", p->font->bbx.ascent );
error = _bdf_add_property( p->font, (char *)"FONT_ASCENT",
nbuf, lineno );
if ( error )
goto Exit;
FT_TRACE2(( "_bdf_parse_properties: " ACMSG1, p->font->bbx.ascent ));
p->font->font_descent = p->font->bbx.descent;
ft_sprintf( nbuf, "%hd", p->font->bbx.descent );
error = _bdf_add_property( p->font, (char *)"FONT_DESCENT",
nbuf, lineno );
if ( error )
goto Exit;
FT_TRACE2(( "_bdf_parse_properties: " ACMSG2, p->font->bbx.descent ));
p->font->modified = 1;
*next = _bdf_parse_glyphs;
/* A special return value. */
error = -1;
goto Exit;
}
FT_ERROR(( "_bdf_parse_start: " ERRMSG9, lineno ));
error = BDF_Err_Invalid_File_Format;
Exit:
return error;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,163
|
_bdf_set_default_spacing( bdf_font_t* font,
bdf_options_t* opts,
unsigned long lineno )
{
size_t len;
char name[256];
_bdf_list_t list;
FT_Memory memory;
FT_Error error = BDF_Err_Ok;
if ( font == 0 || font->name == 0 || font->name[0] == 0 )
{
error = BDF_Err_Invalid_Argument;
goto Exit;
}
memory = font->memory;
_bdf_list_init( &list, memory );
font->spacing = opts->font_spacing;
len = ft_strlen( font->name ) + 1;
/* Limit ourselves to 256 characters in the font name. */
if ( len >= 256 )
{
FT_ERROR(( "_bdf_set_default_spacing: " ERRMSG7, lineno ));
error = BDF_Err_Invalid_Argument;
goto Exit;
}
FT_MEM_COPY( name, font->name, len );
error = _bdf_list_split( &list, (char *)"-", name, len );
if ( error )
goto Fail;
if ( list.used == 15 )
{
switch ( list.field[11][0] )
{
case 'C':
case 'c':
font->spacing = BDF_CHARCELL;
break;
case 'M':
case 'm':
font->spacing = BDF_MONOWIDTH;
break;
case 'P':
case 'p':
font->spacing = BDF_PROPORTIONAL;
break;
}
}
Fail:
_bdf_list_done( &list );
Exit:
return error;
}
|
DoS Overflow
| 0
|
_bdf_set_default_spacing( bdf_font_t* font,
bdf_options_t* opts,
unsigned long lineno )
{
size_t len;
char name[256];
_bdf_list_t list;
FT_Memory memory;
FT_Error error = BDF_Err_Ok;
if ( font == 0 || font->name == 0 || font->name[0] == 0 )
{
error = BDF_Err_Invalid_Argument;
goto Exit;
}
memory = font->memory;
_bdf_list_init( &list, memory );
font->spacing = opts->font_spacing;
len = ft_strlen( font->name ) + 1;
/* Limit ourselves to 256 characters in the font name. */
if ( len >= 256 )
{
FT_ERROR(( "_bdf_set_default_spacing: " ERRMSG7, lineno ));
error = BDF_Err_Invalid_Argument;
goto Exit;
}
FT_MEM_COPY( name, font->name, len );
error = _bdf_list_split( &list, (char *)"-", name, len );
if ( error )
goto Fail;
if ( list.used == 15 )
{
switch ( list.field[11][0] )
{
case 'C':
case 'c':
font->spacing = BDF_CHARCELL;
break;
case 'M':
case 'm':
font->spacing = BDF_MONOWIDTH;
break;
case 'P':
case 'p':
font->spacing = BDF_PROPORTIONAL;
break;
}
}
Fail:
_bdf_list_done( &list );
Exit:
return error;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,164
|
bdf_create_property( char* name,
int format,
bdf_font_t* font )
{
size_t n;
bdf_property_t* p;
FT_Memory memory = font->memory;
FT_Error error = BDF_Err_Ok;
/* First check whether the property has */
/* already been added or not. If it has, then */
/* simply ignore it. */
if ( hash_lookup( name, &(font->proptbl) ) )
goto Exit;
if ( FT_RENEW_ARRAY( font->user_props,
font->nuser_props,
font->nuser_props + 1 ) )
goto Exit;
p = font->user_props + font->nuser_props;
FT_ZERO( p );
n = ft_strlen( name ) + 1;
if ( n > FT_ULONG_MAX )
return BDF_Err_Invalid_Argument;
if ( FT_NEW_ARRAY( p->name, n ) )
goto Exit;
FT_MEM_COPY( (char *)p->name, name, n );
p->format = format;
p->builtin = 0;
n = _num_bdf_properties + font->nuser_props;
error = hash_insert( p->name, n, &(font->proptbl), memory );
if ( error )
goto Exit;
font->nuser_props++;
Exit:
return error;
}
|
DoS Overflow
| 0
|
bdf_create_property( char* name,
int format,
bdf_font_t* font )
{
size_t n;
bdf_property_t* p;
FT_Memory memory = font->memory;
FT_Error error = BDF_Err_Ok;
/* First check whether the property has */
/* already been added or not. If it has, then */
/* simply ignore it. */
if ( hash_lookup( name, &(font->proptbl) ) )
goto Exit;
if ( FT_RENEW_ARRAY( font->user_props,
font->nuser_props,
font->nuser_props + 1 ) )
goto Exit;
p = font->user_props + font->nuser_props;
FT_ZERO( p );
n = ft_strlen( name ) + 1;
if ( n > FT_ULONG_MAX )
return BDF_Err_Invalid_Argument;
if ( FT_NEW_ARRAY( p->name, n ) )
goto Exit;
FT_MEM_COPY( (char *)p->name, name, n );
p->format = format;
p->builtin = 0;
n = _num_bdf_properties + font->nuser_props;
error = hash_insert( p->name, n, &(font->proptbl), memory );
if ( error )
goto Exit;
font->nuser_props++;
Exit:
return error;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,165
|
bdf_free_font( bdf_font_t* font )
{
bdf_property_t* prop;
unsigned long i;
bdf_glyph_t* glyphs;
FT_Memory memory;
if ( font == 0 )
return;
memory = font->memory;
FT_FREE( font->name );
/* Free up the internal hash table of property names. */
if ( font->internal )
{
hash_free( (hashtable *)font->internal, memory );
FT_FREE( font->internal );
}
/* Free up the comment info. */
FT_FREE( font->comments );
/* Free up the properties. */
for ( i = 0; i < font->props_size; i++ )
{
if ( font->props[i].format == BDF_ATOM )
FT_FREE( font->props[i].value.atom );
}
FT_FREE( font->props );
/* Free up the character info. */
for ( i = 0, glyphs = font->glyphs;
i < font->glyphs_used; i++, glyphs++ )
{
FT_FREE( glyphs->name );
FT_FREE( glyphs->bitmap );
}
for ( i = 0, glyphs = font->unencoded; i < font->unencoded_used;
i++, glyphs++ )
{
FT_FREE( glyphs->name );
FT_FREE( glyphs->bitmap );
}
FT_FREE( font->glyphs );
FT_FREE( font->unencoded );
/* Free up the overflow storage if it was used. */
for ( i = 0, glyphs = font->overflow.glyphs;
i < font->overflow.glyphs_used; i++, glyphs++ )
{
FT_FREE( glyphs->name );
FT_FREE( glyphs->bitmap );
}
FT_FREE( font->overflow.glyphs );
/* bdf_cleanup */
hash_free( &(font->proptbl), memory );
/* Free up the user defined properties. */
for ( prop = font->user_props, i = 0;
i < font->nuser_props; i++, prop++ )
{
FT_FREE( prop->name );
if ( prop->format == BDF_ATOM )
FT_FREE( prop->value.atom );
}
FT_FREE( font->user_props );
/* FREE( font ); */ /* XXX Fixme */
}
|
DoS Overflow
| 0
|
bdf_free_font( bdf_font_t* font )
{
bdf_property_t* prop;
unsigned long i;
bdf_glyph_t* glyphs;
FT_Memory memory;
if ( font == 0 )
return;
memory = font->memory;
FT_FREE( font->name );
/* Free up the internal hash table of property names. */
if ( font->internal )
{
hash_free( (hashtable *)font->internal, memory );
FT_FREE( font->internal );
}
/* Free up the comment info. */
FT_FREE( font->comments );
/* Free up the properties. */
for ( i = 0; i < font->props_size; i++ )
{
if ( font->props[i].format == BDF_ATOM )
FT_FREE( font->props[i].value.atom );
}
FT_FREE( font->props );
/* Free up the character info. */
for ( i = 0, glyphs = font->glyphs;
i < font->glyphs_used; i++, glyphs++ )
{
FT_FREE( glyphs->name );
FT_FREE( glyphs->bitmap );
}
for ( i = 0, glyphs = font->unencoded; i < font->unencoded_used;
i++, glyphs++ )
{
FT_FREE( glyphs->name );
FT_FREE( glyphs->bitmap );
}
FT_FREE( font->glyphs );
FT_FREE( font->unencoded );
/* Free up the overflow storage if it was used. */
for ( i = 0, glyphs = font->overflow.glyphs;
i < font->overflow.glyphs_used; i++, glyphs++ )
{
FT_FREE( glyphs->name );
FT_FREE( glyphs->bitmap );
}
FT_FREE( font->overflow.glyphs );
/* bdf_cleanup */
hash_free( &(font->proptbl), memory );
/* Free up the user defined properties. */
for ( prop = font->user_props, i = 0;
i < font->nuser_props; i++, prop++ )
{
FT_FREE( prop->name );
if ( prop->format == BDF_ATOM )
FT_FREE( prop->value.atom );
}
FT_FREE( font->user_props );
/* FREE( font ); */ /* XXX Fixme */
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,166
|
bdf_get_font_property( bdf_font_t* font,
const char* name )
{
hashnode hn;
if ( font == 0 || font->props_size == 0 || name == 0 || *name == 0 )
return 0;
hn = hash_lookup( name, (hashtable *)font->internal );
return hn ? ( font->props + hn->data ) : 0;
}
|
DoS Overflow
| 0
|
bdf_get_font_property( bdf_font_t* font,
const char* name )
{
hashnode hn;
if ( font == 0 || font->props_size == 0 || name == 0 || *name == 0 )
return 0;
hn = hash_lookup( name, (hashtable *)font->internal );
return hn ? ( font->props + hn->data ) : 0;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,167
|
bdf_get_property( char* name,
bdf_font_t* font )
{
hashnode hn;
size_t propid;
if ( name == 0 || *name == 0 )
return 0;
if ( ( hn = hash_lookup( name, &(font->proptbl) ) ) == 0 )
return 0;
propid = hn->data;
if ( propid >= _num_bdf_properties )
return font->user_props + ( propid - _num_bdf_properties );
return (bdf_property_t*)_bdf_properties + propid;
}
|
DoS Overflow
| 0
|
bdf_get_property( char* name,
bdf_font_t* font )
{
hashnode hn;
size_t propid;
if ( name == 0 || *name == 0 )
return 0;
if ( ( hn = hash_lookup( name, &(font->proptbl) ) ) == 0 )
return 0;
propid = hn->data;
if ( propid >= _num_bdf_properties )
return font->user_props + ( propid - _num_bdf_properties );
return (bdf_property_t*)_bdf_properties + propid;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,168
|
bdf_load_font( FT_Stream stream,
FT_Memory extmemory,
bdf_options_t* opts,
bdf_font_t* *font )
{
unsigned long lineno = 0; /* make compiler happy */
_bdf_parse_t *p = NULL;
FT_Memory memory = extmemory;
FT_Error error = BDF_Err_Ok;
if ( FT_NEW( p ) )
goto Exit;
memory = NULL;
p->opts = (bdf_options_t*)( ( opts != 0 ) ? opts : &_bdf_opts );
p->minlb = 32767;
p->memory = extmemory; /* only during font creation */
_bdf_list_init( &p->list, extmemory );
error = _bdf_readstream( stream, _bdf_parse_start,
(void *)p, &lineno );
if ( error )
goto Fail;
if ( p->font != 0 )
{
/* If the font is not proportional, set the font's monowidth */
/* field to the width of the font bounding box. */
memory = p->font->memory;
if ( p->font->spacing != BDF_PROPORTIONAL )
p->font->monowidth = p->font->bbx.width;
/* If the number of glyphs loaded is not that of the original count, */
/* indicate the difference. */
if ( p->cnt != p->font->glyphs_used + p->font->unencoded_used )
{
FT_TRACE2(( "bdf_load_font: " ACMSG15, p->cnt,
p->font->glyphs_used + p->font->unencoded_used ));
p->font->modified = 1;
}
/* Once the font has been loaded, adjust the overall font metrics if */
/* necessary. */
if ( p->opts->correct_metrics != 0 &&
( p->font->glyphs_used > 0 || p->font->unencoded_used > 0 ) )
{
if ( p->maxrb - p->minlb != p->font->bbx.width )
{
FT_TRACE2(( "bdf_load_font: " ACMSG3,
p->font->bbx.width, p->maxrb - p->minlb ));
p->font->bbx.width = (unsigned short)( p->maxrb - p->minlb );
p->font->modified = 1;
}
if ( p->font->bbx.x_offset != p->minlb )
{
FT_TRACE2(( "bdf_load_font: " ACMSG4,
p->font->bbx.x_offset, p->minlb ));
p->font->bbx.x_offset = p->minlb;
p->font->modified = 1;
}
if ( p->font->bbx.ascent != p->maxas )
{
FT_TRACE2(( "bdf_load_font: " ACMSG5,
p->font->bbx.ascent, p->maxas ));
p->font->bbx.ascent = p->maxas;
p->font->modified = 1;
}
if ( p->font->bbx.descent != p->maxds )
{
FT_TRACE2(( "bdf_load_font: " ACMSG6,
p->font->bbx.descent, p->maxds ));
p->font->bbx.descent = p->maxds;
p->font->bbx.y_offset = (short)( -p->maxds );
p->font->modified = 1;
}
if ( p->maxas + p->maxds != p->font->bbx.height )
{
FT_TRACE2(( "bdf_load_font: " ACMSG7,
p->font->bbx.height, p->maxas + p->maxds ));
p->font->bbx.height = (unsigned short)( p->maxas + p->maxds );
}
if ( p->flags & _BDF_SWIDTH_ADJ )
FT_TRACE2(( "bdf_load_font: " ACMSG8 ));
}
}
if ( p->flags & _BDF_START )
{
/* The ENDFONT field was never reached or did not exist. */
if ( !( p->flags & _BDF_GLYPHS ) )
{
/* Error happened while parsing header. */
FT_ERROR(( "bdf_load_font: " ERRMSG2, lineno ));
error = BDF_Err_Corrupted_Font_Header;
goto Exit;
}
else
{
/* Error happened when parsing glyphs. */
FT_ERROR(( "bdf_load_font: " ERRMSG3, lineno ));
error = BDF_Err_Corrupted_Font_Glyphs;
goto Exit;
}
}
if ( p->font != 0 )
{
/* Make sure the comments are NULL terminated if they exist. */
memory = p->font->memory;
if ( p->font->comments_len > 0 )
{
if ( FT_RENEW_ARRAY( p->font->comments,
p->font->comments_len,
p->font->comments_len + 1 ) )
goto Fail;
p->font->comments[p->font->comments_len] = 0;
}
}
else if ( error == BDF_Err_Ok )
error = BDF_Err_Invalid_File_Format;
*font = p->font;
Exit:
if ( p )
{
_bdf_list_done( &p->list );
memory = extmemory;
FT_FREE( p );
}
return error;
Fail:
bdf_free_font( p->font );
memory = extmemory;
FT_FREE( p->font );
goto Exit;
}
|
DoS Overflow
| 0
|
bdf_load_font( FT_Stream stream,
FT_Memory extmemory,
bdf_options_t* opts,
bdf_font_t* *font )
{
unsigned long lineno = 0; /* make compiler happy */
_bdf_parse_t *p = NULL;
FT_Memory memory = extmemory;
FT_Error error = BDF_Err_Ok;
if ( FT_NEW( p ) )
goto Exit;
memory = NULL;
p->opts = (bdf_options_t*)( ( opts != 0 ) ? opts : &_bdf_opts );
p->minlb = 32767;
p->memory = extmemory; /* only during font creation */
_bdf_list_init( &p->list, extmemory );
error = _bdf_readstream( stream, _bdf_parse_start,
(void *)p, &lineno );
if ( error )
goto Fail;
if ( p->font != 0 )
{
/* If the font is not proportional, set the font's monowidth */
/* field to the width of the font bounding box. */
memory = p->font->memory;
if ( p->font->spacing != BDF_PROPORTIONAL )
p->font->monowidth = p->font->bbx.width;
/* If the number of glyphs loaded is not that of the original count, */
/* indicate the difference. */
if ( p->cnt != p->font->glyphs_used + p->font->unencoded_used )
{
FT_TRACE2(( "bdf_load_font: " ACMSG15, p->cnt,
p->font->glyphs_used + p->font->unencoded_used ));
p->font->modified = 1;
}
/* Once the font has been loaded, adjust the overall font metrics if */
/* necessary. */
if ( p->opts->correct_metrics != 0 &&
( p->font->glyphs_used > 0 || p->font->unencoded_used > 0 ) )
{
if ( p->maxrb - p->minlb != p->font->bbx.width )
{
FT_TRACE2(( "bdf_load_font: " ACMSG3,
p->font->bbx.width, p->maxrb - p->minlb ));
p->font->bbx.width = (unsigned short)( p->maxrb - p->minlb );
p->font->modified = 1;
}
if ( p->font->bbx.x_offset != p->minlb )
{
FT_TRACE2(( "bdf_load_font: " ACMSG4,
p->font->bbx.x_offset, p->minlb ));
p->font->bbx.x_offset = p->minlb;
p->font->modified = 1;
}
if ( p->font->bbx.ascent != p->maxas )
{
FT_TRACE2(( "bdf_load_font: " ACMSG5,
p->font->bbx.ascent, p->maxas ));
p->font->bbx.ascent = p->maxas;
p->font->modified = 1;
}
if ( p->font->bbx.descent != p->maxds )
{
FT_TRACE2(( "bdf_load_font: " ACMSG6,
p->font->bbx.descent, p->maxds ));
p->font->bbx.descent = p->maxds;
p->font->bbx.y_offset = (short)( -p->maxds );
p->font->modified = 1;
}
if ( p->maxas + p->maxds != p->font->bbx.height )
{
FT_TRACE2(( "bdf_load_font: " ACMSG7,
p->font->bbx.height, p->maxas + p->maxds ));
p->font->bbx.height = (unsigned short)( p->maxas + p->maxds );
}
if ( p->flags & _BDF_SWIDTH_ADJ )
FT_TRACE2(( "bdf_load_font: " ACMSG8 ));
}
}
if ( p->flags & _BDF_START )
{
/* The ENDFONT field was never reached or did not exist. */
if ( !( p->flags & _BDF_GLYPHS ) )
{
/* Error happened while parsing header. */
FT_ERROR(( "bdf_load_font: " ERRMSG2, lineno ));
error = BDF_Err_Corrupted_Font_Header;
goto Exit;
}
else
{
/* Error happened when parsing glyphs. */
FT_ERROR(( "bdf_load_font: " ERRMSG3, lineno ));
error = BDF_Err_Corrupted_Font_Glyphs;
goto Exit;
}
}
if ( p->font != 0 )
{
/* Make sure the comments are NULL terminated if they exist. */
memory = p->font->memory;
if ( p->font->comments_len > 0 )
{
if ( FT_RENEW_ARRAY( p->font->comments,
p->font->comments_len,
p->font->comments_len + 1 ) )
goto Fail;
p->font->comments[p->font->comments_len] = 0;
}
}
else if ( error == BDF_Err_Ok )
error = BDF_Err_Invalid_File_Format;
*font = p->font;
Exit:
if ( p )
{
_bdf_list_done( &p->list );
memory = extmemory;
FT_FREE( p );
}
return error;
Fail:
bdf_free_font( p->font );
memory = extmemory;
FT_FREE( p->font );
goto Exit;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,169
|
hash_bucket( const char* key,
hashtable* ht )
{
const char* kp = key;
unsigned long res = 0;
hashnode* bp = ht->table, *ndp;
/* Mocklisp hash function. */
while ( *kp )
res = ( res << 5 ) - res + *kp++;
ndp = bp + ( res % ht->size );
while ( *ndp )
{
kp = (*ndp)->key;
if ( kp[0] == key[0] && ft_strcmp( kp, key ) == 0 )
break;
ndp--;
if ( ndp < bp )
ndp = bp + ( ht->size - 1 );
}
return ndp;
}
|
DoS Overflow
| 0
|
hash_bucket( const char* key,
hashtable* ht )
{
const char* kp = key;
unsigned long res = 0;
hashnode* bp = ht->table, *ndp;
/* Mocklisp hash function. */
while ( *kp )
res = ( res << 5 ) - res + *kp++;
ndp = bp + ( res % ht->size );
while ( *ndp )
{
kp = (*ndp)->key;
if ( kp[0] == key[0] && ft_strcmp( kp, key ) == 0 )
break;
ndp--;
if ( ndp < bp )
ndp = bp + ( ht->size - 1 );
}
return ndp;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,170
|
hash_free( hashtable* ht,
FT_Memory memory )
{
if ( ht != 0 )
{
int i, sz = ht->size;
hashnode* bp = ht->table;
for ( i = 0; i < sz; i++, bp++ )
FT_FREE( *bp );
FT_FREE( ht->table );
}
}
|
DoS Overflow
| 0
|
hash_free( hashtable* ht,
FT_Memory memory )
{
if ( ht != 0 )
{
int i, sz = ht->size;
hashnode* bp = ht->table;
for ( i = 0; i < sz; i++, bp++ )
FT_FREE( *bp );
FT_FREE( ht->table );
}
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,171
|
hash_init( hashtable* ht,
FT_Memory memory )
{
int sz = INITIAL_HT_SIZE;
FT_Error error = BDF_Err_Ok;
ht->size = sz;
ht->limit = sz / 3;
ht->used = 0;
if ( FT_NEW_ARRAY( ht->table, sz ) )
goto Exit;
Exit:
return error;
}
|
DoS Overflow
| 0
|
hash_init( hashtable* ht,
FT_Memory memory )
{
int sz = INITIAL_HT_SIZE;
FT_Error error = BDF_Err_Ok;
ht->size = sz;
ht->limit = sz / 3;
ht->used = 0;
if ( FT_NEW_ARRAY( ht->table, sz ) )
goto Exit;
Exit:
return error;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,172
|
hash_insert( char* key,
size_t data,
hashtable* ht,
FT_Memory memory )
{
hashnode nn, *bp = hash_bucket( key, ht );
FT_Error error = BDF_Err_Ok;
nn = *bp;
if ( !nn )
{
if ( FT_NEW( nn ) )
goto Exit;
*bp = nn;
nn->key = key;
nn->data = data;
if ( ht->used >= ht->limit )
{
error = hash_rehash( ht, memory );
if ( error )
goto Exit;
}
ht->used++;
}
else
nn->data = data;
Exit:
return error;
}
|
DoS Overflow
| 0
|
hash_insert( char* key,
size_t data,
hashtable* ht,
FT_Memory memory )
{
hashnode nn, *bp = hash_bucket( key, ht );
FT_Error error = BDF_Err_Ok;
nn = *bp;
if ( !nn )
{
if ( FT_NEW( nn ) )
goto Exit;
*bp = nn;
nn->key = key;
nn->data = data;
if ( ht->used >= ht->limit )
{
error = hash_rehash( ht, memory );
if ( error )
goto Exit;
}
ht->used++;
}
else
nn->data = data;
Exit:
return error;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,173
|
hash_lookup( const char* key,
hashtable* ht )
{
hashnode *np = hash_bucket( key, ht );
return *np;
}
|
DoS Overflow
| 0
|
hash_lookup( const char* key,
hashtable* ht )
{
hashnode *np = hash_bucket( key, ht );
return *np;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,174
|
hash_rehash( hashtable* ht,
FT_Memory memory )
{
hashnode* obp = ht->table, *bp, *nbp;
int i, sz = ht->size;
FT_Error error = BDF_Err_Ok;
ht->size <<= 1;
ht->limit = ht->size / 3;
if ( FT_NEW_ARRAY( ht->table, ht->size ) )
goto Exit;
for ( i = 0, bp = obp; i < sz; i++, bp++ )
{
if ( *bp )
{
nbp = hash_bucket( (*bp)->key, ht );
*nbp = *bp;
}
}
FT_FREE( obp );
Exit:
return error;
}
|
DoS Overflow
| 0
|
hash_rehash( hashtable* ht,
FT_Memory memory )
{
hashnode* obp = ht->table, *bp, *nbp;
int i, sz = ht->size;
FT_Error error = BDF_Err_Ok;
ht->size <<= 1;
ht->limit = ht->size / 3;
if ( FT_NEW_ARRAY( ht->table, ht->size ) )
goto Exit;
for ( i = 0, bp = obp; i < sz; i++, bp++ )
{
if ( *bp )
{
nbp = hash_bucket( (*bp)->key, ht );
*nbp = *bp;
}
}
FT_FREE( obp );
Exit:
return error;
}
|
@@ -1624,6 +1624,9 @@
if ( p->glyph_enc == -1 && p->list.used > 2 )
p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 );
+ if ( p->glyph_enc < -1 )
+ p->glyph_enc = -1;
+
FT_TRACE4(( DBGMSG2, p->glyph_enc ));
/* Check that the encoding is in the Unicode range because */
|
CWE-119
| null | null |
5,175
|
dfaerror (char const *mesg)
{
error (EXIT_TROUBLE, 0, "%s", mesg);
/* notreached */
/* Tell static analyzers that this function does not return. */
abort ();
}
|
Exec Code Overflow
| 0
|
dfaerror (char const *mesg)
{
error (EXIT_TROUBLE, 0, "%s", mesg);
/* notreached */
/* Tell static analyzers that this function does not return. */
abort ();
}
|
@@ -19,6 +19,7 @@
/* Written August 1992 by Mike Haertel. */
#include <config.h>
+#include "intprops.h"
#include "search.h"
#include "dfa.h"
@@ -71,7 +72,7 @@ dfawarn (char const *mesg)
/* Number of compiled fixed strings known to exactly match the regexp.
If kwsexec returns < kwset_exact_matches, then we don't need to
call the regexp matcher at all. */
-static int kwset_exact_matches;
+static size_t kwset_exact_matches;
static char const *
kwsincr_case (const char *must)
@@ -211,7 +212,9 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
{
char const *buflim, *beg, *end, *match, *best_match, *mb_start;
char eol = eolbyte;
- int backref, start, len, best_len;
+ int backref;
+ regoff_t start;
+ ptrdiff_t len, best_len;
struct kwsmatch kwsm;
size_t i, ret_val;
if (MB_CUR_MAX > 1)
@@ -294,6 +297,11 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
end = buflim;
}
+ /* If the "line" is longer than the maximum regexp offset,
+ die as if we've run out of memory. */
+ if (TYPE_MAXIMUM (regoff_t) < end - buf - 1)
+ xalloc_die ();
+
/* If we've made it to this point, this means DFA has seen
a probable match, and we need to run it through Regex. */
best_match = end;
@@ -301,10 +309,13 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
for (i = 0; i < pcount; i++)
{
patterns[i].regexbuf.not_eol = 0;
- if (0 <= (start = re_search (&(patterns[i].regexbuf),
- buf, end - buf - 1,
- beg - buf, end - beg - 1,
- &(patterns[i].regs))))
+ start = re_search (&(patterns[i].regexbuf),
+ buf, end - buf - 1,
+ beg - buf, end - beg - 1,
+ &(patterns[i].regs));
+ if (start < -1)
+ xalloc_die ();
+ else if (0 <= start)
{
len = patterns[i].regs.end[0] - start;
match = buf + start;
@@ -341,6 +352,8 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
len = re_match (&(patterns[i].regexbuf),
buf, match + len - beg, match - buf,
&(patterns[i].regs));
+ if (len < -1)
+ xalloc_die ();
}
if (len <= 0)
{
@@ -354,7 +367,11 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
match - buf, end - match - 1,
&(patterns[i].regs));
if (start < 0)
- break;
+ {
+ if (start < -1)
+ xalloc_die ();
+ break;
+ }
len = patterns[i].regs.end[0] - start;
match = buf + start;
}
|
CWE-189
| null | null |
5,176
|
dfawarn (char const *mesg)
{
static enum { DW_NONE = 0, DW_POSIX, DW_GNU } mode;
if (mode == DW_NONE)
mode = (getenv ("POSIXLY_CORRECT") ? DW_POSIX : DW_GNU);
if (mode == DW_GNU)
dfaerror (mesg);
}
|
Exec Code Overflow
| 0
|
dfawarn (char const *mesg)
{
static enum { DW_NONE = 0, DW_POSIX, DW_GNU } mode;
if (mode == DW_NONE)
mode = (getenv ("POSIXLY_CORRECT") ? DW_POSIX : DW_GNU);
if (mode == DW_GNU)
dfaerror (mesg);
}
|
@@ -19,6 +19,7 @@
/* Written August 1992 by Mike Haertel. */
#include <config.h>
+#include "intprops.h"
#include "search.h"
#include "dfa.h"
@@ -71,7 +72,7 @@ dfawarn (char const *mesg)
/* Number of compiled fixed strings known to exactly match the regexp.
If kwsexec returns < kwset_exact_matches, then we don't need to
call the regexp matcher at all. */
-static int kwset_exact_matches;
+static size_t kwset_exact_matches;
static char const *
kwsincr_case (const char *must)
@@ -211,7 +212,9 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
{
char const *buflim, *beg, *end, *match, *best_match, *mb_start;
char eol = eolbyte;
- int backref, start, len, best_len;
+ int backref;
+ regoff_t start;
+ ptrdiff_t len, best_len;
struct kwsmatch kwsm;
size_t i, ret_val;
if (MB_CUR_MAX > 1)
@@ -294,6 +297,11 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
end = buflim;
}
+ /* If the "line" is longer than the maximum regexp offset,
+ die as if we've run out of memory. */
+ if (TYPE_MAXIMUM (regoff_t) < end - buf - 1)
+ xalloc_die ();
+
/* If we've made it to this point, this means DFA has seen
a probable match, and we need to run it through Regex. */
best_match = end;
@@ -301,10 +309,13 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
for (i = 0; i < pcount; i++)
{
patterns[i].regexbuf.not_eol = 0;
- if (0 <= (start = re_search (&(patterns[i].regexbuf),
- buf, end - buf - 1,
- beg - buf, end - beg - 1,
- &(patterns[i].regs))))
+ start = re_search (&(patterns[i].regexbuf),
+ buf, end - buf - 1,
+ beg - buf, end - beg - 1,
+ &(patterns[i].regs));
+ if (start < -1)
+ xalloc_die ();
+ else if (0 <= start)
{
len = patterns[i].regs.end[0] - start;
match = buf + start;
@@ -341,6 +352,8 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
len = re_match (&(patterns[i].regexbuf),
buf, match + len - beg, match - buf,
&(patterns[i].regs));
+ if (len < -1)
+ xalloc_die ();
}
if (len <= 0)
{
@@ -354,7 +367,11 @@ EGexecute (char const *buf, size_t size, size_t *match_size,
match - buf, end - match - 1,
&(patterns[i].regs));
if (start < 0)
- break;
+ {
+ if (start < -1)
+ xalloc_die ();
+ break;
+ }
len = patterns[i].regs.end[0] - start;
match = buf + start;
}
|
CWE-189
| null | null |
5,177
|
bmexec (kwset_t kws, char const *text, size_t size)
{
struct kwset const *kwset;
unsigned char const *d1;
char const *ep, *sp, *tp;
int d, gc, i, len, md2;
kwset = (struct kwset const *) kws;
len = kwset->mind;
if (len == 0)
return 0;
if (len > size)
return -1;
if (len == 1)
{
tp = memchr (text, kwset->target[0], size);
return tp ? tp - text : -1;
}
d1 = kwset->delta;
sp = kwset->target + len;
gc = U(sp[-2]);
md2 = kwset->mind2;
tp = text + len;
/* Significance of 12: 1 (initial offset) + 10 (skip loop) + 1 (md2). */
if (size > 12 * len)
/* 11 is not a bug, the initial offset happens only once. */
for (ep = text + size - 11 * len;;)
{
while (tp <= ep)
{
d = d1[U(tp[-1])], tp += d;
d = d1[U(tp[-1])], tp += d;
if (d == 0)
goto found;
d = d1[U(tp[-1])], tp += d;
d = d1[U(tp[-1])], tp += d;
d = d1[U(tp[-1])], tp += d;
if (d == 0)
goto found;
d = d1[U(tp[-1])], tp += d;
d = d1[U(tp[-1])], tp += d;
d = d1[U(tp[-1])], tp += d;
if (d == 0)
goto found;
d = d1[U(tp[-1])], tp += d;
d = d1[U(tp[-1])], tp += d;
}
break;
found:
if (U(tp[-2]) == gc)
{
for (i = 3; i <= len && U(tp[-i]) == U(sp[-i]); ++i)
;
if (i > len)
return tp - len - text;
}
tp += md2;
}
/* Now we have only a few characters left to search. We
carefully avoid ever producing an out-of-bounds pointer. */
ep = text + size;
d = d1[U(tp[-1])];
while (d <= ep - tp)
{
d = d1[U((tp += d)[-1])];
if (d != 0)
continue;
if (U(tp[-2]) == gc)
{
for (i = 3; i <= len && U(tp[-i]) == U(sp[-i]); ++i)
;
if (i > len)
return tp - len - text;
}
d = md2;
}
return -1;
}
|
Exec Code Overflow
| 0
|
bmexec (kwset_t kws, char const *text, size_t size)
{
struct kwset const *kwset;
unsigned char const *d1;
char const *ep, *sp, *tp;
int d, gc, i, len, md2;
kwset = (struct kwset const *) kws;
len = kwset->mind;
if (len == 0)
return 0;
if (len > size)
return -1;
if (len == 1)
{
tp = memchr (text, kwset->target[0], size);
return tp ? tp - text : -1;
}
d1 = kwset->delta;
sp = kwset->target + len;
gc = U(sp[-2]);
md2 = kwset->mind2;
tp = text + len;
/* Significance of 12: 1 (initial offset) + 10 (skip loop) + 1 (md2). */
if (size > 12 * len)
/* 11 is not a bug, the initial offset happens only once. */
for (ep = text + size - 11 * len;;)
{
while (tp <= ep)
{
d = d1[U(tp[-1])], tp += d;
d = d1[U(tp[-1])], tp += d;
if (d == 0)
goto found;
d = d1[U(tp[-1])], tp += d;
d = d1[U(tp[-1])], tp += d;
d = d1[U(tp[-1])], tp += d;
if (d == 0)
goto found;
d = d1[U(tp[-1])], tp += d;
d = d1[U(tp[-1])], tp += d;
d = d1[U(tp[-1])], tp += d;
if (d == 0)
goto found;
d = d1[U(tp[-1])], tp += d;
d = d1[U(tp[-1])], tp += d;
}
break;
found:
if (U(tp[-2]) == gc)
{
for (i = 3; i <= len && U(tp[-i]) == U(sp[-i]); ++i)
;
if (i > len)
return tp - len - text;
}
tp += md2;
}
/* Now we have only a few characters left to search. We
carefully avoid ever producing an out-of-bounds pointer. */
ep = text + size;
d = d1[U(tp[-1])];
while (d <= ep - tp)
{
d = d1[U((tp += d)[-1])];
if (d != 0)
continue;
if (U(tp[-2]) == gc)
{
for (i = 3; i <= len && U(tp[-i]) == U(sp[-i]); ++i)
;
if (i > len)
return tp - len - text;
}
d = md2;
}
return -1;
}
|
@@ -62,7 +62,7 @@ struct tree
/* Node of a trie representing a set of reversed keywords. */
struct trie
{
- unsigned int accepting; /* Word index of accepted word, or zero. */
+ size_t accepting; /* Word index of accepted word, or zero. */
struct tree *links; /* Tree of edges leaving this node. */
struct trie *parent; /* Parent of this node. */
struct trie *next; /* List of all trie nodes in level order. */
@@ -76,7 +76,7 @@ struct trie
struct kwset
{
struct obstack obstack; /* Obstack for node allocation. */
- int words; /* Number of words in the trie. */
+ ptrdiff_t words; /* Number of words in the trie. */
struct trie *trie; /* The trie itself. */
int mind; /* Minimum depth of an accepting node. */
int maxd; /* Maximum depth of any node. */
|
CWE-189
| null | null |
5,178
|
cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
{
struct kwset const *kwset;
struct trie * const *next;
struct trie const *trie;
struct trie const *accept;
char const *beg, *lim, *mch, *lmch;
unsigned char c;
unsigned char const *delta;
int d;
char const *end, *qlim;
struct tree const *tree;
char const *trans;
#ifdef lint
accept = NULL;
#endif
/* Initialize register copies and look for easy ways out. */
kwset = (struct kwset *) kws;
if (len < kwset->mind)
return -1;
next = kwset->next;
delta = kwset->delta;
trans = kwset->trans;
lim = text + len;
end = text;
if ((d = kwset->mind) != 0)
mch = NULL;
else
{
mch = text, accept = kwset->trie;
goto match;
}
if (len >= 4 * kwset->mind)
qlim = lim - 4 * kwset->mind;
else
qlim = NULL;
while (lim - end >= d)
{
if (qlim && end <= qlim)
{
end += d - 1;
while ((d = delta[c = *end]) && end < qlim)
{
end += d;
end += delta[U(*end)];
end += delta[U(*end)];
}
++end;
}
else
d = delta[c = (end += d)[-1]];
if (d)
continue;
beg = end - 1;
trie = next[c];
if (trie->accepting)
{
mch = beg;
accept = trie;
}
d = trie->shift;
while (beg > text)
{
c = trans ? trans[U(*--beg)] : *--beg;
tree = trie->links;
while (tree && c != tree->label)
if (c < tree->label)
tree = tree->llink;
else
tree = tree->rlink;
if (tree)
{
trie = tree->trie;
if (trie->accepting)
{
mch = beg;
accept = trie;
}
}
else
break;
d = trie->shift;
}
if (mch)
goto match;
}
return -1;
match:
/* Given a known match, find the longest possible match anchored
at or before its starting point. This is nearly a verbatim
copy of the preceding main search loops. */
if (lim - mch > kwset->maxd)
lim = mch + kwset->maxd;
lmch = 0;
d = 1;
while (lim - end >= d)
{
if ((d = delta[c = (end += d)[-1]]) != 0)
continue;
beg = end - 1;
if (!(trie = next[c]))
{
d = 1;
continue;
}
if (trie->accepting && beg <= mch)
{
lmch = beg;
accept = trie;
}
d = trie->shift;
while (beg > text)
{
c = trans ? trans[U(*--beg)] : *--beg;
tree = trie->links;
while (tree && c != tree->label)
if (c < tree->label)
tree = tree->llink;
else
tree = tree->rlink;
if (tree)
{
trie = tree->trie;
if (trie->accepting && beg <= mch)
{
lmch = beg;
accept = trie;
}
}
else
break;
d = trie->shift;
}
if (lmch)
{
mch = lmch;
goto match;
}
if (!d)
d = 1;
}
kwsmatch->index = accept->accepting / 2;
kwsmatch->offset[0] = mch - text;
kwsmatch->size[0] = accept->depth;
return mch - text;
}
|
Exec Code Overflow
| 0
|
cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
{
struct kwset const *kwset;
struct trie * const *next;
struct trie const *trie;
struct trie const *accept;
char const *beg, *lim, *mch, *lmch;
unsigned char c;
unsigned char const *delta;
int d;
char const *end, *qlim;
struct tree const *tree;
char const *trans;
#ifdef lint
accept = NULL;
#endif
/* Initialize register copies and look for easy ways out. */
kwset = (struct kwset *) kws;
if (len < kwset->mind)
return -1;
next = kwset->next;
delta = kwset->delta;
trans = kwset->trans;
lim = text + len;
end = text;
if ((d = kwset->mind) != 0)
mch = NULL;
else
{
mch = text, accept = kwset->trie;
goto match;
}
if (len >= 4 * kwset->mind)
qlim = lim - 4 * kwset->mind;
else
qlim = NULL;
while (lim - end >= d)
{
if (qlim && end <= qlim)
{
end += d - 1;
while ((d = delta[c = *end]) && end < qlim)
{
end += d;
end += delta[U(*end)];
end += delta[U(*end)];
}
++end;
}
else
d = delta[c = (end += d)[-1]];
if (d)
continue;
beg = end - 1;
trie = next[c];
if (trie->accepting)
{
mch = beg;
accept = trie;
}
d = trie->shift;
while (beg > text)
{
c = trans ? trans[U(*--beg)] : *--beg;
tree = trie->links;
while (tree && c != tree->label)
if (c < tree->label)
tree = tree->llink;
else
tree = tree->rlink;
if (tree)
{
trie = tree->trie;
if (trie->accepting)
{
mch = beg;
accept = trie;
}
}
else
break;
d = trie->shift;
}
if (mch)
goto match;
}
return -1;
match:
/* Given a known match, find the longest possible match anchored
at or before its starting point. This is nearly a verbatim
copy of the preceding main search loops. */
if (lim - mch > kwset->maxd)
lim = mch + kwset->maxd;
lmch = 0;
d = 1;
while (lim - end >= d)
{
if ((d = delta[c = (end += d)[-1]]) != 0)
continue;
beg = end - 1;
if (!(trie = next[c]))
{
d = 1;
continue;
}
if (trie->accepting && beg <= mch)
{
lmch = beg;
accept = trie;
}
d = trie->shift;
while (beg > text)
{
c = trans ? trans[U(*--beg)] : *--beg;
tree = trie->links;
while (tree && c != tree->label)
if (c < tree->label)
tree = tree->llink;
else
tree = tree->rlink;
if (tree)
{
trie = tree->trie;
if (trie->accepting && beg <= mch)
{
lmch = beg;
accept = trie;
}
}
else
break;
d = trie->shift;
}
if (lmch)
{
mch = lmch;
goto match;
}
if (!d)
d = 1;
}
kwsmatch->index = accept->accepting / 2;
kwsmatch->offset[0] = mch - text;
kwsmatch->size[0] = accept->depth;
return mch - text;
}
|
@@ -62,7 +62,7 @@ struct tree
/* Node of a trie representing a set of reversed keywords. */
struct trie
{
- unsigned int accepting; /* Word index of accepted word, or zero. */
+ size_t accepting; /* Word index of accepted word, or zero. */
struct tree *links; /* Tree of edges leaving this node. */
struct trie *parent; /* Parent of this node. */
struct trie *next; /* List of all trie nodes in level order. */
@@ -76,7 +76,7 @@ struct trie
struct kwset
{
struct obstack obstack; /* Obstack for node allocation. */
- int words; /* Number of words in the trie. */
+ ptrdiff_t words; /* Number of words in the trie. */
struct trie *trie; /* The trie itself. */
int mind; /* Minimum depth of an accepting node. */
int maxd; /* Maximum depth of any node. */
|
CWE-189
| null | null |
5,179
|
kwsalloc (char const *trans)
{
struct kwset *kwset;
kwset = (struct kwset *) malloc(sizeof (struct kwset));
if (!kwset)
return NULL;
obstack_init(&kwset->obstack);
kwset->words = 0;
kwset->trie
= (struct trie *) obstack_alloc(&kwset->obstack, sizeof (struct trie));
if (!kwset->trie)
{
kwsfree((kwset_t) kwset);
return NULL;
}
kwset->trie->accepting = 0;
kwset->trie->links = NULL;
kwset->trie->parent = NULL;
kwset->trie->next = NULL;
kwset->trie->fail = NULL;
kwset->trie->depth = 0;
kwset->trie->shift = 0;
kwset->mind = INT_MAX;
kwset->maxd = -1;
kwset->target = NULL;
kwset->trans = trans;
return (kwset_t) kwset;
}
|
Exec Code Overflow
| 0
|
kwsalloc (char const *trans)
{
struct kwset *kwset;
kwset = (struct kwset *) malloc(sizeof (struct kwset));
if (!kwset)
return NULL;
obstack_init(&kwset->obstack);
kwset->words = 0;
kwset->trie
= (struct trie *) obstack_alloc(&kwset->obstack, sizeof (struct trie));
if (!kwset->trie)
{
kwsfree((kwset_t) kwset);
return NULL;
}
kwset->trie->accepting = 0;
kwset->trie->links = NULL;
kwset->trie->parent = NULL;
kwset->trie->next = NULL;
kwset->trie->fail = NULL;
kwset->trie->depth = 0;
kwset->trie->shift = 0;
kwset->mind = INT_MAX;
kwset->maxd = -1;
kwset->target = NULL;
kwset->trans = trans;
return (kwset_t) kwset;
}
|
@@ -62,7 +62,7 @@ struct tree
/* Node of a trie representing a set of reversed keywords. */
struct trie
{
- unsigned int accepting; /* Word index of accepted word, or zero. */
+ size_t accepting; /* Word index of accepted word, or zero. */
struct tree *links; /* Tree of edges leaving this node. */
struct trie *parent; /* Parent of this node. */
struct trie *next; /* List of all trie nodes in level order. */
@@ -76,7 +76,7 @@ struct trie
struct kwset
{
struct obstack obstack; /* Obstack for node allocation. */
- int words; /* Number of words in the trie. */
+ ptrdiff_t words; /* Number of words in the trie. */
struct trie *trie; /* The trie itself. */
int mind; /* Minimum depth of an accepting node. */
int maxd; /* Maximum depth of any node. */
|
CWE-189
| null | null |
5,180
|
kwsexec (kwset_t kws, char const *text, size_t size, struct kwsmatch *kwsmatch)
{
struct kwset const *kwset = (struct kwset *) kws;
if (kwset->words == 1 && kwset->trans == NULL)
{
size_t ret = bmexec (kws, text, size);
if (ret != (size_t) -1)
{
kwsmatch->index = 0;
kwsmatch->offset[0] = ret;
kwsmatch->size[0] = kwset->mind;
}
return ret;
}
else
return cwexec(kws, text, size, kwsmatch);
}
|
Exec Code Overflow
| 0
|
kwsexec (kwset_t kws, char const *text, size_t size, struct kwsmatch *kwsmatch)
{
struct kwset const *kwset = (struct kwset *) kws;
if (kwset->words == 1 && kwset->trans == NULL)
{
size_t ret = bmexec (kws, text, size);
if (ret != (size_t) -1)
{
kwsmatch->index = 0;
kwsmatch->offset[0] = ret;
kwsmatch->size[0] = kwset->mind;
}
return ret;
}
else
return cwexec(kws, text, size, kwsmatch);
}
|
@@ -62,7 +62,7 @@ struct tree
/* Node of a trie representing a set of reversed keywords. */
struct trie
{
- unsigned int accepting; /* Word index of accepted word, or zero. */
+ size_t accepting; /* Word index of accepted word, or zero. */
struct tree *links; /* Tree of edges leaving this node. */
struct trie *parent; /* Parent of this node. */
struct trie *next; /* List of all trie nodes in level order. */
@@ -76,7 +76,7 @@ struct trie
struct kwset
{
struct obstack obstack; /* Obstack for node allocation. */
- int words; /* Number of words in the trie. */
+ ptrdiff_t words; /* Number of words in the trie. */
struct trie *trie; /* The trie itself. */
int mind; /* Minimum depth of an accepting node. */
int maxd; /* Maximum depth of any node. */
|
CWE-189
| null | null |
5,181
|
kwsfree (kwset_t kws)
{
struct kwset *kwset;
kwset = (struct kwset *) kws;
obstack_free(&kwset->obstack, NULL);
free(kws);
}
|
Exec Code Overflow
| 0
|
kwsfree (kwset_t kws)
{
struct kwset *kwset;
kwset = (struct kwset *) kws;
obstack_free(&kwset->obstack, NULL);
free(kws);
}
|
@@ -62,7 +62,7 @@ struct tree
/* Node of a trie representing a set of reversed keywords. */
struct trie
{
- unsigned int accepting; /* Word index of accepted word, or zero. */
+ size_t accepting; /* Word index of accepted word, or zero. */
struct tree *links; /* Tree of edges leaving this node. */
struct trie *parent; /* Parent of this node. */
struct trie *next; /* List of all trie nodes in level order. */
@@ -76,7 +76,7 @@ struct trie
struct kwset
{
struct obstack obstack; /* Obstack for node allocation. */
- int words; /* Number of words in the trie. */
+ ptrdiff_t words; /* Number of words in the trie. */
struct trie *trie; /* The trie itself. */
int mind; /* Minimum depth of an accepting node. */
int maxd; /* Maximum depth of any node. */
|
CWE-189
| null | null |
5,182
|
kwsincr (kwset_t kws, char const *text, size_t len)
{
struct kwset *kwset;
struct trie *trie;
unsigned char label;
struct tree *link;
int depth;
struct tree *links[DEPTH_SIZE];
enum { L, R } dirs[DEPTH_SIZE];
struct tree *t, *r, *l, *rl, *lr;
kwset = (struct kwset *) kws;
trie = kwset->trie;
text += len;
/* Descend the trie (built of reversed keywords) character-by-character,
installing new nodes when necessary. */
while (len--)
{
label = kwset->trans ? kwset->trans[U(*--text)] : *--text;
/* Descend the tree of outgoing links for this trie node,
looking for the current character and keeping track
of the path followed. */
link = trie->links;
links[0] = (struct tree *) &trie->links;
dirs[0] = L;
depth = 1;
while (link && label != link->label)
{
links[depth] = link;
if (label < link->label)
dirs[depth++] = L, link = link->llink;
else
dirs[depth++] = R, link = link->rlink;
}
/* The current character doesn't have an outgoing link at
this trie node, so build a new trie node and install
a link in the current trie node's tree. */
if (!link)
{
link = (struct tree *) obstack_alloc(&kwset->obstack,
sizeof (struct tree));
if (!link)
return _("memory exhausted");
link->llink = NULL;
link->rlink = NULL;
link->trie = (struct trie *) obstack_alloc(&kwset->obstack,
sizeof (struct trie));
if (!link->trie)
{
obstack_free(&kwset->obstack, link);
return _("memory exhausted");
}
link->trie->accepting = 0;
link->trie->links = NULL;
link->trie->parent = trie;
link->trie->next = NULL;
link->trie->fail = NULL;
link->trie->depth = trie->depth + 1;
link->trie->shift = 0;
link->label = label;
link->balance = 0;
/* Install the new tree node in its parent. */
if (dirs[--depth] == L)
links[depth]->llink = link;
else
links[depth]->rlink = link;
/* Back up the tree fixing the balance flags. */
while (depth && !links[depth]->balance)
{
if (dirs[depth] == L)
--links[depth]->balance;
else
++links[depth]->balance;
--depth;
}
/* Rebalance the tree by pointer rotations if necessary. */
if (depth && ((dirs[depth] == L && --links[depth]->balance)
|| (dirs[depth] == R && ++links[depth]->balance)))
{
switch (links[depth]->balance)
{
case (char) -2:
switch (dirs[depth + 1])
{
case L:
r = links[depth], t = r->llink, rl = t->rlink;
t->rlink = r, r->llink = rl;
t->balance = r->balance = 0;
break;
case R:
r = links[depth], l = r->llink, t = l->rlink;
rl = t->rlink, lr = t->llink;
t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
l->balance = t->balance != 1 ? 0 : -1;
r->balance = t->balance != (char) -1 ? 0 : 1;
t->balance = 0;
break;
default:
abort ();
}
break;
case 2:
switch (dirs[depth + 1])
{
case R:
l = links[depth], t = l->rlink, lr = t->llink;
t->llink = l, l->rlink = lr;
t->balance = l->balance = 0;
break;
case L:
l = links[depth], r = l->rlink, t = r->llink;
lr = t->llink, rl = t->rlink;
t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
l->balance = t->balance != 1 ? 0 : -1;
r->balance = t->balance != (char) -1 ? 0 : 1;
t->balance = 0;
break;
default:
abort ();
}
break;
default:
abort ();
}
if (dirs[depth - 1] == L)
links[depth - 1]->llink = t;
else
links[depth - 1]->rlink = t;
}
}
trie = link->trie;
}
/* Mark the node we finally reached as accepting, encoding the
index number of this word in the keyword set so far. */
if (!trie->accepting)
trie->accepting = 1 + 2 * kwset->words;
++kwset->words;
/* Keep track of the longest and shortest string of the keyword set. */
if (trie->depth < kwset->mind)
kwset->mind = trie->depth;
if (trie->depth > kwset->maxd)
kwset->maxd = trie->depth;
return NULL;
}
|
Exec Code Overflow
| 0
|
kwsincr (kwset_t kws, char const *text, size_t len)
{
struct kwset *kwset;
struct trie *trie;
unsigned char label;
struct tree *link;
int depth;
struct tree *links[DEPTH_SIZE];
enum { L, R } dirs[DEPTH_SIZE];
struct tree *t, *r, *l, *rl, *lr;
kwset = (struct kwset *) kws;
trie = kwset->trie;
text += len;
/* Descend the trie (built of reversed keywords) character-by-character,
installing new nodes when necessary. */
while (len--)
{
label = kwset->trans ? kwset->trans[U(*--text)] : *--text;
/* Descend the tree of outgoing links for this trie node,
looking for the current character and keeping track
of the path followed. */
link = trie->links;
links[0] = (struct tree *) &trie->links;
dirs[0] = L;
depth = 1;
while (link && label != link->label)
{
links[depth] = link;
if (label < link->label)
dirs[depth++] = L, link = link->llink;
else
dirs[depth++] = R, link = link->rlink;
}
/* The current character doesn't have an outgoing link at
this trie node, so build a new trie node and install
a link in the current trie node's tree. */
if (!link)
{
link = (struct tree *) obstack_alloc(&kwset->obstack,
sizeof (struct tree));
if (!link)
return _("memory exhausted");
link->llink = NULL;
link->rlink = NULL;
link->trie = (struct trie *) obstack_alloc(&kwset->obstack,
sizeof (struct trie));
if (!link->trie)
{
obstack_free(&kwset->obstack, link);
return _("memory exhausted");
}
link->trie->accepting = 0;
link->trie->links = NULL;
link->trie->parent = trie;
link->trie->next = NULL;
link->trie->fail = NULL;
link->trie->depth = trie->depth + 1;
link->trie->shift = 0;
link->label = label;
link->balance = 0;
/* Install the new tree node in its parent. */
if (dirs[--depth] == L)
links[depth]->llink = link;
else
links[depth]->rlink = link;
/* Back up the tree fixing the balance flags. */
while (depth && !links[depth]->balance)
{
if (dirs[depth] == L)
--links[depth]->balance;
else
++links[depth]->balance;
--depth;
}
/* Rebalance the tree by pointer rotations if necessary. */
if (depth && ((dirs[depth] == L && --links[depth]->balance)
|| (dirs[depth] == R && ++links[depth]->balance)))
{
switch (links[depth]->balance)
{
case (char) -2:
switch (dirs[depth + 1])
{
case L:
r = links[depth], t = r->llink, rl = t->rlink;
t->rlink = r, r->llink = rl;
t->balance = r->balance = 0;
break;
case R:
r = links[depth], l = r->llink, t = l->rlink;
rl = t->rlink, lr = t->llink;
t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
l->balance = t->balance != 1 ? 0 : -1;
r->balance = t->balance != (char) -1 ? 0 : 1;
t->balance = 0;
break;
default:
abort ();
}
break;
case 2:
switch (dirs[depth + 1])
{
case R:
l = links[depth], t = l->rlink, lr = t->llink;
t->llink = l, l->rlink = lr;
t->balance = l->balance = 0;
break;
case L:
l = links[depth], r = l->rlink, t = r->llink;
lr = t->llink, rl = t->rlink;
t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
l->balance = t->balance != 1 ? 0 : -1;
r->balance = t->balance != (char) -1 ? 0 : 1;
t->balance = 0;
break;
default:
abort ();
}
break;
default:
abort ();
}
if (dirs[depth - 1] == L)
links[depth - 1]->llink = t;
else
links[depth - 1]->rlink = t;
}
}
trie = link->trie;
}
/* Mark the node we finally reached as accepting, encoding the
index number of this word in the keyword set so far. */
if (!trie->accepting)
trie->accepting = 1 + 2 * kwset->words;
++kwset->words;
/* Keep track of the longest and shortest string of the keyword set. */
if (trie->depth < kwset->mind)
kwset->mind = trie->depth;
if (trie->depth > kwset->maxd)
kwset->maxd = trie->depth;
return NULL;
}
|
@@ -62,7 +62,7 @@ struct tree
/* Node of a trie representing a set of reversed keywords. */
struct trie
{
- unsigned int accepting; /* Word index of accepted word, or zero. */
+ size_t accepting; /* Word index of accepted word, or zero. */
struct tree *links; /* Tree of edges leaving this node. */
struct trie *parent; /* Parent of this node. */
struct trie *next; /* List of all trie nodes in level order. */
@@ -76,7 +76,7 @@ struct trie
struct kwset
{
struct obstack obstack; /* Obstack for node allocation. */
- int words; /* Number of words in the trie. */
+ ptrdiff_t words; /* Number of words in the trie. */
struct trie *trie; /* The trie itself. */
int mind; /* Minimum depth of an accepting node. */
int maxd; /* Maximum depth of any node. */
|
CWE-189
| null | null |
5,183
|
kwsprep (kwset_t kws)
{
struct kwset *kwset;
int i;
struct trie *curr;
char const *trans;
unsigned char delta[NCHAR];
kwset = (struct kwset *) kws;
/* Initial values for the delta table; will be changed later. The
delta entry for a given character is the smallest depth of any
node at which an outgoing edge is labeled by that character. */
memset(delta, kwset->mind < UCHAR_MAX ? kwset->mind : UCHAR_MAX, NCHAR);
/* Check if we can use the simple boyer-moore algorithm, instead
of the hairy commentz-walter algorithm. */
if (kwset->words == 1 && kwset->trans == NULL)
{
char c;
/* Looking for just one string. Extract it from the trie. */
kwset->target = obstack_alloc(&kwset->obstack, kwset->mind);
if (!kwset->target)
return _("memory exhausted");
for (i = kwset->mind - 1, curr = kwset->trie; i >= 0; --i)
{
kwset->target[i] = curr->links->label;
curr = curr->links->trie;
}
/* Build the Boyer Moore delta. Boy that's easy compared to CW. */
for (i = 0; i < kwset->mind; ++i)
delta[U(kwset->target[i])] = kwset->mind - (i + 1);
/* Find the minimal delta2 shift that we might make after
a backwards match has failed. */
c = kwset->target[kwset->mind - 1];
for (i = kwset->mind - 2; i >= 0; --i)
if (kwset->target[i] == c)
break;
kwset->mind2 = kwset->mind - (i + 1);
}
else
{
struct trie *fail;
struct trie *last, *next[NCHAR];
/* Traverse the nodes of the trie in level order, simultaneously
computing the delta table, failure function, and shift function. */
for (curr = last = kwset->trie; curr; curr = curr->next)
{
/* Enqueue the immediate descendents in the level order queue. */
enqueue(curr->links, &last);
curr->shift = kwset->mind;
curr->maxshift = kwset->mind;
/* Update the delta table for the descendents of this node. */
treedelta(curr->links, curr->depth, delta);
/* Compute the failure function for the decendents of this node. */
treefails(curr->links, curr->fail, kwset->trie);
/* Update the shifts at each node in the current node's chain
of fails back to the root. */
for (fail = curr->fail; fail; fail = fail->fail)
{
/* If the current node has some outgoing edge that the fail
doesn't, then the shift at the fail should be no larger
than the difference of their depths. */
if (!hasevery(fail->links, curr->links))
if (curr->depth - fail->depth < fail->shift)
fail->shift = curr->depth - fail->depth;
/* If the current node is accepting then the shift at the
fail and its descendents should be no larger than the
difference of their depths. */
if (curr->accepting && fail->maxshift > curr->depth - fail->depth)
fail->maxshift = curr->depth - fail->depth;
}
}
/* Traverse the trie in level order again, fixing up all nodes whose
shift exceeds their inherited maxshift. */
for (curr = kwset->trie->next; curr; curr = curr->next)
{
if (curr->maxshift > curr->parent->maxshift)
curr->maxshift = curr->parent->maxshift;
if (curr->shift > curr->maxshift)
curr->shift = curr->maxshift;
}
/* Create a vector, indexed by character code, of the outgoing links
from the root node. */
for (i = 0; i < NCHAR; ++i)
next[i] = NULL;
treenext(kwset->trie->links, next);
if ((trans = kwset->trans) != NULL)
for (i = 0; i < NCHAR; ++i)
kwset->next[i] = next[U(trans[i])];
else
memcpy(kwset->next, next, NCHAR * sizeof(struct trie *));
}
/* Fix things up for any translation table. */
if ((trans = kwset->trans) != NULL)
for (i = 0; i < NCHAR; ++i)
kwset->delta[i] = delta[U(trans[i])];
else
memcpy(kwset->delta, delta, NCHAR);
return NULL;
}
|
Exec Code Overflow
| 0
|
kwsprep (kwset_t kws)
{
struct kwset *kwset;
int i;
struct trie *curr;
char const *trans;
unsigned char delta[NCHAR];
kwset = (struct kwset *) kws;
/* Initial values for the delta table; will be changed later. The
delta entry for a given character is the smallest depth of any
node at which an outgoing edge is labeled by that character. */
memset(delta, kwset->mind < UCHAR_MAX ? kwset->mind : UCHAR_MAX, NCHAR);
/* Check if we can use the simple boyer-moore algorithm, instead
of the hairy commentz-walter algorithm. */
if (kwset->words == 1 && kwset->trans == NULL)
{
char c;
/* Looking for just one string. Extract it from the trie. */
kwset->target = obstack_alloc(&kwset->obstack, kwset->mind);
if (!kwset->target)
return _("memory exhausted");
for (i = kwset->mind - 1, curr = kwset->trie; i >= 0; --i)
{
kwset->target[i] = curr->links->label;
curr = curr->links->trie;
}
/* Build the Boyer Moore delta. Boy that's easy compared to CW. */
for (i = 0; i < kwset->mind; ++i)
delta[U(kwset->target[i])] = kwset->mind - (i + 1);
/* Find the minimal delta2 shift that we might make after
a backwards match has failed. */
c = kwset->target[kwset->mind - 1];
for (i = kwset->mind - 2; i >= 0; --i)
if (kwset->target[i] == c)
break;
kwset->mind2 = kwset->mind - (i + 1);
}
else
{
struct trie *fail;
struct trie *last, *next[NCHAR];
/* Traverse the nodes of the trie in level order, simultaneously
computing the delta table, failure function, and shift function. */
for (curr = last = kwset->trie; curr; curr = curr->next)
{
/* Enqueue the immediate descendents in the level order queue. */
enqueue(curr->links, &last);
curr->shift = kwset->mind;
curr->maxshift = kwset->mind;
/* Update the delta table for the descendents of this node. */
treedelta(curr->links, curr->depth, delta);
/* Compute the failure function for the decendents of this node. */
treefails(curr->links, curr->fail, kwset->trie);
/* Update the shifts at each node in the current node's chain
of fails back to the root. */
for (fail = curr->fail; fail; fail = fail->fail)
{
/* If the current node has some outgoing edge that the fail
doesn't, then the shift at the fail should be no larger
than the difference of their depths. */
if (!hasevery(fail->links, curr->links))
if (curr->depth - fail->depth < fail->shift)
fail->shift = curr->depth - fail->depth;
/* If the current node is accepting then the shift at the
fail and its descendents should be no larger than the
difference of their depths. */
if (curr->accepting && fail->maxshift > curr->depth - fail->depth)
fail->maxshift = curr->depth - fail->depth;
}
}
/* Traverse the trie in level order again, fixing up all nodes whose
shift exceeds their inherited maxshift. */
for (curr = kwset->trie->next; curr; curr = curr->next)
{
if (curr->maxshift > curr->parent->maxshift)
curr->maxshift = curr->parent->maxshift;
if (curr->shift > curr->maxshift)
curr->shift = curr->maxshift;
}
/* Create a vector, indexed by character code, of the outgoing links
from the root node. */
for (i = 0; i < NCHAR; ++i)
next[i] = NULL;
treenext(kwset->trie->links, next);
if ((trans = kwset->trans) != NULL)
for (i = 0; i < NCHAR; ++i)
kwset->next[i] = next[U(trans[i])];
else
memcpy(kwset->next, next, NCHAR * sizeof(struct trie *));
}
/* Fix things up for any translation table. */
if ((trans = kwset->trans) != NULL)
for (i = 0; i < NCHAR; ++i)
kwset->delta[i] = delta[U(trans[i])];
else
memcpy(kwset->delta, delta, NCHAR);
return NULL;
}
|
@@ -62,7 +62,7 @@ struct tree
/* Node of a trie representing a set of reversed keywords. */
struct trie
{
- unsigned int accepting; /* Word index of accepted word, or zero. */
+ size_t accepting; /* Word index of accepted word, or zero. */
struct tree *links; /* Tree of edges leaving this node. */
struct trie *parent; /* Parent of this node. */
struct trie *next; /* List of all trie nodes in level order. */
@@ -76,7 +76,7 @@ struct trie
struct kwset
{
struct obstack obstack; /* Obstack for node allocation. */
- int words; /* Number of words in the trie. */
+ ptrdiff_t words; /* Number of words in the trie. */
struct trie *trie; /* The trie itself. */
int mind; /* Minimum depth of an accepting node. */
int maxd; /* Maximum depth of any node. */
|
CWE-189
| null | null |
5,184
|
treefails (struct tree const *tree, struct trie const *fail,
struct trie *recourse)
{
struct tree *link;
if (!tree)
return;
treefails(tree->llink, fail, recourse);
treefails(tree->rlink, fail, recourse);
/* Find, in the chain of fails going back to the root, the first
node that has a descendent on the current label. */
while (fail)
{
link = fail->links;
while (link && tree->label != link->label)
if (tree->label < link->label)
link = link->llink;
else
link = link->rlink;
if (link)
{
tree->trie->fail = link->trie;
return;
}
fail = fail->fail;
}
tree->trie->fail = recourse;
}
|
Exec Code Overflow
| 0
|
treefails (struct tree const *tree, struct trie const *fail,
struct trie *recourse)
{
struct tree *link;
if (!tree)
return;
treefails(tree->llink, fail, recourse);
treefails(tree->rlink, fail, recourse);
/* Find, in the chain of fails going back to the root, the first
node that has a descendent on the current label. */
while (fail)
{
link = fail->links;
while (link && tree->label != link->label)
if (tree->label < link->label)
link = link->llink;
else
link = link->rlink;
if (link)
{
tree->trie->fail = link->trie;
return;
}
fail = fail->fail;
}
tree->trie->fail = recourse;
}
|
@@ -62,7 +62,7 @@ struct tree
/* Node of a trie representing a set of reversed keywords. */
struct trie
{
- unsigned int accepting; /* Word index of accepted word, or zero. */
+ size_t accepting; /* Word index of accepted word, or zero. */
struct tree *links; /* Tree of edges leaving this node. */
struct trie *parent; /* Parent of this node. */
struct trie *next; /* List of all trie nodes in level order. */
@@ -76,7 +76,7 @@ struct trie
struct kwset
{
struct obstack obstack; /* Obstack for node allocation. */
- int words; /* Number of words in the trie. */
+ ptrdiff_t words; /* Number of words in the trie. */
struct trie *trie; /* The trie itself. */
int mind; /* Minimum depth of an accepting node. */
int maxd; /* Maximum depth of any node. */
|
CWE-189
| null | null |
5,185
|
clean_up_stdout (void)
{
if (! write_error_seen)
close_stdout ();
close_stdout ();
}
|
Exec Code Overflow
| 0
|
clean_up_stdout (void)
{
if (! write_error_seen)
close_stdout ();
close_stdout ();
}
|
@@ -25,6 +25,7 @@
#include <wchar.h>
#include <wctype.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include "system.h"
@@ -425,17 +426,21 @@ clean_up_stdout (void)
close_stdout ();
}
-/* Convert STR to a positive integer, storing the result in *OUT.
+/* Convert STR to a nonnegative integer, storing the result in *OUT.
STR must be a valid context length argument; report an error if it
- isn't. */
+ isn't. Silently ceiling *OUT at the maximum value, as that is
+ practically equivalent to infinity for grep's purposes. */
static void
-context_length_arg (char const *str, int *out)
+context_length_arg (char const *str, intmax_t *out)
{
- uintmax_t value;
- if (! (xstrtoumax (str, 0, 10, &value, "") == LONGINT_OK
- && 0 <= (*out = value)
- && *out == value))
+ switch (xstrtoimax (str, 0, 10, out, ""))
{
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ if (0 <= *out)
+ break;
+ /* Fall through. */
+ default:
error (EXIT_TROUBLE, 0, "%s: %s", str,
_("invalid context length argument"));
}
@@ -603,12 +608,12 @@ static int out_invert; /* Print nonmatching stuff. */
static int out_file; /* Print filenames. */
static int out_line; /* Print line numbers. */
static int out_byte; /* Print byte offsets. */
-static int out_before; /* Lines of leading context. */
-static int out_after; /* Lines of trailing context. */
+static intmax_t out_before; /* Lines of leading context. */
+static intmax_t out_after; /* Lines of trailing context. */
static int count_matches; /* Count matching lines. */
static int list_files; /* List matching files. */
static int no_filenames; /* Suppress file names. */
-static off_t max_count; /* Stop after outputting this many
+static intmax_t max_count; /* Stop after outputting this many
lines from an input file. */
static int line_buffered; /* If nonzero, use line buffering, i.e.
fflush everyline out. */
@@ -622,8 +627,8 @@ static char const *lastout; /* Pointer after last character output;
NULL if no character has been output
or if it's conceptually before bufbeg. */
static uintmax_t totalnl; /* Total newline count before lastnl. */
-static off_t outleft; /* Maximum number of lines to be output. */
-static int pending; /* Pending lines of output.
+static intmax_t outleft; /* Maximum number of lines to be output. */
+static intmax_t pending; /* Pending lines of output.
Always kept 0 if out_quiet is true. */
static int done_on_match; /* Stop scanning file on first match. */
static int exit_on_match; /* Exit on first match. */
@@ -917,12 +922,12 @@ prpending (char const *lim)
/* Print the lines between BEG and LIM. Deal with context crap.
If NLINESP is non-null, store a count of lines between BEG and LIM. */
static void
-prtext (char const *beg, char const *lim, int *nlinesp)
+prtext (char const *beg, char const *lim, intmax_t *nlinesp)
{
static int used; /* avoid printing SEP_STR_GROUP before any output */
char const *bp, *p;
char eol = eolbyte;
- int i, n;
+ intmax_t i, n;
if (!out_quiet && pending > 0)
prpending (beg);
@@ -1026,10 +1031,10 @@ do_execute (char const *buf, size_t size, size_t *match_size, char const *start_
/* Scan the specified portion of the buffer, matching lines (or
between matching lines if OUT_INVERT is true). Return a count of
lines printed. */
-static int
+static intmax_t
grepbuf (char const *beg, char const *lim)
{
- int nlines, n;
+ intmax_t nlines, n;
char const *p;
size_t match_offset;
size_t match_size;
@@ -1046,7 +1051,7 @@ grepbuf (char const *beg, char const *lim)
break;
if (!out_invert)
{
- prtext (b, endp, (int *) 0);
+ prtext (b, endp, NULL);
nlines++;
outleft--;
if (!outleft || done_on_match)
@@ -1079,10 +1084,10 @@ grepbuf (char const *beg, char const *lim)
/* Search a given file. Normally, return a count of lines printed;
but if the file is a directory and we search it recursively, then
return -2 if there was a match, and -1 otherwise. */
-static int
+static intmax_t
grep (int fd, char const *file, struct stats *stats)
{
- int nlines, i;
+ intmax_t nlines, i;
int not_text;
size_t residue, save;
char oldc;
@@ -1212,7 +1217,7 @@ static int
grepfile (char const *file, struct stats *stats)
{
int desc;
- int count;
+ intmax_t count;
int status;
filename = (file ? file : label ? label : _("(standard input)"));
@@ -1319,7 +1324,7 @@ grepfile (char const *file, struct stats *stats)
else
fputc (0, stdout);
}
- printf ("%d\n", count);
+ printf ("%" PRIdMAX "\n", count);
}
status = !count;
@@ -1590,12 +1595,12 @@ setmatcher (char const *m)
etc. to the option copies. Return the number N of options found.
Do not set ARGV[N] to NULL. If ARGV is NULL, do not store ARGV[0]
etc. Backslash can be used to escape whitespace (and backslashes). */
-static int
+static size_t
prepend_args (char const *options, char *buf, char **argv)
{
char const *o = options;
char *b = buf;
- int n = 0;
+ size_t n = 0;
for (;;)
{
@@ -1625,10 +1630,14 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
if (options && *options)
{
char *buf = xmalloc (strlen (options) + 1);
- int prepended = prepend_args (options, buf, (char **) NULL);
+ size_t prepended = prepend_args (options, buf, NULL);
int argc = *pargc;
char *const *argv = *pargv;
- char **pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
+ char **pp;
+ enum { MAX_ARGS = MIN (INT_MAX, SIZE_MAX / sizeof *pp - 1) };
+ if (MAX_ARGS - argc < prepended)
+ xalloc_die ();
+ pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
*pargc = prepended + argc;
*pargv = pp;
*pp++ = *argv++;
@@ -1646,11 +1655,11 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
Process any digit options that were encountered on the way,
and store the resulting integer into *DEFAULT_CONTEXT. */
static int
-get_nondigit_option (int argc, char *const *argv, int *default_context)
+get_nondigit_option (int argc, char *const *argv, intmax_t *default_context)
{
static int prev_digit_optind = -1;
int opt, this_digit_optind, was_digit;
- char buf[sizeof (uintmax_t) * CHAR_BIT + 4];
+ char buf[INT_BUFSIZE_BOUND (intmax_t) + 4];
char *p = buf;
was_digit = 0;
@@ -1760,11 +1769,11 @@ main (int argc, char **argv)
char *keys;
size_t keycc, oldcc, keyalloc;
int with_filenames;
- int opt, cc, status, prepended;
+ size_t cc;
+ int opt, status, prepended;
int prev_optind, last_recursive;
- int default_context;
+ intmax_t default_context;
FILE *fp;
-
exit_failure = EXIT_TROUBLE;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -1776,7 +1785,7 @@ main (int argc, char **argv)
eolbyte = '\n';
filename_mask = ~0;
- max_count = TYPE_MAXIMUM (off_t);
+ max_count = INTMAX_MAX;
/* The value -1 means to use DEFAULT_CONTEXT. */
out_after = out_before = -1;
@@ -1947,23 +1956,15 @@ main (int argc, char **argv)
break;
case 'm':
- {
- uintmax_t value;
- switch (xstrtoumax (optarg, 0, 10, &value, ""))
- {
- case LONGINT_OK:
- max_count = value;
- if (0 <= max_count && max_count == value)
- break;
- /* Fall through. */
- case LONGINT_OVERFLOW:
- max_count = TYPE_MAXIMUM (off_t);
- break;
+ switch (xstrtoimax (optarg, 0, 10, &max_count, ""))
+ {
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ break;
- default:
- error (EXIT_TROUBLE, 0, _("invalid max count"));
- }
- }
+ default:
+ error (EXIT_TROUBLE, 0, _("invalid max count"));
+ }
break;
case 'n':
|
CWE-189
| null | null |
5,186
|
color_cap_mt_fct (void)
{
/* Our caller just set selected_match_color. */
context_match_color = selected_match_color;
}
|
Exec Code Overflow
| 0
|
color_cap_mt_fct (void)
{
/* Our caller just set selected_match_color. */
context_match_color = selected_match_color;
}
|
@@ -25,6 +25,7 @@
#include <wchar.h>
#include <wctype.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include "system.h"
@@ -425,17 +426,21 @@ clean_up_stdout (void)
close_stdout ();
}
-/* Convert STR to a positive integer, storing the result in *OUT.
+/* Convert STR to a nonnegative integer, storing the result in *OUT.
STR must be a valid context length argument; report an error if it
- isn't. */
+ isn't. Silently ceiling *OUT at the maximum value, as that is
+ practically equivalent to infinity for grep's purposes. */
static void
-context_length_arg (char const *str, int *out)
+context_length_arg (char const *str, intmax_t *out)
{
- uintmax_t value;
- if (! (xstrtoumax (str, 0, 10, &value, "") == LONGINT_OK
- && 0 <= (*out = value)
- && *out == value))
+ switch (xstrtoimax (str, 0, 10, out, ""))
{
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ if (0 <= *out)
+ break;
+ /* Fall through. */
+ default:
error (EXIT_TROUBLE, 0, "%s: %s", str,
_("invalid context length argument"));
}
@@ -603,12 +608,12 @@ static int out_invert; /* Print nonmatching stuff. */
static int out_file; /* Print filenames. */
static int out_line; /* Print line numbers. */
static int out_byte; /* Print byte offsets. */
-static int out_before; /* Lines of leading context. */
-static int out_after; /* Lines of trailing context. */
+static intmax_t out_before; /* Lines of leading context. */
+static intmax_t out_after; /* Lines of trailing context. */
static int count_matches; /* Count matching lines. */
static int list_files; /* List matching files. */
static int no_filenames; /* Suppress file names. */
-static off_t max_count; /* Stop after outputting this many
+static intmax_t max_count; /* Stop after outputting this many
lines from an input file. */
static int line_buffered; /* If nonzero, use line buffering, i.e.
fflush everyline out. */
@@ -622,8 +627,8 @@ static char const *lastout; /* Pointer after last character output;
NULL if no character has been output
or if it's conceptually before bufbeg. */
static uintmax_t totalnl; /* Total newline count before lastnl. */
-static off_t outleft; /* Maximum number of lines to be output. */
-static int pending; /* Pending lines of output.
+static intmax_t outleft; /* Maximum number of lines to be output. */
+static intmax_t pending; /* Pending lines of output.
Always kept 0 if out_quiet is true. */
static int done_on_match; /* Stop scanning file on first match. */
static int exit_on_match; /* Exit on first match. */
@@ -917,12 +922,12 @@ prpending (char const *lim)
/* Print the lines between BEG and LIM. Deal with context crap.
If NLINESP is non-null, store a count of lines between BEG and LIM. */
static void
-prtext (char const *beg, char const *lim, int *nlinesp)
+prtext (char const *beg, char const *lim, intmax_t *nlinesp)
{
static int used; /* avoid printing SEP_STR_GROUP before any output */
char const *bp, *p;
char eol = eolbyte;
- int i, n;
+ intmax_t i, n;
if (!out_quiet && pending > 0)
prpending (beg);
@@ -1026,10 +1031,10 @@ do_execute (char const *buf, size_t size, size_t *match_size, char const *start_
/* Scan the specified portion of the buffer, matching lines (or
between matching lines if OUT_INVERT is true). Return a count of
lines printed. */
-static int
+static intmax_t
grepbuf (char const *beg, char const *lim)
{
- int nlines, n;
+ intmax_t nlines, n;
char const *p;
size_t match_offset;
size_t match_size;
@@ -1046,7 +1051,7 @@ grepbuf (char const *beg, char const *lim)
break;
if (!out_invert)
{
- prtext (b, endp, (int *) 0);
+ prtext (b, endp, NULL);
nlines++;
outleft--;
if (!outleft || done_on_match)
@@ -1079,10 +1084,10 @@ grepbuf (char const *beg, char const *lim)
/* Search a given file. Normally, return a count of lines printed;
but if the file is a directory and we search it recursively, then
return -2 if there was a match, and -1 otherwise. */
-static int
+static intmax_t
grep (int fd, char const *file, struct stats *stats)
{
- int nlines, i;
+ intmax_t nlines, i;
int not_text;
size_t residue, save;
char oldc;
@@ -1212,7 +1217,7 @@ static int
grepfile (char const *file, struct stats *stats)
{
int desc;
- int count;
+ intmax_t count;
int status;
filename = (file ? file : label ? label : _("(standard input)"));
@@ -1319,7 +1324,7 @@ grepfile (char const *file, struct stats *stats)
else
fputc (0, stdout);
}
- printf ("%d\n", count);
+ printf ("%" PRIdMAX "\n", count);
}
status = !count;
@@ -1590,12 +1595,12 @@ setmatcher (char const *m)
etc. to the option copies. Return the number N of options found.
Do not set ARGV[N] to NULL. If ARGV is NULL, do not store ARGV[0]
etc. Backslash can be used to escape whitespace (and backslashes). */
-static int
+static size_t
prepend_args (char const *options, char *buf, char **argv)
{
char const *o = options;
char *b = buf;
- int n = 0;
+ size_t n = 0;
for (;;)
{
@@ -1625,10 +1630,14 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
if (options && *options)
{
char *buf = xmalloc (strlen (options) + 1);
- int prepended = prepend_args (options, buf, (char **) NULL);
+ size_t prepended = prepend_args (options, buf, NULL);
int argc = *pargc;
char *const *argv = *pargv;
- char **pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
+ char **pp;
+ enum { MAX_ARGS = MIN (INT_MAX, SIZE_MAX / sizeof *pp - 1) };
+ if (MAX_ARGS - argc < prepended)
+ xalloc_die ();
+ pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
*pargc = prepended + argc;
*pargv = pp;
*pp++ = *argv++;
@@ -1646,11 +1655,11 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
Process any digit options that were encountered on the way,
and store the resulting integer into *DEFAULT_CONTEXT. */
static int
-get_nondigit_option (int argc, char *const *argv, int *default_context)
+get_nondigit_option (int argc, char *const *argv, intmax_t *default_context)
{
static int prev_digit_optind = -1;
int opt, this_digit_optind, was_digit;
- char buf[sizeof (uintmax_t) * CHAR_BIT + 4];
+ char buf[INT_BUFSIZE_BOUND (intmax_t) + 4];
char *p = buf;
was_digit = 0;
@@ -1760,11 +1769,11 @@ main (int argc, char **argv)
char *keys;
size_t keycc, oldcc, keyalloc;
int with_filenames;
- int opt, cc, status, prepended;
+ size_t cc;
+ int opt, status, prepended;
int prev_optind, last_recursive;
- int default_context;
+ intmax_t default_context;
FILE *fp;
-
exit_failure = EXIT_TROUBLE;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -1776,7 +1785,7 @@ main (int argc, char **argv)
eolbyte = '\n';
filename_mask = ~0;
- max_count = TYPE_MAXIMUM (off_t);
+ max_count = INTMAX_MAX;
/* The value -1 means to use DEFAULT_CONTEXT. */
out_after = out_before = -1;
@@ -1947,23 +1956,15 @@ main (int argc, char **argv)
break;
case 'm':
- {
- uintmax_t value;
- switch (xstrtoumax (optarg, 0, 10, &value, ""))
- {
- case LONGINT_OK:
- max_count = value;
- if (0 <= max_count && max_count == value)
- break;
- /* Fall through. */
- case LONGINT_OVERFLOW:
- max_count = TYPE_MAXIMUM (off_t);
- break;
+ switch (xstrtoimax (optarg, 0, 10, &max_count, ""))
+ {
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ break;
- default:
- error (EXIT_TROUBLE, 0, _("invalid max count"));
- }
- }
+ default:
+ error (EXIT_TROUBLE, 0, _("invalid max count"));
+ }
break;
case 'n':
|
CWE-189
| null | null |
5,187
|
color_cap_rv_fct (void)
{
/* By this point, it was 1 (or already -1). */
color_option = -1; /* That's still != 0. */
}
|
Exec Code Overflow
| 0
|
color_cap_rv_fct (void)
{
/* By this point, it was 1 (or already -1). */
color_option = -1; /* That's still != 0. */
}
|
@@ -25,6 +25,7 @@
#include <wchar.h>
#include <wctype.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include "system.h"
@@ -425,17 +426,21 @@ clean_up_stdout (void)
close_stdout ();
}
-/* Convert STR to a positive integer, storing the result in *OUT.
+/* Convert STR to a nonnegative integer, storing the result in *OUT.
STR must be a valid context length argument; report an error if it
- isn't. */
+ isn't. Silently ceiling *OUT at the maximum value, as that is
+ practically equivalent to infinity for grep's purposes. */
static void
-context_length_arg (char const *str, int *out)
+context_length_arg (char const *str, intmax_t *out)
{
- uintmax_t value;
- if (! (xstrtoumax (str, 0, 10, &value, "") == LONGINT_OK
- && 0 <= (*out = value)
- && *out == value))
+ switch (xstrtoimax (str, 0, 10, out, ""))
{
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ if (0 <= *out)
+ break;
+ /* Fall through. */
+ default:
error (EXIT_TROUBLE, 0, "%s: %s", str,
_("invalid context length argument"));
}
@@ -603,12 +608,12 @@ static int out_invert; /* Print nonmatching stuff. */
static int out_file; /* Print filenames. */
static int out_line; /* Print line numbers. */
static int out_byte; /* Print byte offsets. */
-static int out_before; /* Lines of leading context. */
-static int out_after; /* Lines of trailing context. */
+static intmax_t out_before; /* Lines of leading context. */
+static intmax_t out_after; /* Lines of trailing context. */
static int count_matches; /* Count matching lines. */
static int list_files; /* List matching files. */
static int no_filenames; /* Suppress file names. */
-static off_t max_count; /* Stop after outputting this many
+static intmax_t max_count; /* Stop after outputting this many
lines from an input file. */
static int line_buffered; /* If nonzero, use line buffering, i.e.
fflush everyline out. */
@@ -622,8 +627,8 @@ static char const *lastout; /* Pointer after last character output;
NULL if no character has been output
or if it's conceptually before bufbeg. */
static uintmax_t totalnl; /* Total newline count before lastnl. */
-static off_t outleft; /* Maximum number of lines to be output. */
-static int pending; /* Pending lines of output.
+static intmax_t outleft; /* Maximum number of lines to be output. */
+static intmax_t pending; /* Pending lines of output.
Always kept 0 if out_quiet is true. */
static int done_on_match; /* Stop scanning file on first match. */
static int exit_on_match; /* Exit on first match. */
@@ -917,12 +922,12 @@ prpending (char const *lim)
/* Print the lines between BEG and LIM. Deal with context crap.
If NLINESP is non-null, store a count of lines between BEG and LIM. */
static void
-prtext (char const *beg, char const *lim, int *nlinesp)
+prtext (char const *beg, char const *lim, intmax_t *nlinesp)
{
static int used; /* avoid printing SEP_STR_GROUP before any output */
char const *bp, *p;
char eol = eolbyte;
- int i, n;
+ intmax_t i, n;
if (!out_quiet && pending > 0)
prpending (beg);
@@ -1026,10 +1031,10 @@ do_execute (char const *buf, size_t size, size_t *match_size, char const *start_
/* Scan the specified portion of the buffer, matching lines (or
between matching lines if OUT_INVERT is true). Return a count of
lines printed. */
-static int
+static intmax_t
grepbuf (char const *beg, char const *lim)
{
- int nlines, n;
+ intmax_t nlines, n;
char const *p;
size_t match_offset;
size_t match_size;
@@ -1046,7 +1051,7 @@ grepbuf (char const *beg, char const *lim)
break;
if (!out_invert)
{
- prtext (b, endp, (int *) 0);
+ prtext (b, endp, NULL);
nlines++;
outleft--;
if (!outleft || done_on_match)
@@ -1079,10 +1084,10 @@ grepbuf (char const *beg, char const *lim)
/* Search a given file. Normally, return a count of lines printed;
but if the file is a directory and we search it recursively, then
return -2 if there was a match, and -1 otherwise. */
-static int
+static intmax_t
grep (int fd, char const *file, struct stats *stats)
{
- int nlines, i;
+ intmax_t nlines, i;
int not_text;
size_t residue, save;
char oldc;
@@ -1212,7 +1217,7 @@ static int
grepfile (char const *file, struct stats *stats)
{
int desc;
- int count;
+ intmax_t count;
int status;
filename = (file ? file : label ? label : _("(standard input)"));
@@ -1319,7 +1324,7 @@ grepfile (char const *file, struct stats *stats)
else
fputc (0, stdout);
}
- printf ("%d\n", count);
+ printf ("%" PRIdMAX "\n", count);
}
status = !count;
@@ -1590,12 +1595,12 @@ setmatcher (char const *m)
etc. to the option copies. Return the number N of options found.
Do not set ARGV[N] to NULL. If ARGV is NULL, do not store ARGV[0]
etc. Backslash can be used to escape whitespace (and backslashes). */
-static int
+static size_t
prepend_args (char const *options, char *buf, char **argv)
{
char const *o = options;
char *b = buf;
- int n = 0;
+ size_t n = 0;
for (;;)
{
@@ -1625,10 +1630,14 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
if (options && *options)
{
char *buf = xmalloc (strlen (options) + 1);
- int prepended = prepend_args (options, buf, (char **) NULL);
+ size_t prepended = prepend_args (options, buf, NULL);
int argc = *pargc;
char *const *argv = *pargv;
- char **pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
+ char **pp;
+ enum { MAX_ARGS = MIN (INT_MAX, SIZE_MAX / sizeof *pp - 1) };
+ if (MAX_ARGS - argc < prepended)
+ xalloc_die ();
+ pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
*pargc = prepended + argc;
*pargv = pp;
*pp++ = *argv++;
@@ -1646,11 +1655,11 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
Process any digit options that were encountered on the way,
and store the resulting integer into *DEFAULT_CONTEXT. */
static int
-get_nondigit_option (int argc, char *const *argv, int *default_context)
+get_nondigit_option (int argc, char *const *argv, intmax_t *default_context)
{
static int prev_digit_optind = -1;
int opt, this_digit_optind, was_digit;
- char buf[sizeof (uintmax_t) * CHAR_BIT + 4];
+ char buf[INT_BUFSIZE_BOUND (intmax_t) + 4];
char *p = buf;
was_digit = 0;
@@ -1760,11 +1769,11 @@ main (int argc, char **argv)
char *keys;
size_t keycc, oldcc, keyalloc;
int with_filenames;
- int opt, cc, status, prepended;
+ size_t cc;
+ int opt, status, prepended;
int prev_optind, last_recursive;
- int default_context;
+ intmax_t default_context;
FILE *fp;
-
exit_failure = EXIT_TROUBLE;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -1776,7 +1785,7 @@ main (int argc, char **argv)
eolbyte = '\n';
filename_mask = ~0;
- max_count = TYPE_MAXIMUM (off_t);
+ max_count = INTMAX_MAX;
/* The value -1 means to use DEFAULT_CONTEXT. */
out_after = out_before = -1;
@@ -1947,23 +1956,15 @@ main (int argc, char **argv)
break;
case 'm':
- {
- uintmax_t value;
- switch (xstrtoumax (optarg, 0, 10, &value, ""))
- {
- case LONGINT_OK:
- max_count = value;
- if (0 <= max_count && max_count == value)
- break;
- /* Fall through. */
- case LONGINT_OVERFLOW:
- max_count = TYPE_MAXIMUM (off_t);
- break;
+ switch (xstrtoimax (optarg, 0, 10, &max_count, ""))
+ {
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ break;
- default:
- error (EXIT_TROUBLE, 0, _("invalid max count"));
- }
- }
+ default:
+ error (EXIT_TROUBLE, 0, _("invalid max count"));
+ }
break;
case 'n':
|
CWE-189
| null | null |
5,188
|
pr_sgr_end (char const *s)
{
if (*s)
print_end_colorize (sgr_end);
}
|
Exec Code Overflow
| 0
|
pr_sgr_end (char const *s)
{
if (*s)
print_end_colorize (sgr_end);
}
|
@@ -25,6 +25,7 @@
#include <wchar.h>
#include <wctype.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include "system.h"
@@ -425,17 +426,21 @@ clean_up_stdout (void)
close_stdout ();
}
-/* Convert STR to a positive integer, storing the result in *OUT.
+/* Convert STR to a nonnegative integer, storing the result in *OUT.
STR must be a valid context length argument; report an error if it
- isn't. */
+ isn't. Silently ceiling *OUT at the maximum value, as that is
+ practically equivalent to infinity for grep's purposes. */
static void
-context_length_arg (char const *str, int *out)
+context_length_arg (char const *str, intmax_t *out)
{
- uintmax_t value;
- if (! (xstrtoumax (str, 0, 10, &value, "") == LONGINT_OK
- && 0 <= (*out = value)
- && *out == value))
+ switch (xstrtoimax (str, 0, 10, out, ""))
{
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ if (0 <= *out)
+ break;
+ /* Fall through. */
+ default:
error (EXIT_TROUBLE, 0, "%s: %s", str,
_("invalid context length argument"));
}
@@ -603,12 +608,12 @@ static int out_invert; /* Print nonmatching stuff. */
static int out_file; /* Print filenames. */
static int out_line; /* Print line numbers. */
static int out_byte; /* Print byte offsets. */
-static int out_before; /* Lines of leading context. */
-static int out_after; /* Lines of trailing context. */
+static intmax_t out_before; /* Lines of leading context. */
+static intmax_t out_after; /* Lines of trailing context. */
static int count_matches; /* Count matching lines. */
static int list_files; /* List matching files. */
static int no_filenames; /* Suppress file names. */
-static off_t max_count; /* Stop after outputting this many
+static intmax_t max_count; /* Stop after outputting this many
lines from an input file. */
static int line_buffered; /* If nonzero, use line buffering, i.e.
fflush everyline out. */
@@ -622,8 +627,8 @@ static char const *lastout; /* Pointer after last character output;
NULL if no character has been output
or if it's conceptually before bufbeg. */
static uintmax_t totalnl; /* Total newline count before lastnl. */
-static off_t outleft; /* Maximum number of lines to be output. */
-static int pending; /* Pending lines of output.
+static intmax_t outleft; /* Maximum number of lines to be output. */
+static intmax_t pending; /* Pending lines of output.
Always kept 0 if out_quiet is true. */
static int done_on_match; /* Stop scanning file on first match. */
static int exit_on_match; /* Exit on first match. */
@@ -917,12 +922,12 @@ prpending (char const *lim)
/* Print the lines between BEG and LIM. Deal with context crap.
If NLINESP is non-null, store a count of lines between BEG and LIM. */
static void
-prtext (char const *beg, char const *lim, int *nlinesp)
+prtext (char const *beg, char const *lim, intmax_t *nlinesp)
{
static int used; /* avoid printing SEP_STR_GROUP before any output */
char const *bp, *p;
char eol = eolbyte;
- int i, n;
+ intmax_t i, n;
if (!out_quiet && pending > 0)
prpending (beg);
@@ -1026,10 +1031,10 @@ do_execute (char const *buf, size_t size, size_t *match_size, char const *start_
/* Scan the specified portion of the buffer, matching lines (or
between matching lines if OUT_INVERT is true). Return a count of
lines printed. */
-static int
+static intmax_t
grepbuf (char const *beg, char const *lim)
{
- int nlines, n;
+ intmax_t nlines, n;
char const *p;
size_t match_offset;
size_t match_size;
@@ -1046,7 +1051,7 @@ grepbuf (char const *beg, char const *lim)
break;
if (!out_invert)
{
- prtext (b, endp, (int *) 0);
+ prtext (b, endp, NULL);
nlines++;
outleft--;
if (!outleft || done_on_match)
@@ -1079,10 +1084,10 @@ grepbuf (char const *beg, char const *lim)
/* Search a given file. Normally, return a count of lines printed;
but if the file is a directory and we search it recursively, then
return -2 if there was a match, and -1 otherwise. */
-static int
+static intmax_t
grep (int fd, char const *file, struct stats *stats)
{
- int nlines, i;
+ intmax_t nlines, i;
int not_text;
size_t residue, save;
char oldc;
@@ -1212,7 +1217,7 @@ static int
grepfile (char const *file, struct stats *stats)
{
int desc;
- int count;
+ intmax_t count;
int status;
filename = (file ? file : label ? label : _("(standard input)"));
@@ -1319,7 +1324,7 @@ grepfile (char const *file, struct stats *stats)
else
fputc (0, stdout);
}
- printf ("%d\n", count);
+ printf ("%" PRIdMAX "\n", count);
}
status = !count;
@@ -1590,12 +1595,12 @@ setmatcher (char const *m)
etc. to the option copies. Return the number N of options found.
Do not set ARGV[N] to NULL. If ARGV is NULL, do not store ARGV[0]
etc. Backslash can be used to escape whitespace (and backslashes). */
-static int
+static size_t
prepend_args (char const *options, char *buf, char **argv)
{
char const *o = options;
char *b = buf;
- int n = 0;
+ size_t n = 0;
for (;;)
{
@@ -1625,10 +1630,14 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
if (options && *options)
{
char *buf = xmalloc (strlen (options) + 1);
- int prepended = prepend_args (options, buf, (char **) NULL);
+ size_t prepended = prepend_args (options, buf, NULL);
int argc = *pargc;
char *const *argv = *pargv;
- char **pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
+ char **pp;
+ enum { MAX_ARGS = MIN (INT_MAX, SIZE_MAX / sizeof *pp - 1) };
+ if (MAX_ARGS - argc < prepended)
+ xalloc_die ();
+ pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
*pargc = prepended + argc;
*pargv = pp;
*pp++ = *argv++;
@@ -1646,11 +1655,11 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
Process any digit options that were encountered on the way,
and store the resulting integer into *DEFAULT_CONTEXT. */
static int
-get_nondigit_option (int argc, char *const *argv, int *default_context)
+get_nondigit_option (int argc, char *const *argv, intmax_t *default_context)
{
static int prev_digit_optind = -1;
int opt, this_digit_optind, was_digit;
- char buf[sizeof (uintmax_t) * CHAR_BIT + 4];
+ char buf[INT_BUFSIZE_BOUND (intmax_t) + 4];
char *p = buf;
was_digit = 0;
@@ -1760,11 +1769,11 @@ main (int argc, char **argv)
char *keys;
size_t keycc, oldcc, keyalloc;
int with_filenames;
- int opt, cc, status, prepended;
+ size_t cc;
+ int opt, status, prepended;
int prev_optind, last_recursive;
- int default_context;
+ intmax_t default_context;
FILE *fp;
-
exit_failure = EXIT_TROUBLE;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -1776,7 +1785,7 @@ main (int argc, char **argv)
eolbyte = '\n';
filename_mask = ~0;
- max_count = TYPE_MAXIMUM (off_t);
+ max_count = INTMAX_MAX;
/* The value -1 means to use DEFAULT_CONTEXT. */
out_after = out_before = -1;
@@ -1947,23 +1956,15 @@ main (int argc, char **argv)
break;
case 'm':
- {
- uintmax_t value;
- switch (xstrtoumax (optarg, 0, 10, &value, ""))
- {
- case LONGINT_OK:
- max_count = value;
- if (0 <= max_count && max_count == value)
- break;
- /* Fall through. */
- case LONGINT_OVERFLOW:
- max_count = TYPE_MAXIMUM (off_t);
- break;
+ switch (xstrtoimax (optarg, 0, 10, &max_count, ""))
+ {
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ break;
- default:
- error (EXIT_TROUBLE, 0, _("invalid max count"));
- }
- }
+ default:
+ error (EXIT_TROUBLE, 0, _("invalid max count"));
+ }
break;
case 'n':
|
CWE-189
| null | null |
5,189
|
pr_sgr_end_if (char const *s)
{
if (color_option)
pr_sgr_end (s);
}
|
Exec Code Overflow
| 0
|
pr_sgr_end_if (char const *s)
{
if (color_option)
pr_sgr_end (s);
}
|
@@ -25,6 +25,7 @@
#include <wchar.h>
#include <wctype.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include "system.h"
@@ -425,17 +426,21 @@ clean_up_stdout (void)
close_stdout ();
}
-/* Convert STR to a positive integer, storing the result in *OUT.
+/* Convert STR to a nonnegative integer, storing the result in *OUT.
STR must be a valid context length argument; report an error if it
- isn't. */
+ isn't. Silently ceiling *OUT at the maximum value, as that is
+ practically equivalent to infinity for grep's purposes. */
static void
-context_length_arg (char const *str, int *out)
+context_length_arg (char const *str, intmax_t *out)
{
- uintmax_t value;
- if (! (xstrtoumax (str, 0, 10, &value, "") == LONGINT_OK
- && 0 <= (*out = value)
- && *out == value))
+ switch (xstrtoimax (str, 0, 10, out, ""))
{
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ if (0 <= *out)
+ break;
+ /* Fall through. */
+ default:
error (EXIT_TROUBLE, 0, "%s: %s", str,
_("invalid context length argument"));
}
@@ -603,12 +608,12 @@ static int out_invert; /* Print nonmatching stuff. */
static int out_file; /* Print filenames. */
static int out_line; /* Print line numbers. */
static int out_byte; /* Print byte offsets. */
-static int out_before; /* Lines of leading context. */
-static int out_after; /* Lines of trailing context. */
+static intmax_t out_before; /* Lines of leading context. */
+static intmax_t out_after; /* Lines of trailing context. */
static int count_matches; /* Count matching lines. */
static int list_files; /* List matching files. */
static int no_filenames; /* Suppress file names. */
-static off_t max_count; /* Stop after outputting this many
+static intmax_t max_count; /* Stop after outputting this many
lines from an input file. */
static int line_buffered; /* If nonzero, use line buffering, i.e.
fflush everyline out. */
@@ -622,8 +627,8 @@ static char const *lastout; /* Pointer after last character output;
NULL if no character has been output
or if it's conceptually before bufbeg. */
static uintmax_t totalnl; /* Total newline count before lastnl. */
-static off_t outleft; /* Maximum number of lines to be output. */
-static int pending; /* Pending lines of output.
+static intmax_t outleft; /* Maximum number of lines to be output. */
+static intmax_t pending; /* Pending lines of output.
Always kept 0 if out_quiet is true. */
static int done_on_match; /* Stop scanning file on first match. */
static int exit_on_match; /* Exit on first match. */
@@ -917,12 +922,12 @@ prpending (char const *lim)
/* Print the lines between BEG and LIM. Deal with context crap.
If NLINESP is non-null, store a count of lines between BEG and LIM. */
static void
-prtext (char const *beg, char const *lim, int *nlinesp)
+prtext (char const *beg, char const *lim, intmax_t *nlinesp)
{
static int used; /* avoid printing SEP_STR_GROUP before any output */
char const *bp, *p;
char eol = eolbyte;
- int i, n;
+ intmax_t i, n;
if (!out_quiet && pending > 0)
prpending (beg);
@@ -1026,10 +1031,10 @@ do_execute (char const *buf, size_t size, size_t *match_size, char const *start_
/* Scan the specified portion of the buffer, matching lines (or
between matching lines if OUT_INVERT is true). Return a count of
lines printed. */
-static int
+static intmax_t
grepbuf (char const *beg, char const *lim)
{
- int nlines, n;
+ intmax_t nlines, n;
char const *p;
size_t match_offset;
size_t match_size;
@@ -1046,7 +1051,7 @@ grepbuf (char const *beg, char const *lim)
break;
if (!out_invert)
{
- prtext (b, endp, (int *) 0);
+ prtext (b, endp, NULL);
nlines++;
outleft--;
if (!outleft || done_on_match)
@@ -1079,10 +1084,10 @@ grepbuf (char const *beg, char const *lim)
/* Search a given file. Normally, return a count of lines printed;
but if the file is a directory and we search it recursively, then
return -2 if there was a match, and -1 otherwise. */
-static int
+static intmax_t
grep (int fd, char const *file, struct stats *stats)
{
- int nlines, i;
+ intmax_t nlines, i;
int not_text;
size_t residue, save;
char oldc;
@@ -1212,7 +1217,7 @@ static int
grepfile (char const *file, struct stats *stats)
{
int desc;
- int count;
+ intmax_t count;
int status;
filename = (file ? file : label ? label : _("(standard input)"));
@@ -1319,7 +1324,7 @@ grepfile (char const *file, struct stats *stats)
else
fputc (0, stdout);
}
- printf ("%d\n", count);
+ printf ("%" PRIdMAX "\n", count);
}
status = !count;
@@ -1590,12 +1595,12 @@ setmatcher (char const *m)
etc. to the option copies. Return the number N of options found.
Do not set ARGV[N] to NULL. If ARGV is NULL, do not store ARGV[0]
etc. Backslash can be used to escape whitespace (and backslashes). */
-static int
+static size_t
prepend_args (char const *options, char *buf, char **argv)
{
char const *o = options;
char *b = buf;
- int n = 0;
+ size_t n = 0;
for (;;)
{
@@ -1625,10 +1630,14 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
if (options && *options)
{
char *buf = xmalloc (strlen (options) + 1);
- int prepended = prepend_args (options, buf, (char **) NULL);
+ size_t prepended = prepend_args (options, buf, NULL);
int argc = *pargc;
char *const *argv = *pargv;
- char **pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
+ char **pp;
+ enum { MAX_ARGS = MIN (INT_MAX, SIZE_MAX / sizeof *pp - 1) };
+ if (MAX_ARGS - argc < prepended)
+ xalloc_die ();
+ pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
*pargc = prepended + argc;
*pargv = pp;
*pp++ = *argv++;
@@ -1646,11 +1655,11 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
Process any digit options that were encountered on the way,
and store the resulting integer into *DEFAULT_CONTEXT. */
static int
-get_nondigit_option (int argc, char *const *argv, int *default_context)
+get_nondigit_option (int argc, char *const *argv, intmax_t *default_context)
{
static int prev_digit_optind = -1;
int opt, this_digit_optind, was_digit;
- char buf[sizeof (uintmax_t) * CHAR_BIT + 4];
+ char buf[INT_BUFSIZE_BOUND (intmax_t) + 4];
char *p = buf;
was_digit = 0;
@@ -1760,11 +1769,11 @@ main (int argc, char **argv)
char *keys;
size_t keycc, oldcc, keyalloc;
int with_filenames;
- int opt, cc, status, prepended;
+ size_t cc;
+ int opt, status, prepended;
int prev_optind, last_recursive;
- int default_context;
+ intmax_t default_context;
FILE *fp;
-
exit_failure = EXIT_TROUBLE;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -1776,7 +1785,7 @@ main (int argc, char **argv)
eolbyte = '\n';
filename_mask = ~0;
- max_count = TYPE_MAXIMUM (off_t);
+ max_count = INTMAX_MAX;
/* The value -1 means to use DEFAULT_CONTEXT. */
out_after = out_before = -1;
@@ -1947,23 +1956,15 @@ main (int argc, char **argv)
break;
case 'm':
- {
- uintmax_t value;
- switch (xstrtoumax (optarg, 0, 10, &value, ""))
- {
- case LONGINT_OK:
- max_count = value;
- if (0 <= max_count && max_count == value)
- break;
- /* Fall through. */
- case LONGINT_OVERFLOW:
- max_count = TYPE_MAXIMUM (off_t);
- break;
+ switch (xstrtoimax (optarg, 0, 10, &max_count, ""))
+ {
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ break;
- default:
- error (EXIT_TROUBLE, 0, _("invalid max count"));
- }
- }
+ default:
+ error (EXIT_TROUBLE, 0, _("invalid max count"));
+ }
break;
case 'n':
|
CWE-189
| null | null |
5,190
|
pr_sgr_start (char const *s)
{
if (*s)
print_start_colorize (sgr_start, s);
}
|
Exec Code Overflow
| 0
|
pr_sgr_start (char const *s)
{
if (*s)
print_start_colorize (sgr_start, s);
}
|
@@ -25,6 +25,7 @@
#include <wchar.h>
#include <wctype.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include "system.h"
@@ -425,17 +426,21 @@ clean_up_stdout (void)
close_stdout ();
}
-/* Convert STR to a positive integer, storing the result in *OUT.
+/* Convert STR to a nonnegative integer, storing the result in *OUT.
STR must be a valid context length argument; report an error if it
- isn't. */
+ isn't. Silently ceiling *OUT at the maximum value, as that is
+ practically equivalent to infinity for grep's purposes. */
static void
-context_length_arg (char const *str, int *out)
+context_length_arg (char const *str, intmax_t *out)
{
- uintmax_t value;
- if (! (xstrtoumax (str, 0, 10, &value, "") == LONGINT_OK
- && 0 <= (*out = value)
- && *out == value))
+ switch (xstrtoimax (str, 0, 10, out, ""))
{
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ if (0 <= *out)
+ break;
+ /* Fall through. */
+ default:
error (EXIT_TROUBLE, 0, "%s: %s", str,
_("invalid context length argument"));
}
@@ -603,12 +608,12 @@ static int out_invert; /* Print nonmatching stuff. */
static int out_file; /* Print filenames. */
static int out_line; /* Print line numbers. */
static int out_byte; /* Print byte offsets. */
-static int out_before; /* Lines of leading context. */
-static int out_after; /* Lines of trailing context. */
+static intmax_t out_before; /* Lines of leading context. */
+static intmax_t out_after; /* Lines of trailing context. */
static int count_matches; /* Count matching lines. */
static int list_files; /* List matching files. */
static int no_filenames; /* Suppress file names. */
-static off_t max_count; /* Stop after outputting this many
+static intmax_t max_count; /* Stop after outputting this many
lines from an input file. */
static int line_buffered; /* If nonzero, use line buffering, i.e.
fflush everyline out. */
@@ -622,8 +627,8 @@ static char const *lastout; /* Pointer after last character output;
NULL if no character has been output
or if it's conceptually before bufbeg. */
static uintmax_t totalnl; /* Total newline count before lastnl. */
-static off_t outleft; /* Maximum number of lines to be output. */
-static int pending; /* Pending lines of output.
+static intmax_t outleft; /* Maximum number of lines to be output. */
+static intmax_t pending; /* Pending lines of output.
Always kept 0 if out_quiet is true. */
static int done_on_match; /* Stop scanning file on first match. */
static int exit_on_match; /* Exit on first match. */
@@ -917,12 +922,12 @@ prpending (char const *lim)
/* Print the lines between BEG and LIM. Deal with context crap.
If NLINESP is non-null, store a count of lines between BEG and LIM. */
static void
-prtext (char const *beg, char const *lim, int *nlinesp)
+prtext (char const *beg, char const *lim, intmax_t *nlinesp)
{
static int used; /* avoid printing SEP_STR_GROUP before any output */
char const *bp, *p;
char eol = eolbyte;
- int i, n;
+ intmax_t i, n;
if (!out_quiet && pending > 0)
prpending (beg);
@@ -1026,10 +1031,10 @@ do_execute (char const *buf, size_t size, size_t *match_size, char const *start_
/* Scan the specified portion of the buffer, matching lines (or
between matching lines if OUT_INVERT is true). Return a count of
lines printed. */
-static int
+static intmax_t
grepbuf (char const *beg, char const *lim)
{
- int nlines, n;
+ intmax_t nlines, n;
char const *p;
size_t match_offset;
size_t match_size;
@@ -1046,7 +1051,7 @@ grepbuf (char const *beg, char const *lim)
break;
if (!out_invert)
{
- prtext (b, endp, (int *) 0);
+ prtext (b, endp, NULL);
nlines++;
outleft--;
if (!outleft || done_on_match)
@@ -1079,10 +1084,10 @@ grepbuf (char const *beg, char const *lim)
/* Search a given file. Normally, return a count of lines printed;
but if the file is a directory and we search it recursively, then
return -2 if there was a match, and -1 otherwise. */
-static int
+static intmax_t
grep (int fd, char const *file, struct stats *stats)
{
- int nlines, i;
+ intmax_t nlines, i;
int not_text;
size_t residue, save;
char oldc;
@@ -1212,7 +1217,7 @@ static int
grepfile (char const *file, struct stats *stats)
{
int desc;
- int count;
+ intmax_t count;
int status;
filename = (file ? file : label ? label : _("(standard input)"));
@@ -1319,7 +1324,7 @@ grepfile (char const *file, struct stats *stats)
else
fputc (0, stdout);
}
- printf ("%d\n", count);
+ printf ("%" PRIdMAX "\n", count);
}
status = !count;
@@ -1590,12 +1595,12 @@ setmatcher (char const *m)
etc. to the option copies. Return the number N of options found.
Do not set ARGV[N] to NULL. If ARGV is NULL, do not store ARGV[0]
etc. Backslash can be used to escape whitespace (and backslashes). */
-static int
+static size_t
prepend_args (char const *options, char *buf, char **argv)
{
char const *o = options;
char *b = buf;
- int n = 0;
+ size_t n = 0;
for (;;)
{
@@ -1625,10 +1630,14 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
if (options && *options)
{
char *buf = xmalloc (strlen (options) + 1);
- int prepended = prepend_args (options, buf, (char **) NULL);
+ size_t prepended = prepend_args (options, buf, NULL);
int argc = *pargc;
char *const *argv = *pargv;
- char **pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
+ char **pp;
+ enum { MAX_ARGS = MIN (INT_MAX, SIZE_MAX / sizeof *pp - 1) };
+ if (MAX_ARGS - argc < prepended)
+ xalloc_die ();
+ pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
*pargc = prepended + argc;
*pargv = pp;
*pp++ = *argv++;
@@ -1646,11 +1655,11 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
Process any digit options that were encountered on the way,
and store the resulting integer into *DEFAULT_CONTEXT. */
static int
-get_nondigit_option (int argc, char *const *argv, int *default_context)
+get_nondigit_option (int argc, char *const *argv, intmax_t *default_context)
{
static int prev_digit_optind = -1;
int opt, this_digit_optind, was_digit;
- char buf[sizeof (uintmax_t) * CHAR_BIT + 4];
+ char buf[INT_BUFSIZE_BOUND (intmax_t) + 4];
char *p = buf;
was_digit = 0;
@@ -1760,11 +1769,11 @@ main (int argc, char **argv)
char *keys;
size_t keycc, oldcc, keyalloc;
int with_filenames;
- int opt, cc, status, prepended;
+ size_t cc;
+ int opt, status, prepended;
int prev_optind, last_recursive;
- int default_context;
+ intmax_t default_context;
FILE *fp;
-
exit_failure = EXIT_TROUBLE;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -1776,7 +1785,7 @@ main (int argc, char **argv)
eolbyte = '\n';
filename_mask = ~0;
- max_count = TYPE_MAXIMUM (off_t);
+ max_count = INTMAX_MAX;
/* The value -1 means to use DEFAULT_CONTEXT. */
out_after = out_before = -1;
@@ -1947,23 +1956,15 @@ main (int argc, char **argv)
break;
case 'm':
- {
- uintmax_t value;
- switch (xstrtoumax (optarg, 0, 10, &value, ""))
- {
- case LONGINT_OK:
- max_count = value;
- if (0 <= max_count && max_count == value)
- break;
- /* Fall through. */
- case LONGINT_OVERFLOW:
- max_count = TYPE_MAXIMUM (off_t);
- break;
+ switch (xstrtoimax (optarg, 0, 10, &max_count, ""))
+ {
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ break;
- default:
- error (EXIT_TROUBLE, 0, _("invalid max count"));
- }
- }
+ default:
+ error (EXIT_TROUBLE, 0, _("invalid max count"));
+ }
break;
case 'n':
|
CWE-189
| null | null |
5,191
|
suppressible_error (char const *mesg, int errnum)
{
if (! suppress_errors)
error (0, errnum, "%s", mesg);
errseen = 1;
}
|
Exec Code Overflow
| 0
|
suppressible_error (char const *mesg, int errnum)
{
if (! suppress_errors)
error (0, errnum, "%s", mesg);
errseen = 1;
}
|
@@ -25,6 +25,7 @@
#include <wchar.h>
#include <wctype.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include "system.h"
@@ -425,17 +426,21 @@ clean_up_stdout (void)
close_stdout ();
}
-/* Convert STR to a positive integer, storing the result in *OUT.
+/* Convert STR to a nonnegative integer, storing the result in *OUT.
STR must be a valid context length argument; report an error if it
- isn't. */
+ isn't. Silently ceiling *OUT at the maximum value, as that is
+ practically equivalent to infinity for grep's purposes. */
static void
-context_length_arg (char const *str, int *out)
+context_length_arg (char const *str, intmax_t *out)
{
- uintmax_t value;
- if (! (xstrtoumax (str, 0, 10, &value, "") == LONGINT_OK
- && 0 <= (*out = value)
- && *out == value))
+ switch (xstrtoimax (str, 0, 10, out, ""))
{
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ if (0 <= *out)
+ break;
+ /* Fall through. */
+ default:
error (EXIT_TROUBLE, 0, "%s: %s", str,
_("invalid context length argument"));
}
@@ -603,12 +608,12 @@ static int out_invert; /* Print nonmatching stuff. */
static int out_file; /* Print filenames. */
static int out_line; /* Print line numbers. */
static int out_byte; /* Print byte offsets. */
-static int out_before; /* Lines of leading context. */
-static int out_after; /* Lines of trailing context. */
+static intmax_t out_before; /* Lines of leading context. */
+static intmax_t out_after; /* Lines of trailing context. */
static int count_matches; /* Count matching lines. */
static int list_files; /* List matching files. */
static int no_filenames; /* Suppress file names. */
-static off_t max_count; /* Stop after outputting this many
+static intmax_t max_count; /* Stop after outputting this many
lines from an input file. */
static int line_buffered; /* If nonzero, use line buffering, i.e.
fflush everyline out. */
@@ -622,8 +627,8 @@ static char const *lastout; /* Pointer after last character output;
NULL if no character has been output
or if it's conceptually before bufbeg. */
static uintmax_t totalnl; /* Total newline count before lastnl. */
-static off_t outleft; /* Maximum number of lines to be output. */
-static int pending; /* Pending lines of output.
+static intmax_t outleft; /* Maximum number of lines to be output. */
+static intmax_t pending; /* Pending lines of output.
Always kept 0 if out_quiet is true. */
static int done_on_match; /* Stop scanning file on first match. */
static int exit_on_match; /* Exit on first match. */
@@ -917,12 +922,12 @@ prpending (char const *lim)
/* Print the lines between BEG and LIM. Deal with context crap.
If NLINESP is non-null, store a count of lines between BEG and LIM. */
static void
-prtext (char const *beg, char const *lim, int *nlinesp)
+prtext (char const *beg, char const *lim, intmax_t *nlinesp)
{
static int used; /* avoid printing SEP_STR_GROUP before any output */
char const *bp, *p;
char eol = eolbyte;
- int i, n;
+ intmax_t i, n;
if (!out_quiet && pending > 0)
prpending (beg);
@@ -1026,10 +1031,10 @@ do_execute (char const *buf, size_t size, size_t *match_size, char const *start_
/* Scan the specified portion of the buffer, matching lines (or
between matching lines if OUT_INVERT is true). Return a count of
lines printed. */
-static int
+static intmax_t
grepbuf (char const *beg, char const *lim)
{
- int nlines, n;
+ intmax_t nlines, n;
char const *p;
size_t match_offset;
size_t match_size;
@@ -1046,7 +1051,7 @@ grepbuf (char const *beg, char const *lim)
break;
if (!out_invert)
{
- prtext (b, endp, (int *) 0);
+ prtext (b, endp, NULL);
nlines++;
outleft--;
if (!outleft || done_on_match)
@@ -1079,10 +1084,10 @@ grepbuf (char const *beg, char const *lim)
/* Search a given file. Normally, return a count of lines printed;
but if the file is a directory and we search it recursively, then
return -2 if there was a match, and -1 otherwise. */
-static int
+static intmax_t
grep (int fd, char const *file, struct stats *stats)
{
- int nlines, i;
+ intmax_t nlines, i;
int not_text;
size_t residue, save;
char oldc;
@@ -1212,7 +1217,7 @@ static int
grepfile (char const *file, struct stats *stats)
{
int desc;
- int count;
+ intmax_t count;
int status;
filename = (file ? file : label ? label : _("(standard input)"));
@@ -1319,7 +1324,7 @@ grepfile (char const *file, struct stats *stats)
else
fputc (0, stdout);
}
- printf ("%d\n", count);
+ printf ("%" PRIdMAX "\n", count);
}
status = !count;
@@ -1590,12 +1595,12 @@ setmatcher (char const *m)
etc. to the option copies. Return the number N of options found.
Do not set ARGV[N] to NULL. If ARGV is NULL, do not store ARGV[0]
etc. Backslash can be used to escape whitespace (and backslashes). */
-static int
+static size_t
prepend_args (char const *options, char *buf, char **argv)
{
char const *o = options;
char *b = buf;
- int n = 0;
+ size_t n = 0;
for (;;)
{
@@ -1625,10 +1630,14 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
if (options && *options)
{
char *buf = xmalloc (strlen (options) + 1);
- int prepended = prepend_args (options, buf, (char **) NULL);
+ size_t prepended = prepend_args (options, buf, NULL);
int argc = *pargc;
char *const *argv = *pargv;
- char **pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
+ char **pp;
+ enum { MAX_ARGS = MIN (INT_MAX, SIZE_MAX / sizeof *pp - 1) };
+ if (MAX_ARGS - argc < prepended)
+ xalloc_die ();
+ pp = xmalloc ((prepended + argc + 1) * sizeof *pp);
*pargc = prepended + argc;
*pargv = pp;
*pp++ = *argv++;
@@ -1646,11 +1655,11 @@ prepend_default_options (char const *options, int *pargc, char ***pargv)
Process any digit options that were encountered on the way,
and store the resulting integer into *DEFAULT_CONTEXT. */
static int
-get_nondigit_option (int argc, char *const *argv, int *default_context)
+get_nondigit_option (int argc, char *const *argv, intmax_t *default_context)
{
static int prev_digit_optind = -1;
int opt, this_digit_optind, was_digit;
- char buf[sizeof (uintmax_t) * CHAR_BIT + 4];
+ char buf[INT_BUFSIZE_BOUND (intmax_t) + 4];
char *p = buf;
was_digit = 0;
@@ -1760,11 +1769,11 @@ main (int argc, char **argv)
char *keys;
size_t keycc, oldcc, keyalloc;
int with_filenames;
- int opt, cc, status, prepended;
+ size_t cc;
+ int opt, status, prepended;
int prev_optind, last_recursive;
- int default_context;
+ intmax_t default_context;
FILE *fp;
-
exit_failure = EXIT_TROUBLE;
initialize_main (&argc, &argv);
set_program_name (argv[0]);
@@ -1776,7 +1785,7 @@ main (int argc, char **argv)
eolbyte = '\n';
filename_mask = ~0;
- max_count = TYPE_MAXIMUM (off_t);
+ max_count = INTMAX_MAX;
/* The value -1 means to use DEFAULT_CONTEXT. */
out_after = out_before = -1;
@@ -1947,23 +1956,15 @@ main (int argc, char **argv)
break;
case 'm':
- {
- uintmax_t value;
- switch (xstrtoumax (optarg, 0, 10, &value, ""))
- {
- case LONGINT_OK:
- max_count = value;
- if (0 <= max_count && max_count == value)
- break;
- /* Fall through. */
- case LONGINT_OVERFLOW:
- max_count = TYPE_MAXIMUM (off_t);
- break;
+ switch (xstrtoimax (optarg, 0, 10, &max_count, ""))
+ {
+ case LONGINT_OK:
+ case LONGINT_OVERFLOW:
+ break;
- default:
- error (EXIT_TROUBLE, 0, _("invalid max count"));
- }
- }
+ default:
+ error (EXIT_TROUBLE, 0, _("invalid max count"));
+ }
break;
case 'n':
|
CWE-189
| null | null |
5,192
|
Smb4KGlobal::Smb4KEvent::Smb4KEvent( QEvent::Type type ): QEvent( type )
{
}
|
+Priv
| 0
|
Smb4KGlobal::Smb4KEvent::Smb4KEvent( QEvent::Type type ): QEvent( type )
{
}
|
@@ -2,7 +2,7 @@
smb4kglobal - This is the global namespace for Smb4K.
-------------------
begin : Sa Apr 2 2005
- copyright : (C) 2005-2014 by Alexander Reinholdt
+ copyright : (C) 2005-2017 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
@@ -851,3 +851,66 @@ QStringList Smb4KGlobal::whitelistedMountArguments()
#endif
+const QString Smb4KGlobal::findMountExecutable()
+{
+ QString mount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for (int i = 0; i < paths.size(); ++i)
+ {
+#if defined(Q_OS_LINUX)
+ mount = KGlobal::dirs()->findExe("mount.cifs", paths.at(i));
+#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
+ mount = KGlobal::dirs()->findExe("mount_smbfs", paths.at(i));
+#endif
+
+ if (!mount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return mount;
+}
+
+
+const QString Smb4KGlobal::findUmountExecutable()
+{
+ // Find the umount program.
+ QString umount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for ( int i = 0; i < paths.size(); ++i )
+ {
+ umount = KGlobal::dirs()->findExe("umount", paths.at(i));
+
+ if (!umount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return umount;
+}
+
+
|
CWE-20
| null | null |
5,193
|
void Smb4KGlobal::abortCore()
{
Smb4KScanner::self()->abortAll();
Smb4KMounter::self()->abortAll();
Smb4KPrint::self()->abortAll();
Smb4KSynchronizer::self()->abortAll();
Smb4KPreviewer::self()->abortAll();
Smb4KSearch::self()->abortAll();
}
|
+Priv
| 0
|
void Smb4KGlobal::abortCore()
{
Smb4KScanner::self()->abortAll();
Smb4KMounter::self()->abortAll();
Smb4KPrint::self()->abortAll();
Smb4KSynchronizer::self()->abortAll();
Smb4KPreviewer::self()->abortAll();
Smb4KSearch::self()->abortAll();
}
|
@@ -2,7 +2,7 @@
smb4kglobal - This is the global namespace for Smb4K.
-------------------
begin : Sa Apr 2 2005
- copyright : (C) 2005-2014 by Alexander Reinholdt
+ copyright : (C) 2005-2017 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
@@ -851,3 +851,66 @@ QStringList Smb4KGlobal::whitelistedMountArguments()
#endif
+const QString Smb4KGlobal::findMountExecutable()
+{
+ QString mount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for (int i = 0; i < paths.size(); ++i)
+ {
+#if defined(Q_OS_LINUX)
+ mount = KGlobal::dirs()->findExe("mount.cifs", paths.at(i));
+#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
+ mount = KGlobal::dirs()->findExe("mount_smbfs", paths.at(i));
+#endif
+
+ if (!mount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return mount;
+}
+
+
+const QString Smb4KGlobal::findUmountExecutable()
+{
+ // Find the umount program.
+ QString umount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for ( int i = 0; i < paths.size(); ++i )
+ {
+ umount = KGlobal::dirs()->findExe("umount", paths.at(i));
+
+ if (!umount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return umount;
+}
+
+
|
CWE-20
| null | null |
5,194
|
bool Smb4KGlobal::addHost( Smb4KHost *host )
{
Q_ASSERT( host );
bool added = false;
mutex.lock();
if ( !findHost( host->hostName(), host->workgroupName() ) )
{
p->hostsList.append( host );
added = true;
}
else
{
}
mutex.unlock();
return added;
}
|
+Priv
| 0
|
bool Smb4KGlobal::addHost( Smb4KHost *host )
{
Q_ASSERT( host );
bool added = false;
mutex.lock();
if ( !findHost( host->hostName(), host->workgroupName() ) )
{
p->hostsList.append( host );
added = true;
}
else
{
}
mutex.unlock();
return added;
}
|
@@ -2,7 +2,7 @@
smb4kglobal - This is the global namespace for Smb4K.
-------------------
begin : Sa Apr 2 2005
- copyright : (C) 2005-2014 by Alexander Reinholdt
+ copyright : (C) 2005-2017 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
@@ -851,3 +851,66 @@ QStringList Smb4KGlobal::whitelistedMountArguments()
#endif
+const QString Smb4KGlobal::findMountExecutable()
+{
+ QString mount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for (int i = 0; i < paths.size(); ++i)
+ {
+#if defined(Q_OS_LINUX)
+ mount = KGlobal::dirs()->findExe("mount.cifs", paths.at(i));
+#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
+ mount = KGlobal::dirs()->findExe("mount_smbfs", paths.at(i));
+#endif
+
+ if (!mount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return mount;
+}
+
+
+const QString Smb4KGlobal::findUmountExecutable()
+{
+ // Find the umount program.
+ QString umount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for ( int i = 0; i < paths.size(); ++i )
+ {
+ umount = KGlobal::dirs()->findExe("umount", paths.at(i));
+
+ if (!umount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return umount;
+}
+
+
|
CWE-20
| null | null |
5,195
|
bool Smb4KGlobal::addWorkgroup( Smb4KWorkgroup *workgroup )
{
Q_ASSERT( workgroup );
bool added = false;
mutex.lock();
if ( !findWorkgroup( workgroup->workgroupName() ) )
{
p->workgroupsList.append( workgroup );
added = true;
}
else
{
}
mutex.unlock();
return added;
}
|
+Priv
| 0
|
bool Smb4KGlobal::addWorkgroup( Smb4KWorkgroup *workgroup )
{
Q_ASSERT( workgroup );
bool added = false;
mutex.lock();
if ( !findWorkgroup( workgroup->workgroupName() ) )
{
p->workgroupsList.append( workgroup );
added = true;
}
else
{
}
mutex.unlock();
return added;
}
|
@@ -2,7 +2,7 @@
smb4kglobal - This is the global namespace for Smb4K.
-------------------
begin : Sa Apr 2 2005
- copyright : (C) 2005-2014 by Alexander Reinholdt
+ copyright : (C) 2005-2017 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
@@ -851,3 +851,66 @@ QStringList Smb4KGlobal::whitelistedMountArguments()
#endif
+const QString Smb4KGlobal::findMountExecutable()
+{
+ QString mount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for (int i = 0; i < paths.size(); ++i)
+ {
+#if defined(Q_OS_LINUX)
+ mount = KGlobal::dirs()->findExe("mount.cifs", paths.at(i));
+#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
+ mount = KGlobal::dirs()->findExe("mount_smbfs", paths.at(i));
+#endif
+
+ if (!mount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return mount;
+}
+
+
+const QString Smb4KGlobal::findUmountExecutable()
+{
+ // Find the umount program.
+ QString umount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for ( int i = 0; i < paths.size(); ++i )
+ {
+ umount = KGlobal::dirs()->findExe("umount", paths.at(i));
+
+ if (!umount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return umount;
+}
+
+
|
CWE-20
| null | null |
5,196
|
void Smb4KGlobal::clearHostsList()
{
mutex.lock();
while ( !p->hostsList.isEmpty() )
{
delete p->hostsList.takeFirst();
}
mutex.unlock();
}
|
+Priv
| 0
|
void Smb4KGlobal::clearHostsList()
{
mutex.lock();
while ( !p->hostsList.isEmpty() )
{
delete p->hostsList.takeFirst();
}
mutex.unlock();
}
|
@@ -2,7 +2,7 @@
smb4kglobal - This is the global namespace for Smb4K.
-------------------
begin : Sa Apr 2 2005
- copyright : (C) 2005-2014 by Alexander Reinholdt
+ copyright : (C) 2005-2017 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
@@ -851,3 +851,66 @@ QStringList Smb4KGlobal::whitelistedMountArguments()
#endif
+const QString Smb4KGlobal::findMountExecutable()
+{
+ QString mount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for (int i = 0; i < paths.size(); ++i)
+ {
+#if defined(Q_OS_LINUX)
+ mount = KGlobal::dirs()->findExe("mount.cifs", paths.at(i));
+#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
+ mount = KGlobal::dirs()->findExe("mount_smbfs", paths.at(i));
+#endif
+
+ if (!mount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return mount;
+}
+
+
+const QString Smb4KGlobal::findUmountExecutable()
+{
+ // Find the umount program.
+ QString umount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for ( int i = 0; i < paths.size(); ++i )
+ {
+ umount = KGlobal::dirs()->findExe("umount", paths.at(i));
+
+ if (!umount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return umount;
+}
+
+
|
CWE-20
| null | null |
5,197
|
void Smb4KGlobal::clearSharesList()
{
mutex.lock();
while ( !p->sharesList.isEmpty() )
{
delete p->sharesList.takeFirst();
}
mutex.unlock();
}
|
+Priv
| 0
|
void Smb4KGlobal::clearSharesList()
{
mutex.lock();
while ( !p->sharesList.isEmpty() )
{
delete p->sharesList.takeFirst();
}
mutex.unlock();
}
|
@@ -2,7 +2,7 @@
smb4kglobal - This is the global namespace for Smb4K.
-------------------
begin : Sa Apr 2 2005
- copyright : (C) 2005-2014 by Alexander Reinholdt
+ copyright : (C) 2005-2017 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
@@ -851,3 +851,66 @@ QStringList Smb4KGlobal::whitelistedMountArguments()
#endif
+const QString Smb4KGlobal::findMountExecutable()
+{
+ QString mount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for (int i = 0; i < paths.size(); ++i)
+ {
+#if defined(Q_OS_LINUX)
+ mount = KGlobal::dirs()->findExe("mount.cifs", paths.at(i));
+#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
+ mount = KGlobal::dirs()->findExe("mount_smbfs", paths.at(i));
+#endif
+
+ if (!mount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return mount;
+}
+
+
+const QString Smb4KGlobal::findUmountExecutable()
+{
+ // Find the umount program.
+ QString umount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for ( int i = 0; i < paths.size(); ++i )
+ {
+ umount = KGlobal::dirs()->findExe("umount", paths.at(i));
+
+ if (!umount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return umount;
+}
+
+
|
CWE-20
| null | null |
5,198
|
void Smb4KGlobal::clearWorkgroupsList()
{
mutex.lock();
while ( !p->workgroupsList.isEmpty() )
{
delete p->workgroupsList.takeFirst();
}
mutex.unlock();
}
|
+Priv
| 0
|
void Smb4KGlobal::clearWorkgroupsList()
{
mutex.lock();
while ( !p->workgroupsList.isEmpty() )
{
delete p->workgroupsList.takeFirst();
}
mutex.unlock();
}
|
@@ -2,7 +2,7 @@
smb4kglobal - This is the global namespace for Smb4K.
-------------------
begin : Sa Apr 2 2005
- copyright : (C) 2005-2014 by Alexander Reinholdt
+ copyright : (C) 2005-2017 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
@@ -851,3 +851,66 @@ QStringList Smb4KGlobal::whitelistedMountArguments()
#endif
+const QString Smb4KGlobal::findMountExecutable()
+{
+ QString mount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for (int i = 0; i < paths.size(); ++i)
+ {
+#if defined(Q_OS_LINUX)
+ mount = KGlobal::dirs()->findExe("mount.cifs", paths.at(i));
+#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
+ mount = KGlobal::dirs()->findExe("mount_smbfs", paths.at(i));
+#endif
+
+ if (!mount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return mount;
+}
+
+
+const QString Smb4KGlobal::findUmountExecutable()
+{
+ // Find the umount program.
+ QString umount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for ( int i = 0; i < paths.size(); ++i )
+ {
+ umount = KGlobal::dirs()->findExe("umount", paths.at(i));
+
+ if (!umount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return umount;
+}
+
+
|
CWE-20
| null | null |
5,199
|
bool Smb4KGlobal::coreIsInitialized()
{
return p->coreInitialized;
}
|
+Priv
| 0
|
bool Smb4KGlobal::coreIsInitialized()
{
return p->coreInitialized;
}
|
@@ -2,7 +2,7 @@
smb4kglobal - This is the global namespace for Smb4K.
-------------------
begin : Sa Apr 2 2005
- copyright : (C) 2005-2014 by Alexander Reinholdt
+ copyright : (C) 2005-2017 by Alexander Reinholdt
email : alexander.reinholdt@kdemail.net
***************************************************************************/
@@ -851,3 +851,66 @@ QStringList Smb4KGlobal::whitelistedMountArguments()
#endif
+const QString Smb4KGlobal::findMountExecutable()
+{
+ QString mount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for (int i = 0; i < paths.size(); ++i)
+ {
+#if defined(Q_OS_LINUX)
+ mount = KGlobal::dirs()->findExe("mount.cifs", paths.at(i));
+#elif defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
+ mount = KGlobal::dirs()->findExe("mount_smbfs", paths.at(i));
+#endif
+
+ if (!mount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return mount;
+}
+
+
+const QString Smb4KGlobal::findUmountExecutable()
+{
+ // Find the umount program.
+ QString umount;
+ QStringList paths;
+ paths << "/bin";
+ paths << "/sbin";
+ paths << "/usr/bin";
+ paths << "/usr/sbin";
+ paths << "/usr/local/bin";
+ paths << "/usr/local/sbin";
+
+ for ( int i = 0; i < paths.size(); ++i )
+ {
+ umount = KGlobal::dirs()->findExe("umount", paths.at(i));
+
+ if (!umount.isEmpty())
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
+ return umount;
+}
+
+
|
CWE-20
| null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.