Permalink
Browse files

fixed segfault for accessing deleted articles

  • Loading branch information...
1 parent 096c8c1 commit 53c3708d1440e0e76cb95d0c9fdeba949b349807 Barium Blue committed Sep 6, 2012
Showing with 9 additions and 3 deletions.
  1. +3 −2 src/news.c
  2. +6 −1 src/nlua_news.c
View
@@ -248,10 +248,11 @@ news_t* news_get(int id)
{
news_t* article_ptr=news_list;
- while (article_ptr!=NULL && article_ptr->id!=id)
+ while (article_ptr!=NULL && article_ptr->id!=id){
article_ptr=article_ptr->next;
+ }
- if (article_ptr->id!=id)
+ if (article_ptr==NULL)
return NULL;
return article_ptr;
View
@@ -367,9 +367,14 @@ int newsL_eq( lua_State *L )
*/
Lua_article* luaL_validarticle( lua_State *L, int ind )
{
+ Lua_article* Larticle;
if (lua_isarticle(L, ind)) {
- return (Lua_article*) lua_touserdata(L,ind);
+ Larticle = (Lua_article*) lua_touserdata(L,ind);
+ if (news_get(Larticle->id))
+ return Larticle;
+ else
+ NLUA_ERROR(L, "article is old");
}
else {
luaL_typerror(L, ind, ARTICLE_METATABLE);

0 comments on commit 53c3708

Please sign in to comment.