Merge lp:~akkzilla/ubuntu/natty/gmemusage/gmemusage-fix-370735 into lp:ubuntu/natty/gmemusage

Proposed by Akkana Peck
Status: Work in progress
Proposed branch: lp:~akkzilla/ubuntu/natty/gmemusage/gmemusage-fix-370735
Merge into: lp:ubuntu/natty/gmemusage
Diff against target: 115 lines (+18/-7)
5 files modified
common.h (+2/-1)
debian/changelog (+6/-0)
gmemusage.c (+2/-2)
hash.c (+4/-2)
proc.c (+4/-2)
To merge this branch: bzr merge lp:~akkzilla/ubuntu/natty/gmemusage/gmemusage-fix-370735
Reviewer Review Type Date Requested Status
Chris Coulson (community) Needs Fixing
Marc Deslauriers Needs Fixing
Ubuntu branches Pending
Review via email: mp+61171@code.launchpad.net

Description of the change

Merge patch that's been sitting in bug 370735, so gmemusage will no longer crash on startup with a stack-smashing error.

To post a comment you must log in.
Revision history for this message
Marc Deslauriers (mdeslaur) wrote :

The gmemusage uses the CDBS patch system. Please add the fix as a proper patch.

review: Needs Fixing
Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Oh, I didn't see this had a merge proposal too. I'll add my comment from the bug report in here too:

Hi,

Thanks for working on this. I have a couple of comments though:

- The scope of the patch seems to expand beyond the original bug. Whilst it's perfectly ok for you to fix the additional issues, would you mind splitting those changes in to a separate patch? (I'm referring to the cast you added in draw_window and the prototype change to main() ).

- You hardcode "%15s" in the format string for sscanf, when you use a constant everywhere else. Why not do something like this?

     char *format ;
     asprintf ( &format , "%%*s %%%ds" , PROCNAMELEN - 1 ) ;
     sscanf ( buf , format , procName ) ;
     free ( format ) ;

(Note that this doesn't make sure asprintf succeeded, which isn't good - but it doesn't look like this application checks that any other call succeeds either, so I'm not sure that matters so much here).

Let me know what you think, but I'd certainly sponsor this once you've addressed the first point

review: Needs Fixing

Unmerged revisions

5. By Akkana Peck

Fix stack smashing crash on startup, bug 370735.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'common.h'
--- common.h 2002-04-11 20:54:15 +0000
+++ common.h 2011-05-16 20:18:30 +0000
@@ -8,11 +8,12 @@
8 */8 */
9#define kernelname "linux"9#define kernelname "linux"
10#define freename "free"10#define freename "free"
11#define PROCNAMELEN 16
1112
12struct ProcInfo13struct ProcInfo
13{14{
14 char15 char
15 procname [14] ;16 procname [PROCNAMELEN] ;
16 int17 int
17 totMem ,18 totMem ,
18 totRSS ,19 totRSS ,
1920
=== modified file 'debian/changelog'
--- debian/changelog 2008-11-28 14:18:17 +0000
+++ debian/changelog 2011-05-16 20:18:30 +0000
@@ -1,3 +1,9 @@
1gmemusage (0.2-11ubuntu1) natty; urgency=low
2
3 * Fix stack smashing crash on startup, bug 370735.
4
5 -- Akkana Peck <akkana@shallowsky.com> Mon, 16 May 2011 12:54:25 -0700
6
1gmemusage (0.2-11) unstable; urgency=low7gmemusage (0.2-11) unstable; urgency=low
28
3 * Adopt the package (Closes: #486759).9 * Adopt the package (Closes: #486759).
410
=== modified file 'gmemusage.c'
--- gmemusage.c 2008-11-28 14:18:17 +0000
+++ gmemusage.c 2011-05-16 20:18:30 +0000
@@ -92,7 +92,7 @@
92void draw_window ( void ) ;92void draw_window ( void ) ;
93void TooSmall ( Window win , GC gc , XFontStruct *font_into ) ;93void TooSmall ( Window win , GC gc , XFontStruct *font_into ) ;
9494
95void main ( int argc , char **argv )95int main ( int argc , char **argv )
96{96{
97 int97 int
98 default_height ,98 default_height ,
@@ -700,7 +700,7 @@
700/*700/*
701 * We can accept alarms again701 * We can accept alarms again
702 */702 */
703 (void) signal ( SIGALRM , draw_window ) ;703 (void) signal ( SIGALRM , (__sighandler_t)draw_window ) ;
704 return ;704 return ;
705}705}
706 706
707707
=== modified file 'hash.c'
--- hash.c 2002-04-11 20:54:15 +0000
+++ hash.c 2011-05-16 20:18:30 +0000
@@ -7,6 +7,8 @@
7 * See file COPYING (included in this distribution) for copyright information.7 * See file COPYING (included in this distribution) for copyright information.
8 */8 */
9#include <stdio.h>9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
10#include <malloc.h>12#include <malloc.h>
11#include "common.h"13#include "common.h"
1214
@@ -71,7 +73,7 @@
71 }73 }
72/* printf("allocated %d procs\n",lastallocated); */74/* printf("allocated %d procs\n",lastallocated); */
73 thisproc = nextproc = procs ;75 thisproc = nextproc = procs ;
74 strcpy ( thisproc -> procname , procname ) ;76 strncpy ( thisproc -> procname , procname , PROCNAMELEN ) ;
75 thisproc -> totMem = mem ;77 thisproc -> totMem = mem ;
76 thisproc -> totRSS = rss ;78 thisproc -> totRSS = rss ;
77 thisproc -> nProcs = 1 ;79 thisproc -> nProcs = 1 ;
@@ -98,7 +100,7 @@
98/* printf("allocated %d procs\n",lastallocated); */100/* printf("allocated %d procs\n",lastallocated); */
99 }101 }
100 thisproc = procs + nProcs ;102 thisproc = procs + nProcs ;
101 strcpy ( thisproc -> procname , procname ) ;103 strncpy ( thisproc -> procname , procname , PROCNAMELEN ) ;
102 thisproc -> totMem = mem ;104 thisproc -> totMem = mem ;
103 thisproc -> totRSS = rss ;105 thisproc -> totRSS = rss ;
104 thisproc -> nProcs = 1 ;106 thisproc -> nProcs = 1 ;
105107
=== modified file 'proc.c'
--- proc.c 2008-11-28 14:18:17 +0000
+++ proc.c 2011-05-16 20:18:30 +0000
@@ -7,6 +7,7 @@
7 * See file COPYING (included in this distribution) for copyright information.7 * See file COPYING (included in this distribution) for copyright information.
8 */8 */
9#include <stdio.h>9#include <stdio.h>
10#include <stdlib.h>
10#include <string.h>11#include <string.h>
11#include <sys/types.h>12#include <sys/types.h>
12#include <dirent.h>13#include <dirent.h>
@@ -93,7 +94,7 @@
93 char94 char
94 buf [128] ;95 buf [128] ;
95 char96 char
96 procName [14] ;97 procName [PROCNAMELEN] ;
97 int98 int
98 procSize ,99 procSize ,
99 procRSS ,100 procRSS ,
@@ -164,7 +165,8 @@
164 if ( !strncmp ( buf , NameLine , NameLineLen ) )165 if ( !strncmp ( buf , NameLine , NameLineLen ) )
165 {166 {
166 /* Name: procName */167 /* Name: procName */
167 sscanf ( buf , "%*s %s" , procName ) ;168 /* The field width here should correspond to PROCNAMELEN-1 */
169 sscanf ( buf , "%*s %15s" , procName ) ;
168 }170 }
169 else if ( !strncmp ( buf , VmSizeLine , VmSizeLineLen ) )171 else if ( !strncmp ( buf , VmSizeLine , VmSizeLineLen ) )
170 {172 {

Subscribers

People subscribed via source and target branches

to all changes: