~ubuntu-branches/ubuntu/precise/das-watchdog/precise-security

« back to all changes in this revision

Viewing changes to debian/patches/0003-The-result-of-fgetc-is-an-int-not-a-char.patch

  • Committer: Package Import Robot
  • Author(s): Tyler Hicks
  • Date: 2015-05-15 12:08:01 UTC
  • Revision ID: package-import@ubuntu.com-20150515120801-z4ha7uy7f8hqnkbn
Tags: 0.9.0-2+deb6u1build0.12.04.1
fake sync from Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
From 57e7400d046f382ee94745791ccb0e1a06efb2e4 Mon Sep 17 00:00:00 2001
 
2
From: Adam Sampson <ats@offog.org>
 
3
Date: Wed, 1 Apr 2015 20:33:41 +0100
 
4
Subject: [PATCH 3/3] The result of fgetc is an int, not a char
 
5
 
 
6
Without this change, get_pid_environ_val would go into an infinite loop
 
7
when asked to find a variable that doesn't exist on a platform where
 
8
char is unsigned (e.g. ARM): fgetc would return -1 (EOF), which would be
 
9
stored as 255 in temp[i], which then wouldn't be equal to -1 when
 
10
testing.
 
11
---
 
12
 das_watchdog.c | 11 ++++++-----
 
13
 1 file changed, 6 insertions(+), 5 deletions(-)
 
14
 
 
15
diff --git a/das_watchdog.c b/das_watchdog.c
 
16
index 176fb1b..0dfe38a 100644
 
17
--- a/das_watchdog.c
 
18
+++ b/das_watchdog.c
 
19
@@ -322,21 +322,20 @@ static char *get_pid_environ_val(pid_t pid,char *val){
 
20
   }
 
21
   
 
22
   for(;;){
 
23
-    
 
24
+    int c = fgetc(fp);
 
25
+
 
26
     if (i >= temp_size) {
 
27
       temp_size *= 2;
 
28
       temp = realloc(temp, temp_size);
 
29
     }
 
30
-      
 
31
-    temp[i]=fgetc(fp);    
 
32
 
 
33
-    if(foundit==1 && (temp[i]=='\0' || temp[i]==EOF)){
 
34
+    if(foundit==1 && (c=='\0' || c==EOF)){
 
35
       fclose(fp);
 
36
       temp[i]=0;
 
37
       return temp;
 
38
     }
 
39
 
 
40
-    switch(temp[i]){
 
41
+    switch(c){
 
42
     case EOF:
 
43
       fclose(fp);
 
44
       free(temp);
 
45
@@ -349,9 +348,11 @@ static char *get_pid_environ_val(pid_t pid,char *val){
 
46
       i=0;
 
47
       break;
 
48
     case '\0':
 
49
+      temp[i]=0;
 
50
       i=0;
 
51
       break;
 
52
     default:
 
53
+      temp[i]=c;
 
54
       i++;
 
55
     }
 
56
   }
 
57
-- 
 
58
2.1.4
 
59