Skip to content

Commit

Permalink
fixed segfault for accessing deleted articles
Browse files Browse the repository at this point in the history
  • Loading branch information
Barium Blue committed Sep 6, 2012
1 parent 096c8c1 commit 53c3708
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/news.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -248,10 +248,11 @@ news_t* news_get(int id)
{ {
news_t* article_ptr=news_list; 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; article_ptr=article_ptr->next;
}


if (article_ptr->id!=id) if (article_ptr==NULL)
return NULL; return NULL;


return article_ptr; return article_ptr;
Expand Down
7 changes: 6 additions & 1 deletion src/nlua_news.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -367,9 +367,14 @@ int newsL_eq( lua_State *L )
*/ */
Lua_article* luaL_validarticle( lua_State *L, int ind ) Lua_article* luaL_validarticle( lua_State *L, int ind )
{ {
Lua_article* Larticle;


if (lua_isarticle(L, ind)) { 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 { else {
luaL_typerror(L, ind, ARTICLE_METATABLE); luaL_typerror(L, ind, ARTICLE_METATABLE);
Expand Down

0 comments on commit 53c3708

Please sign in to comment.