lkml.org 
[lkml]   [2001]   [Sep]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patches in this message
/
Date
From
Subject[PATCH] 2.4.9-ac10 but not only, locks_alloc_lock()

Also affects: 2.4.7, 2.4.9-ac{4,6,9}, probably others.

Problem: in locks_mandatory_area(), fcntl_setlk(), fcntl_setlk64(), no
check whether locks_alloc_lock() succeeds. Attached patch fixes that.

Not sure about one thing, though: what error code to return for
locks_mandatory_area() on failure. It's invoked from some of the
{do,sys}_*{read,write}*() routines and nowhere else AFAICT. I set it to
-ENOMEM, maybe this is not the right thing to do.

Patch follows and is attached. Made over 2.4.9-ac10, applies cleanly
over -ac's mentioned above and with offests (1 to 3 lines) on 2.4.7 and
2.4.9.


diff -urN linux-old/fs/locks.c linux/fs/locks.c
--- linux-old/fs/locks.c Sun Sep 9 09:00:06 2001
+++ linux/fs/locks.c Sun Sep 9 09:21:07 2001
@@ -698,6 +698,9 @@
struct file_lock *new_fl = locks_alloc_lock(0);
int error;

+ if (new_fl == NULL)
+ return -ENOMEM;
+
new_fl->fl_owner = current->files;
new_fl->fl_pid = current->pid;
new_fl->fl_file = filp;
@@ -1411,6 +1414,9 @@
struct inode *inode;
int error;

+ if (file_lock == NULL)
+ return -ENOLCK;
+
/*
* This might block, so we do it before checking the inode.
*/
@@ -1563,6 +1569,9 @@
struct flock64 flock;
struct inode *inode;
int error;
+
+ if (file_lock == NULL)
+ return -ENOLCK;

/*
* This might block, so we do it before checking the inode.
--
Francis Galiegue, fg@mandrakesoft.com - Normand et fier de l'être
"Programming is a race between programmers, who try and make more and more
idiot-proof software, and universe, which produces more and more remarkable
idiots. Until now, universe leads the race" -- R. Cook
diff -urN linux-old/fs/locks.c linux/fs/locks.c
--- linux-old/fs/locks.c Sun Sep 9 09:00:06 2001
+++ linux/fs/locks.c Sun Sep 9 09:21:07 2001
@@ -698,6 +698,9 @@
struct file_lock *new_fl = locks_alloc_lock(0);
int error;

+ if (new_fl == NULL)
+ return -ENOMEM;
+
new_fl->fl_owner = current->files;
new_fl->fl_pid = current->pid;
new_fl->fl_file = filp;
@@ -1411,6 +1414,9 @@
struct inode *inode;
int error;

+ if (file_lock == NULL)
+ return -ENOLCK;
+
/*
* This might block, so we do it before checking the inode.
*/
@@ -1563,6 +1569,9 @@
struct flock64 flock;
struct inode *inode;
int error;
+
+ if (file_lock == NULL)
+ return -ENOLCK;

/*
* This might block, so we do it before checking the inode.
\
 
 \ /
  Last update: 2005-03-22 13:03    [W:0.023 / U:5.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site